diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 18c914718..000000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,128 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, religion, or sexual identity -and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -* Focusing on what is best not just for us as individuals, but for the - overall community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or - advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email - address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -. -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series -of actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or -permanent ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within -the community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.0, available at -https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. - -Community Impact Guidelines were inspired by [Mozilla's code of conduct -enforcement ladder](https://github.com/mozilla/diversity). - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 8c74aa683..000000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 Hogan - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index bda0fe1cb..000000000 --- a/README.md +++ /dev/null @@ -1,719 +0,0 @@ -# LeetCode Solutions - -![Python](https://img.shields.io/badge/language-Python-blue.svg) -![C++](https://img.shields.io/badge/language-C++-orange.svg) -![JavaScript](https://img.shields.io/badge/language-JavaScript-yellow.svg) -![SQL](https://img.shields.io/badge/language-SQL-lightgrey.svg) -![TypeScript](https://img.shields.io/badge/language-TypeScript-blue.svg) - -Welcome to a robust and versatile repository of LeetCode solutions! This repository is a treasure trove for coding enthusiasts, educators, students, and professionals who are preparing for technical interviews or enhancing their coding skills. - -## What You'll Find Here - -- **Wide Range of Problems:** Our collection includes an extensive range of LeetCode problems, covering various topics and difficulty levels – from Easy to Hard. -- **Multi-Language Support:** We offer solutions in several programming languages, including Python, C++, JavaScript, SQL, and TypeScript, catering to a diverse coding community. -- **Organized and Accessible:** Each solution is meticulously organized by difficulty and language, making it easy to navigate and find what you need. -- **In-Depth Explanations:** You'll find README files in each problem folder with detailed explanations of the problem, the approach taken, and a thorough walkthrough of the solution. - -## Statistics - -hogan-tech-leetcode - -## Folder Structure - -The solutions are organized as follows: - -- **Difficulty:** Problems are categorized into Easy, Medium, and Hard. -- **Languages:** Solutions are available in multiple programming languages, including Python, C++, JavaScript, SQL, and TypeScript. -- **Problem Titles:** Each problem is named after its LeetCode title. - -## Question List - -| # | Title | Solution | Difficulty & ReadMe | -| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | -| 0001 | [Two Sum](https://leetcode.com/problems/two-sum/) | [Python](./0001-two-sum/0001-two-sum.py), [C++](./0001-two-sum/0001-two-sum.cpp) | [Easy](./0001-two-sum/README.md) | -| 0002 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [C++](./0002-add-two-numbers/0002-add-two-numbers.cpp) | [Medium](./0002-add-two-numbers/README.md) | -| 0003 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [Python](./0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.py), [C++](./0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.cpp) | [Medium](./0003-longest-substring-without-repeating-characters/README.md) | -| 0004 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [Python](./0004-median-of-two-sorted-arrays/0004-median-of-two-sorted-arrays.py) | [Hard](./0004-median-of-two-sorted-arrays/README.md) | -| 0005 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [Python](./0005-longest-palindromic-substring/0005-longest-palindromic-substring.py) | [Medium](./0005-longest-palindromic-substring/README.md) | -| 0006 | [ZigZag Conversion](https://leetcode.com/problems/zigzag-conversion/) | [Python](./0006-zigzag-conversion/0006-zigzag-conversion.py) | [Medium](./0006-zigzag-conversion/README.md) | -| 0007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [Python](./0007-reverse-integer/0007-reverse-integer.py) | [Medium](./0007-reverse-integer/README.md) | -| 0008 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/) | [Python](./0008-string-to-integer-atoi/0008-string-to-integer-atoi.py) | [Medium](./0008-string-to-integer-atoi/README.md) | -| 0009 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [C++](./0009-palindrome-number/0009-palindrome-number.cpp) | [Easy](./0009-palindrome-number/README.md) | -| 0010 | [Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching/) | [Python](./0010-regular-expression-matching/0010-regular-expression-matching.py) | [Hard](./0010-regular-expression-matching/README.md) | -| 0011 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./0011-container-with-most-water/0011-container-with-most-water.py) | [Medium](./0011-container-with-most-water/README.md) | -| 0012 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman/) | [Python](./0012-integer-to-roman/0012-integer-to-roman.py) | [Medium](./0012-integer-to-roman/README.md) | -| 0013 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [C++](./0013-roman-to-integer/0013-roman-to-integer.cpp) | [Easy](./0013-roman-to-integer/README.md) | -| 0014 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [C++](./0014-longest-common-prefix/0014-longest-common-prefix.cpp) | [Easy](./0014-longest-common-prefix/README.md) | -| 0015 | [3Sum](https://leetcode.com/problems/3sum/) | [Python](./0015-3sum/0015-3sum.py), [C++](./0015-3sum/0015-3sum.cpp) | [Medium](./0015-3sum/README.md) | -| 0016 | [3Sum Closest](https://leetcode.com/problems/3sum-closest/) | [Python](./0016-3sum-closest/0016-3sum-closest.py) | [Medium](./0016-3sum-closest/README.md) | -| 0017 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/) | [Python](./0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py) | [Medium](./0017-letter-combinations-of-a-phone-number/README.md) | -| 0018 | [4Sum](https://leetcode.com/problems/4sum/) | [Python](./0018-4sum/0018-4sum.py) | [Medium](./0018-4sum/README.md) | -| 0019 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) | [Python](./0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.py), [C++](./0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.cpp) | [Medium](./0019-remove-nth-node-from-end-of-list/README.md) | -| 0020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./0020-valid-parentheses/0020-valid-parentheses.py), [C++](./0020-valid-parentheses/0020-valid-parentheses.cpp), [JavaScript](./0020-valid-parentheses/0020-valid-parentheses.js) | [Easy](./0020-valid-parentheses/README.md) | -| 0021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [Python](./0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.py), [C++](./0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.cpp), [Javascript](./0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.js) | [Easy](./0021-merge-two-sorted-lists/README.md) | -| 0022 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/) | [Python](./0022-generate-parentheses/0022-generate-parentheses.py) | [Medium](./0022-generate-parentheses/README.md) | -| 0023 | [Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) | [Python](./0023-merge-k-sorted-lists/0023-merge-k-sorted-lists.py) | [Hard](./0023-merge-k-sorted-lists/README.md) | -| 0024 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [Python](./0024-swap-nodes-in-pairs/0024-swap-nodes-in-pairs.py) | [Medium](./0024-swap-nodes-in-pairs/README.md) | -| 0025 | [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/) | [Python](./0025-reverse-nodes-in-k-group/0025-reverse-nodes-in-k-group.py) | [Hard](./0025-reverse-nodes-in-k-group/README.md) | -| 0026 | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | [Python](./0026-remove-duplicates-from-sorted-array/0026-remove-duplicates-from-sorted-array.py) | [Easy](./0026-remove-duplicates-from-sorted-array/README.md) | -| 0027 | [Remove Element](https://leetcode.com/problems/remove-element/) | [Python](./0027-remove-element/0027-remove-element.py) | [Easy](./0027-remove-element/README.md) | -| 0028 | [Implement strStr()](https://leetcode.com/problems/implement-strstr/) | [Python](./0028-implement-strstr/0028-implement-strstr.py) | [Easy](./0028-implement-strstr/README.md) | -| 0029 | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers/) | [Python](./0029-divide-two-integers/0029-divide-two-integers.py) | [Medium](./0029-divide-two-integers/README.md) | -| 0031 | [Next Permutation](https://leetcode.com/problems/next-permutation/) | [Python](./0031-next-permutation/0031-next-permutation.py) | [Medium](./0031-next-permutation/README.md) | -| 0033 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | [Python](./0033-search-in-rotated-sorted-array/0033-search-in-rotated-sorted-array.py) | [Medium](./0033-search-in-rotated-sorted-array/README.md) | -| 0034 | [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | [Python](./0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.py) | [Medium](./0034-find-first-and-last-position-of-element-in-sorted-array/README.md) | -| 0035 | [Search Insert Position](https://leetcode.com/problems/search-insert-position/) | [C++](./0035-search-insert-position/0035-search-insert-position.cpp) | [Easy](./0035-search-insert-position/README.md) | -| 0036 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | [Python](./0036-valid-sudoku/0036-valid-sudoku.py), [C++](./0036-valid-sudoku/0036-valid-sudoku.cpp) | [Medium](./0036-valid-sudoku/README.md) | -| 0039 | [Combination Sum](https://leetcode.com/problems/combination-sum/) | [Python](./0039-combination-sum/0039-combination-sum.py) | [Medium](./0039-combination-sum/README.md) | -| 0040 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii/) | [Python](./0040-combination-sum-ii/0040-combination-sum-ii.py) | [Medium](./0040-combination-sum-ii/README.md) | -| 0041 | [First Missing Positive](https://leetcode.com/problems/first-missing-positive/) | [Python](./0041-first-missing-positive/0041-first-missing-positive.py) | [Hard](./0041-first-missing-positive/README.md) | -| 0042 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) | [Python](./0042-trapping-rain-water/0042-trapping-rain-water.py) | [Hard](./0042-trapping-rain-water/README.md) | -| 0045 | [Jump Game II](https://leetcode.com/problems/jump-game-ii/) | [C++](./0045-jump-game-ii/0045-jump-game-ii.cpp) | [Hard](./0045-jump-game-ii/README.md) | -| 0046 | [Permutations](https://leetcode.com/problems/permutations/) | [C++](./0046-permutations/0046-permutations.cpp) | [Medium](./0046-permutations/README.md) | -| 0048 | [Rotate Image](https://leetcode.com/problems/rotate-image/) | [C++](./0048-rotate-image/0048-rotate-image.cpp) | [Medium](./0048-rotate-image/README.md) | -| 0049 | [Group Anagrams](https://leetcode.com/problems/group-anagrams/) | [Python](./0049-group-anagrams/0049-group-anagrams.py), [JavaScript](./0049-group-anagrams/0049-group-anagrams.js) | [Medium](./0049-group-anagrams/README.md) | -| 0050 | [Pow(x, n)](https://leetcode.com/problems/powx-n/) | [Python](./0050-powx-n/0050-powx-n.py) | [Medium](./0050-powx-n/README.md) | -| 0053 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [Python](./0053-maximum-subarray/0053-maximum-subarray.py), [C++](./0053-maximum-subarray/0053-maximum-subarray.cpp) | [Easy](./0053-maximum-subarray/README.md) | -| 0054 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) | [Python](./0054-spiral-matrix/0054-spiral-matrix.py), [C++](./0054-spiral-matrix/0054-spiral-matrix.cpp) | [Medium](./0054-spiral-matrix/README.md) | -| 0055 | [Jump Game](https://leetcode.com/problems/jump-game/) | [C++](./0055-jump-game/0055-jump-game.cpp) | [Medium](./0055-jump-game/README.md) | -| 0056 | [Merge Intervals](https://leetcode.com/problems/merge-intervals/) | [Python](./0056-merge-intervals/0056-merge-intervals.py), [C++](./0056-merge-intervals/0056-merge-intervals.cpp) | [Medium](./0056-merge-intervals/README.md) | -| 0057 | [Insert Interval](https://leetcode.com/problems/insert-interval/) | [Python](./0057-insert-interval/0057-insert-interval.py) | [Hard](./0057-insert-interval/README.md) | -| 0058 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word/) | [Python](./0058-length-of-last-word/0058-length-of-last-word.py) | [Easy](./0058-length-of-last-word/README.md) | -| 0059 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii/) | [C++](./0059-spiral-matrix-ii/0059-spiral-matrix-ii.cpp) | [Medium](./0059-spiral-matrix-ii/README.md) | -| 0061 | [Rotate List](https://leetcode.com/problems/rotate-list/) | [Python](./0061-rotate-list/0061-rotate-list.py) | [Medium](./0061-rotate-list/README.md) | -| 0062 | [Unique Paths](https://leetcode.com/problems/unique-paths/) | [Python](./0062-unique-paths/0062-unique-paths.py) | [Medium](./0062-unique-paths/README.md) | -| 0063 | [Unique Paths II](https://leetcode.com/problems/unique-paths-ii/) | [Python](./0063-unique-paths-ii/0063-unique-paths-ii.py) | [Medium](./0063-unique-paths-ii/README.md) | -| 0064 | [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/) | [Python](./0064-minimum-path-sum/0064-minimum-path-sum.py) | [Medium](./0064-minimum-path-sum/README.md) | -| 0066 | [Plus One](https://leetcode.com/problems/plus-one/) | [Python](./0066-plus-one/0066-plus-one.py) | [Easy](./0066-plus-one/README.md) | -| 0067 | [Add Binary](https://leetcode.com/problems/add-binary/) | [Python](./0067-add-binary/0067-add-binary.py) | [Easy](./0067-add-binary/README.md) | -| 0068 | [Text Justification](https://leetcode.com/problems/text-justification/) | [Python](./0068-text-justification/0068-text-justification.py) | [Hard](./0068-text-justification/README.md) | -| 0069 | [Sqrt(x)](https://leetcode.com/problems/sqrtx/) | [Python](./0069-sqrtx/0069-sqrtx.py) | [Easy](./0069-sqrtx/README.md) | -| 0070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [Python](./0070-climbing-stairs/0070-climbing-stairs.py), [C++](./0070-climbing-stairs/0070-climbing-stairs.cpp) | [Easy](./0070-climbing-stairs/README.md) | -| 0073 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | [Python](./0073-set-matrix-zeroes/0073-set-matrix-zeroes.py) | [Medium](./0073-set-matrix-zeroes/README.md) | -| 0074 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) | [Python](./0074-search-a-2d-matrix/0074-search-a-2d-matrix.py), [C++](./0074-search-a-2d-matrix/0074-search-a-2d-matrix.cpp) | [Medium](./0074-search-a-2d-matrix/README.md) | -| 0075 | [Sort Colors](https://leetcode.com/problems/sort-colors/) | [Python](./0075-sort-colors/0075-sort-colors.py), [JavaScript](./0075-sort-colors/0075-sort-colors.js), [C++](./0075-sort-colors/0075-sort-colors.cpp) | [Medium](./0075-sort-colors/README.md) | -| 0076 | [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/) | [Python](./0076-minimum-window-substring/0076-minimum-window-substring.py) | [Hard](./0076-minimum-window-substring/README.md) | -| 0077 | [Combinations](https://leetcode.com/problems/combinations/) | [Python](./0077-combinations/0077-combinations.py), [C++](./0077-combinations/0077-combinations.cpp) | [Medium](./0077-combinations/README.md) | -| 0078 | [Subsets](https://leetcode.com/problems/subsets/) | [Python](./0078-subsets/0078-subsets.py), [JavaScript](./0078-subsets/0078-subsets.js) | [Medium](./0078-subsets/README.md) | -| 0079 | [Word Search](https://leetcode.com/problems/word-search/) | [Python](./0079-word-search/0079-word-search.py) | [Medium](./0079-word-search/README.md) | -| 0081 | [Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii/) | [Python](./0081-search-in-rotated-sorted-array-ii/0081-search-in-rotated-sorted-array-ii.py) | [Medium](./0081-search-in-rotated-sorted-array-ii/README.md) | -| 0083 | [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) | [C++](./0083-remove-duplicates-from-sorted-list/0083-remove-duplicates-from-sorted-list.cpp) | [Easy](./0083-remove-duplicates-from-sorted-list/README.md) | -| 0084 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | [Python](./0084-largest-rectangle-in-histogram/0084-largest-rectangle-in-histogram.py) | [Hard](./0084-largest-rectangle-in-histogram/README.md) | -| 0085 | [Maximal Rectangle](https://leetcode.com/problems/maximal-rectangle/) | [Python](./0085-maximal-rectangle/0085-maximal-rectangle.py) | [Hard](./0085-maximal-rectangle/README.md) | -| 0086 | [Partition List](https://leetcode.com/problems/partition-list/) | [Python](./0086-partition-list/0086-partition-list.py) | [Medium](./0086-partition-list/README.md) | -| 0088 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/) | [C++](./0088-merge-sorted-array/0088-merge-sorted-array.cpp) | [Easy](./0088-merge-sorted-array/README.md) | -| 0090 | [Subsets II](https://leetcode.com/problems/subsets-ii/) | [Python](./0090-subsets-ii/0090-subsets-ii.py) | [Medium](./0090-subsets-ii/README.md) | -| 0091 | [Decode Ways](https://leetcode.com/problems/decode-ways/) | [Python](./0091-decode-ways/0091-decode-ways.py) | [Medium](./0091-decode-ways/README.md) | -| 0092 | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) | [Python](./0092-reverse-linked-list-ii/0092-reverse-linked-list-ii.py) | [Medium](./0092-reverse-linked-list-ii/README.md) | -| 0094 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Python](./0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.py), [C++](./0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp), [JavaScript](./0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.js) | [Easy](./0094-binary-tree-inorder-traversal/README.md) | -| 0095 | [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii/) | [Python](./0095-unique-binary-search-trees-ii/0095-unique-binary-search-trees-ii.py) | [Medium](./0095-unique-binary-search-trees-ii/README.md) | -| 0097 | [Interleaving String](https://leetcode.com/problems/interleaving-string/) | [Python](./0097-interleaving-string/0097-interleaving-string.py) | [Medium](./0097-interleaving-string/README.md) | -| 0098 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) | [Python](./0098-validate-binary-search-tree/0098-validate-binary-search-tree.py), [C++](./0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp) | [Medium](./0098-validate-binary-search-tree/README.md) | -| 0100 | [Same Tree](https://leetcode.com/problems/same-tree/) | [Python](./0100-same-tree/0100-same-tree.py), [JavaScript](./0100-same-tree/0100-same-tree.js) | [Easy](./0100-same-tree/README.md) | -| 0101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [C++](./0101-symmetric-tree/0101-symmetric-tree.cpp) | [Easy](./0101-symmetric-tree/README.md) | -| 0102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) | [Python](./0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.py), [C++](./0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp) | [Medium](./0102-binary-tree-level-order-traversal/README.md) | -| 0104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [Python](./0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.py), [C++](./0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp) | [Easy](./0104-maximum-depth-of-binary-tree/README.md) | -| 0105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | [Python](./0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.py) | [Medium](./0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md) | -| 0110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Python](./0110-balanced-binary-tree/0110-balanced-binary-tree.py) | [Easy](./0110-balanced-binary-tree/README.md) | -| 0112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [C++](./0112-path-sum/0112-path-sum.cpp) | [Easy](./0112-path-sum/README.md) | -| 0116 | [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/) | [C++](./0116-populating-next-right-pointers-in-each-node/0116-populating-next-right-pointers-in-each-node.cpp) | [Medium](./0116-populating-next-right-pointers-in-each-node/README.md) | -| 0118 | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) | [Python](./0118-pascals-triangle/0118-pascals-triangle.py), [C++](./0118-pascals-triangle/0118-pascals-triangle.cpp) | [Easy](./0118-pascals-triangle/README.md) | -| 0119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/) | [Python](./0119-pascals-triangle-ii/0119-pascals-triangle-ii.py), [C++](./0119-pascals-triangle-ii/0119-pascals-triangle-ii.cpp) | [Easy](./0119-pascals-triangle-ii/README.md) | -| 0120 | [Triangle](https://leetcode.com/problems/triangle/) | [Python](./0120-triangle/0120-triangle.py) | [Medium](./0120-triangle/README.md) | -| 0121 | [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | [Python](./0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.py), [C++](./0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.cpp) | [Easy](./0121-best-time-to-buy-and-sell-stock/README.md) | -| 0125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | [Python](./0125-valid-palindrome/0125-valid-palindrome.py) | [Easy](./0125-valid-palindrome/README.md) | -| 0127 | [Word Ladder](https://leetcode.com/problems/word-ladder/) | [Python](./0127-word-ladder/0127-word-ladder.py) | [Medium](./0127-word-ladder/README.md) | -| 0128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/) | [Python](./0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.py) | [Hard](./0128-longest-consecutive-sequence/README.md) | -| 0129 | [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/) | [Python](./0129-sum-root-to-leaf-numbers/0129-sum-root-to-leaf-numbers.py) | [Medium](./0129-sum-root-to-leaf-numbers/README.md) | -| 0131 | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning/) | [Python](./0131-palindrome-partitioning/0131-palindrome-partitioning.py) | [Medium](./0131-palindrome-partitioning/README.md) | -| 0133 | [Clone Graph](https://leetcode.com/problems/clone-graph/) | [Python](./0133-clone-graph/0133-clone-graph.py) | [Medium](./0133-clone-graph/README.md) | -| 0135 | [Candy](https://leetcode.com/problems/candy/) | [Python](./0135-candy/0135-candy.py) | [Hard](./0135-candy/README.md) | -| 0136 | [Single Number](https://leetcode.com/problems/single-number/) | [Python](./0136-single-number/0136-single-number.py), [C++](./0136-single-number/0136-single-number.cpp) | [Easy](./0136-single-number/README.md) | -| 0137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](./0137-single-number-ii/0137-single-number-ii.py) | [Medium](./0137-single-number-ii/README.md) | -| 0138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/) | [Python](./0138-copy-list-with-random-pointer/0138-copy-list-with-random-pointer.py) | [Medium](./0138-copy-list-with-random-pointer/README.md) | -| 0139 | [Word Break](https://leetcode.com/problems/word-break/) | [Python](./0139-word-break/0139-word-break.py) | [Medium](./0139-word-break/README.md) | -| 0140 | [Word Break II](https://leetcode.com/problems/word-break-ii/) | [Python](./0140-word-break-ii/0140-word-break-ii.py) | [Hard](./0140-word-break-ii/README.md) | -| 0141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/) | [Python](./0141-linked-list-cycle/0141-linked-list-cycle.py), [C++](./0141-linked-list-cycle/0141-linked-list-cycle.cpp), [JavaScript](./0141-linked-list-cycle/0141-linked-list-cycle.js) | [Easy](./0141-linked-list-cycle/README.md) | -| 0143 | [Reorder List](https://leetcode.com/problems/reorder-list/) | [Python](./0143-reorder-list/0143-reorder-list.py) | [Medium](./0143-reorder-list/README.md) | -| 0144 | [Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/) | [Python](./0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.py), [C++](./0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.cpp), [JavaScript](./0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.js) | [Easy](./0144-binary-tree-preorder-traversal/README.md) | -| 0145 | [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/) | [Python](./0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.py), [C++](./0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp), [JavaScript](./0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.js) | [Easy](./0145-binary-tree-postorder-traversal/README.md) | -| 0146 | [LRU Cache](https://leetcode.com/problems/lru-cache/) | [Python](./0146-lru-cache/0146-lru-cache.py) | [Medium](./0146-lru-cache/README.md) | -| 0148 | [Sort List](https://leetcode.com/problems/sort-list/) | [Python](./0148-sort-list/0148-sort-list.py) | [Medium](./0148-sort-list/README.md) | -| 0150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./0150-evaluate-reverse-polish-notation/0150-evaluate-reverse-polish-notation.py) | [Medium](./0150-evaluate-reverse-polish-notation/README.md) | -| 0153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | [Python](./0153-find-minimum-in-rotated-sorted-array/0153-find-minimum-in-rotated-sorted-array.py) | [Medium](./0153-find-minimum-in-rotated-sorted-array/README.md) | -| 0155 | [Min Stack](https://leetcode.com/problems/min-stack/) | [Python](./0155-min-stack/0155-min-stack.py) | [Easy](./0155-min-stack/README.md) | -| 0159 | [Longest Substring with At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/) | [Python](./0159-longest-substring-with-at-most-two-distinct-characters/0159-longest-substring-with-at-most-two-distinct-characters.py) | [Medium](./0159-longest-substring-with-at-most-two-distinct-characters/README.md) | -| 0162 | [Find Peak Element](https://leetcode.com/problems/find-peak-element/) | [Python](./0162-find-peak-element/0162-find-peak-element.py) | [Medium](./0162-find-peak-element/README.md) | -| 0165 | [Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers/) | [Python](./0165-compare-version-numbers/0165-compare-version-numbers.py) | [Medium](./0165-compare-version-numbers/README.md) | -| 0167 | [Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | [Python](./0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.py), [C++](./0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.cpp) | [Easy](./0167-two-sum-ii-input-array-is-sorted/README.md) | -| 0168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title/) | [Python](./0168-excel-sheet-column-title/0168-excel-sheet-column-title.py) | [Easy](./0168-excel-sheet-column-title/README.md) | -| 0169 | [Majority Element](https://leetcode.com/problems/majority-element/) | [Python](./0169-majority-element/0169-majority-element.py), [C++](./0169-majority-element/0169-majority-element.cpp) | [Easy](./0169-majority-element/README.md) | -| 0189 | [Rotate Array](https://leetcode.com/problems/rotate-array/) | [C++](./0189-rotate-array/0189-rotate-array.cpp) | [Medium](./0189-rotate-array/README.md) | -| 0190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits/) | [Python](./0190-reverse-bits/0190-reverse-bits.py) | [Easy](./0190-reverse-bits/README.md) | -| 0191 | [Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/) | [Python](./0191-number-of-1-bits/0191-number-of-1-bits.py) | [Easy](./0191-number-of-1-bits/README.md) | -| 0198 | [House Robber](https://leetcode.com/problems/house-robber/) | [Python](./0198-house-robber/0198-house-robber.py), [C++](./0198-house-robber/0198-house-robber.cpp) | [Easy](./0198-house-robber/README.md) | -| 0199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view/) | [Python](./0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.py) | [Medium](./0199-binary-tree-right-side-view/README.md) | -| 0200 | [Number of Islands](https://leetcode.com/problems/number-of-islands/) | [Python](./0200-number-of-islands/0200-number-of-islands.py) | [Medium](./0200-number-of-islands/README.md) | -| 0201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range/) | [Python](./0201-bitwise-and-of-numbers-range/0201-bitwise-and-of-numbers-range.py) | [Medium](./0201-bitwise-and-of-numbers-range/README.md) | -| 0202 | [Happy Number](https://leetcode.com/problems/happy-number/) | [Python](./0202-happy-number/0202-happy-number.py) | [Easy](./0202-happy-number/README.md) | -| 0203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/) | [C++](./0203-remove-linked-list-elements/0203-remove-linked-list-elements.cpp) | [Easy](./0203-remove-linked-list-elements/README.md) | -| 0205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/) | [Python](./0205-isomorphic-strings/0205-isomorphic-strings.py) | [Easy](./0205-isomorphic-strings/README.md) | -| 0206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) | [Python](./0206-reverse-linked-list/0206-reverse-linked-list.py), [C++](./0206-reverse-linked-list/0206-reverse-linked-list.cpp), [JavaScript](./0206-reverse-linked-list/0206-reverse-linked-list.js) | [Easy](./0206-reverse-linked-list/README.md) | -| 0207 | [Course Schedule](https://leetcode.com/problems/course-schedule/) | [Python](./0207-course-schedule/0207-course-schedule.py) | [Medium](./0207-course-schedule/README.md) | -| 0208 | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/) | [Python](./0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.py) | [Medium](./0208-implement-trie-prefix-tree/README.md) | -| 0213 | [House Robber II](https://leetcode.com/problems/house-robber-ii/) | [C++](./0213-house-robber-ii/0213-house-robber-ii.cpp) | [Medium](./0213-house-robber-ii/README.md) | -| 0215 | [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) | [Python](./0215-kth-largest-element-in-an-array/0215-kth-largest-element-in-an-array.py) | [Medium](./0215-kth-largest-element-in-an-array/README.md) | -| 0217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [Python](./0217-contains-duplicate/0217-contains-duplicate.py), [C++](./0217-contains-duplicate/0217-contains-duplicate.cpp), [JavaScript](./0217-contains-duplicate/0217-contains-duplicate.js) | [Easy](./0217-contains-duplicate/README.md) | -| 0219 | [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii/) | [Python](./0219-contains-duplicate-ii/0219-contains-duplicate-ii.py) | [Easy](./0219-contains-duplicate-ii/README.md) | -| 0224 | [Basic Calculator](https://leetcode.com/problems/basic-calculator/) | [Python](./0224-basic-calculator/0224-basic-calculator.py) | [Hard](./0224-basic-calculator/README.md) | -| 0225 | [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues/) | [Python](./0225-implement-stack-using-queues/0225-implement-stack-using-queues.py) | [Easy](./0225-implement-stack-using-queues/README.md) | -| 0226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/) | [Python](./0226-invert-binary-tree/0226-invert-binary-tree.py), [JavaScript](./0226-invert-binary-tree/0226-invert-binary-tree.js) | [Easy](./0226-invert-binary-tree/README.md) | -| 0229 | [Majority Element II](https://leetcode.com/problems/majority-element-ii/) | [Python](./0229-majority-element-ii/0229-majority-element-ii.py) | [Medium](./0229-majority-element-ii/README.md) | -| 0230 | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/) | [Python](./0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.py) | [Medium](./0230-kth-smallest-element-in-a-bst/README.md) | -| 0231 | [Power of Two](https://leetcode.com/problems/power-of-two/) | [C++](./0231-power-of-two/0231-power-of-two.cpp) | [Easy](./0231-power-of-two/README.md) | -| 0232 | [Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/) | [Python](./0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.py), [C++](./0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.cpp) | [Easy](./0232-implement-queue-using-stacks/README.md) | -| 0234 | [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) | [Python](./0234-palindrome-linked-list/0234-palindrome-linked-list.py) | [Easy](./0234-palindrome-linked-list/README.md) | -| 0235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | [Python](./0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.py), [C++](./0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp) | [Easy](./0235-lowest-common-ancestor-of-a-binary-search-tree/README.md) | -| 0236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/) | [Python](./0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.py) | [Medium](./0236-lowest-common-ancestor-of-a-binary-tree/README.md) | -| 0237 | [Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/) | [Python](./0237-delete-node-in-a-linked-list/0237-delete-node-in-a-linked-list.py) | [Medium](./0237-delete-node-in-a-linked-list/README.md) | -| 0238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | [Python](./0238-product-of-array-except-self/0238-product-of-array-except-self.py) | [Medium](./0238-product-of-array-except-self/README.md) | -| 0239 | [Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/) | [Python](./0239-sliding-window-maximum/0239-sliding-window-maximum.py) | [Hard](./0239-sliding-window-maximum/README.md) | -| 0242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [Python](./0242-valid-anagram/0242-valid-anagram.py), [C++](./0242-valid-anagram/0242-valid-anagram.cpp), [JavaScript](./0242-valid-anagram/0242-valid-anagram.js) | [Easy](./0242-valid-anagram/README.md) | -| 0253 | [Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii/) | [Python](./0253-meeting-rooms-ii/0253-meeting-rooms-ii.py) | [Medium](./0253-meeting-rooms-ii/README.md) | -| 0255 | [Verify Preorder Sequence in Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree/) | [Python](./0255-verify-preorder-sequence-in-binary-search-tree/0255-verify-preorder-sequence-in-binary-search-tree.py) | [Medium](./0255-verify-preorder-sequence-in-binary-search-tree/README.md) | -| 0256 | [Paint House](https://leetcode.com/problems/paint-house/) | [Python](./0256-paint-house/0256-paint-house.py) | [Medium](./0256-paint-house/README.md) | -| 0260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./0260-single-number-iii/0260-single-number-iii.py) | [Medium](./0260-single-number-iii/README.md) | -| 0263 | [Ugly Number](https://leetcode.com/problems/ugly-number/) | [Python](./0263-ugly-number/0263-ugly-number.py) | [Easy](./0263-ugly-number/README.md) | -| 0264 | [Ugly Number II](https://leetcode.com/problems/ugly-number-ii/) | [Python](./0264-ugly-number-ii/0264-ugly-number-ii.py) | [Medium](./0264-ugly-number-ii/README.md) | -| 0268 | [Missing Number](https://leetcode.com/problems/missing-number/) | [Python](./0268-missing-number/0268-missing-number.py) | [Easy](./0268-missing-number/README.md) | -| 0271 | [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings/) | [Python](./0271-encode-and-decode-strings/0271-encode-and-decode-strings.py) | [Medium](./0271-encode-and-decode-strings/README.md) | -| 0273 | [Integer to English Words](https://leetcode.com/problems/integer-to-english-words/) | [Python](./0273-integer-to-english-words/0273-integer-to-english-words.py) | [Hard](./0273-integer-to-english-words/README.md) | -| 0276 | [Paint Fence](https://leetcode.com/problems/paint-fence/) | [Python](./0276-paint-fence/0276-paint-fence.py) | [Medium](./0276-paint-fence/README.md) | -| 0278 | [First Bad Version](https://leetcode.com/problems/first-bad-version/) | [Python](./0278-first-bad-version/0278-first-bad-version.py), [C++](./0278-first-bad-version/0278-first-bad-version.cpp) | [Easy](./0278-first-bad-version/README.md) | -| 0279 | [Perfect Squares](https://leetcode.com/problems/perfect-squares/) | [Python](./0279-perfect-squares/0279-perfect-squares.py) | [Medium](./0279-perfect-squares/README.md) | -| 0283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes/) | [C++](./0283-move-zeroes/0283-move-zeroes.cpp) | [Easy](./0283-move-zeroes/README.md) | -| 0287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) | [Python](./0287-find-the-duplicate-number/0287-find-the-duplicate-number.py) | [Medium](./0287-find-the-duplicate-number/README.md) | -| 0290 | [Word Pattern](https://leetcode.com/problems/word-pattern/) | [Python](./0290-word-pattern/0290-word-pattern.py) | [Easy](./0290-word-pattern/README.md) | -| 0291 | [Word Pattern II](https://leetcode.com/problems/word-pattern-ii/) | [Python](./0291-word-pattern-ii/0291-word-pattern-ii.py) | [Medium](./0291-word-pattern-ii/README.md) | -| 0293 | [Flip Game](https://leetcode.com/problems/flip-game/) | [Python](./0293-flip-game/0293-flip-game.py) | [Easy](./0293-flip-game/README.md) | -| 0295 | [Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/) | [Python](./0295-find-median-from-data-stream/0295-find-median-from-data-stream.py) | [Hard](./0295-find-median-from-data-stream/README.md) | -| 0296 | [Best Meeting Point](https://leetcode.com/problems/best-meeting-point/) | [Python](./0296-best-meeting-point/0296-best-meeting-point.py) | [Hard](./0296-best-meeting-point/README.md) | -| 0297 | [Serialize and Deserialize Binary Tree](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/) | [Python](./0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.py) | [Hard](./0297-serialize-and-deserialize-binary-tree/README.md) | -| 0300 | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) | [Python](./0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.py) | [Medium](./0300-longest-increasing-subsequence/README.md) | -| 0305 | [Number of Islands II](https://leetcode.com/problems/number-of-islands-ii/) | [Python](./0305-number-of-islands-ii/0305-number-of-islands-ii.py) | [Hard](./0305-number-of-islands-ii/README.md) | -| 0310 | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/) | [Python](./0310-minimum-height-trees/0310-minimum-height-trees.py) | [Medium](./0310-minimum-height-trees/README.md) | -| 0316 | [Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters/) | [Python](./0316-remove-duplicate-letters/0316-remove-duplicate-letters.py) | [Hard](./0316-remove-duplicate-letters/README.md) | -| 0320 | [Generalized Abbreviation](https://leetcode.com/problems/generalized-abbreviation/) | [Python](./0320-generalized-abbreviation/0320-generalized-abbreviation.py) | [Medium](./0320-generalized-abbreviation/README.md) | -| 0322 | [Coin Change](https://leetcode.com/problems/coin-change/) | [Python](./0322-coin-change/0322-coin-change.py) | [Medium](./0322-coin-change/README.md) | -| 0330 | [Patching Array](https://leetcode.com/problems/patching-array/) | [Python](./0330-patching-array/0330-patching-array.py) | [Hard](./0330-patching-array/README.md) | -| 0332 | [Reconstruct Itinerary](https://leetcode.com/problems/reconstruct-itinerary/) | [Python](./0332-reconstruct-itinerary/0332-reconstruct-itinerary.py) | [Medium](./0332-reconstruct-itinerary/README.md) | -| 0338 | [Counting Bits](https://leetcode.com/problems/counting-bits/) | [Python](./0338-counting-bits/0338-counting-bits.py) | [Medium](./0338-counting-bits/README.md) | -| 0340 | [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/) | [Python](./0340-longest-substring-with-at-most-k-distinct-characters/0340-longest-substring-with-at-most-k-distinct-characters.py) | [Medium](./0340-longest-substring-with-at-most-k-distinct-characters/README.md) | -| 0341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator/) | [Python](./0341-flatten-nested-list-iterator/0341-flatten-nested-list-iterator.py) | [Medium](./0341-flatten-nested-list-iterator/README.md) | -| 0342 | [Power of Four](https://leetcode.com/problems/power-of-four/) | [Python](./0342-power-of-four/0342-power-of-four.py) | [Easy](./0342-power-of-four/README.md) | -| 0343 | [Integer Break](https://leetcode.com/problems/integer-break/) | [Python](./0343-integer-break/0343-integer-break.py) | [Medium](./0343-integer-break/README.md) | -| 0344 | [Reverse String](https://leetcode.com/problems/reverse-string/) | [Python](./0344-reverse-string/0344-reverse-string.py), [C++](./0344-reverse-string/0344-reverse-string.cpp) | [Easy](./0344-reverse-string/README.md) | -| 0346 | [Moving Average from Data Stream](https://leetcode.com/problems/moving-average-from-data-stream/) | [Python](./0346-moving-average-from-data-stream/0346-moving-average-from-data-stream.py) | [Easy](./0346-moving-average-from-data-stream/README.md) | -| 0347 | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/) | [Python](./0347-top-k-frequent-elements/0347-top-k-frequent-elements.py) | [Medium](./0347-top-k-frequent-elements/README.md) | -| 0349 | [Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/) | [Python](./0349-intersection-of-two-arrays/0349-intersection-of-two-arrays.py) | [Easy](./0349-intersection-of-two-arrays/README.md) | -| 0350 | [Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | [Python](./0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.py), [C++](./0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.cpp) | [Easy](./0350-intersection-of-two-arrays-ii/README.md) | -| 0351 | [Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns/) | [Python](./0351-android-unlock-patterns/0351-android-unlock-patterns.py) | [Medium](./0351-android-unlock-patterns/README.md) | -| 0358 | [Rearrange String k Distance Apart](https://leetcode.com/problems/rearrange-string-k-distance-apart/) | [Python](./0358-rearrange-string-k-distance-apart/0358-rearrange-string-k-distance-apart.py) | [Hard](./0358-rearrange-string-k-distance-apart/README.md) | -| 0368 | [Largest Divisible Subset](https://leetcode.com/problems/largest-divisible-subset/) | [Python](./0368-largest-divisible-subset/0368-largest-divisible-subset.py) | [Medium](./0368-largest-divisible-subset/README.md) | -| 0377 | [Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/) | [Python](./0377-combination-sum-iv/0377-combination-sum-iv.py) | [Medium](./0377-combination-sum-iv/README.md) | -| 0380 | [Insert Delete GetRandom O(1)](https://leetcode.com/problems/insert-delete-getrandom-o1/) | [Python](./0380-insert-delete-getrandom-o1/0380-insert-delete-getrandom-o1.py) | [Medium](./0380-insert-delete-getrandom-o1/README.md) | -| 0383 | [Ransom Note](https://leetcode.com/problems/ransom-note/) | [Python](./0383-ransom-note/0383-ransom-note.py), [C++](./0383-ransom-note/0383-ransom-note.cpp) | [Easy](./0383-ransom-note/README.md) | -| 0387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | [Python](./0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.py), [C++](./0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.cpp) | [Easy](./0387-first-unique-character-in-a-string/README.md) | -| 0389 | [Find the Difference](https://leetcode.com/problems/find-the-difference/) | [Python](./0389-find-the-difference/0389-find-the-difference.py) | [Easy](./0389-find-the-difference/README.md) | -| 0392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence/) | [Python](./0392-is-subsequence/0392-is-subsequence.py) | [Easy](./0392-is-subsequence/README.md) | -| 0402 | [Remove K Digits](https://leetcode.com/problems/remove-k-digits/) | [Python](./0402-remove-k-digits/0402-remove-k-digits.py) | [Medium](./0402-remove-k-digits/README.md) | -| 0403 | [Frog Jump](https://leetcode.com/problems/frog-jump/) | [Python](./0403-frog-jump/0403-frog-jump.py) | [Hard](./0403-frog-jump/README.md) | -| 0404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/) | [Python](./0404-sum-of-left-leaves/0404-sum-of-left-leaves.py) | [Easy](./0404-sum-of-left-leaves/README.md) | -| 0409 | [Longest Palindrome](https://leetcode.com/problems/longest-palindrome/) | [Python](./0409-longest-palindrome/0409-longest-palindrome.py) | [Easy](./0409-longest-palindrome/README.md) | -| 0416 | [Partition Equal Subset Sum](https://leetcode.com/problems/partition-equal-subset-sum/) | [Python](./0416-partition-equal-subset-sum/0416-partition-equal-subset-sum.py) | [Medium](./0416-partition-equal-subset-sum/README.md) | -| 0438 | [Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/) | [Python](./0438-find-all-anagrams-in-a-string/0438-find-all-anagrams-in-a-string.py) | [Medium](./0438-find-all-anagrams-in-a-string/README.md) | -| 0439 | [Ternary Expression Parser](https://leetcode.com/problems/ternary-expression-parser/) | [Python](./0439-ternary-expression-parser/0439-ternary-expression-parser.py) | [Medium](./0439-ternary-expression-parser/README.md) | -| 0442 | [Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array/) | [Python](./0442-find-all-duplicates-in-an-array/0442-find-all-duplicates-in-an-array.py) | [Medium](./0442-find-all-duplicates-in-an-array/README.md) | -| 0446 | [Arithmetic Slices II - Subsequence](https://leetcode.com/problems/arithmetic-slices-ii-subsequence/) | [Python](./0446-arithmetic-slices-ii-subsequence/0446-arithmetic-slices-ii-subsequence.py) | [Hard](./0446-arithmetic-slices-ii-subsequence/README.md) | -| 0451 | [Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency/) | [Python](./0451-sort-characters-by-frequency/0451-sort-characters-by-frequency.py) | [Medium](./0451-sort-characters-by-frequency/README.md) | -| 0452 | [Minimum Number of Arrows to Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/) | [Python](./0452-minimum-number-of-arrows-to-burst-balloons/0452-minimum-number-of-arrows-to-burst-balloons.py) | [Medium](./0452-minimum-number-of-arrows-to-burst-balloons/README.md) | -| 0455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies/) | [Python](./0455-assign-cookies/0455-assign-cookies.py) | [Easy](./0455-assign-cookies/README.md) | -| 0456 | [132 Pattern](https://leetcode.com/problems/132-pattern/) | [Python](./0456-132-pattern/0456-132-pattern.py) | [Medium](./0456-132-pattern/README.md) | -| 0458 | [Poor Pigs](https://leetcode.com/problems/poor-pigs/) | [Python](./0458-poor-pigs/0458-poor-pigs.py) | [Hard](./0458-poor-pigs/README.md) | -| 0459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern/) | [Python](./0459-repeated-substring-pattern/0459-repeated-substring-pattern.py) | [Easy](./0459-repeated-substring-pattern/README.md) | -| 0463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter/) | [Python](./0463-island-perimeter/0463-island-perimeter.py) | [Easy](./0463-island-perimeter/README.md) | -| 0476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Python](./0476-number-complement/0476-number-complement.py) | [Easy](./0476-number-complement/README.md) | -| 0486 | [Predict the Winner](https://leetcode.com/problems/predict-the-winner/) | [Python](./0486-predict-the-winner/0486-predict-the-winner.py) | [Medium](./0486-predict-the-winner/README.md) | -| 0487 | [Max Consecutive Ones II](https://leetcode.com/problems/max-consecutive-ones-ii/) | [Python](./0487-max-consecutive-ones-ii/0487-max-consecutive-ones-ii.py) | [Medium](./0487-max-consecutive-ones-ii/README.md) | -| 0490 | [The Maze](https://leetcode.com/problems/the-maze/) | [Python](./0490-the-maze/0490-the-maze.py) | [Medium](./0490-the-maze/README.md) | -| 0501 | [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree/) | [Python](./0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.py) | [Easy](./0501-find-mode-in-binary-search-tree/README.md) | -| 0502 | [IPO](https://leetcode.com/problems/ipo/) | [Python](./0502-ipo/0502-ipo.py) | [Hard](./0502-ipo/README.md) | -| 0505 | [The Maze II](https://leetcode.com/problems/the-maze-ii/) | [Python](./0505-the-maze-ii/0505-the-maze-ii.py) | [Medium](./0505-the-maze-ii/README.md) | -| 0506 | [Relative Ranks](https://leetcode.com/problems/relative-ranks/) | [Python](./0506-relative-ranks/0506-relative-ranks.py) | [Easy](./0506-relative-ranks/README.md) | -| 0509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) | [C++](./0509-fibonacci-number/0509-fibonacci-number.cpp) | [Easy](./0509-fibonacci-number/README.md) | -| 0513 | [Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value/) | [Python](./0513-find-bottom-left-tree-value/0513-find-bottom-left-tree-value.py) | [Medium](./0513-find-bottom-left-tree-value/README.md) | -| 0514 | [Freedom Trail](https://leetcode.com/problems/freedom-trail/) | [Python](./0514-freedom-trail/0514-freedom-trail.py) | [Hard](./0514-freedom-trail/README.md) | -| 0515 | [Find Largest Value in Each Tree Row](https://leetcode.com/problems/find-largest-value-in-each-tree-row/) | [Python](./0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.py) | [Medium](./0515-find-largest-value-in-each-tree-row/README.md) | -| 0518 | [Coin Change 2](https://leetcode.com/problems/coin-change-2/) | [Python](./0518-coin-change-2/0518-coin-change-2.py) | [Medium](./0518-coin-change-2/README.md) | -| 0523 | [Continuous Subarray Sum](https://leetcode.com/problems/continuous-subarray-sum/) | [Python](./0523-continuous-subarray-sum/0523-continuous-subarray-sum.py) | [Medium](./0523-continuous-subarray-sum/README.md) | -| 0525 | [Contiguous Array](https://leetcode.com/problems/contiguous-array/) | [Python](./0525-contiguous-array/0525-contiguous-array.py) | [Medium](./0525-contiguous-array/README.md) | -| 0532 | [K-diff Pairs in an Array](https://leetcode.com/problems/k-diff-pairs-in-an-array/) | [Python](./0532-k-diff-pairs-in-an-array/0532-k-diff-pairs-in-an-array.py) | [Easy](./0532-k-diff-pairs-in-an-array/README.md) | -| 0540 | [Single Element in a Sorted Array](https://leetcode.com/problems/single-element-in-a-sorted-array/) | [Python](./0540-single-element-in-a-sorted-array/0540-single-element-in-a-sorted-array.py) | [Medium](./0540-single-element-in-a-sorted-array/README.md) | -| 0542 | [01 Matrix](https://leetcode.com/problems/01-matrix/) | [Python](./0542-01-matrix/0542-01-matrix.py), [C++](./0542-01-matrix/0542-01-matrix.cpp) | [Medium](./0542-01-matrix/README.md) | -| 0543 | [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/) | [Python](./0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.py) | [Easy](./0543-diameter-of-binary-tree/README.md) | -| 0552 | [Student Attendance Record II](https://leetcode.com/problems/student-attendance-record-ii/) | [Python](./0552-student-attendance-record-ii/0552-student-attendance-record-ii.py) | [Hard](./0552-student-attendance-record-ii/README.md) | -| 0557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii/) | [C++](./0557-reverse-words-in-a-string-iii/0557-reverse-words-in-a-string-iii.cpp) | [Easy](./0557-reverse-words-in-a-string-iii/README.md) | -| 0561 | [Array Partition I](https://leetcode.com/problems/array-partition-i/) | [Python](./0561-array-partition-i/0561-array-partition-i.py) | [Easy](./0561-array-partition-i/README.md) | -| 0564 | [Find the Closest Palindrome](https://leetcode.com/problems/find-the-closest-palindrome/) | [Python](./0564-find-the-closest-palindrome/0564-find-the-closest-palindrome.py) | [Hard](./0564-find-the-closest-palindrome/README.md) | -| 0566 | [Reshape the Matrix](https://leetcode.com/problems/reshape-the-matrix/) | [C++](./0566-reshape-the-matrix/0566-reshape-the-matrix.cpp) | [Easy](./0566-reshape-the-matrix/README.md) | -| 0567 | [Permutation in String](https://leetcode.com/problems/permutation-in-string/) | [C++](./0567-permutation-in-string/0567-permutation-in-string.cpp) | [Medium](./0567-permutation-in-string/README.md) | -| 0572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/) | [Python](./0572-subtree-of-another-tree/0572-subtree-of-another-tree.py), [Javascript](./0572-subtree-of-another-tree/0572-subtree-of-another-tree.js) | [Easy](./0572-subtree-of-another-tree/README.md) | -| 0573 | [Squirrel Simulation](https://leetcode.com/problems/squirrel-simulation/) | [Python](./0573-squirrel-simulation/0573-squirrel-simulation.py) | [Medium](./0573-squirrel-simulation/README.md) | -| 0576 | [Out of Boundary Paths](https://leetcode.com/problems/out-of-boundary-paths/) | [Python](./0576-out-of-boundary-paths/0576-out-of-boundary-paths.py) | [Medium](./0576-out-of-boundary-paths/README.md) | -| 0584 | [Find Customer Referee](https://leetcode.com/problems/find-customer-referee/) | [SQL](./0584-find-customer-referee/0584-find-customer-referee.sql) | [Easy](./0584-find-customer-referee/README.md) | -| 0590 | [N-ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal/) | [Python](./0590-n-ary-tree-postorder-traversal/0590-n-ary-tree-postorder-traversal.py) | [Easy](./0590-n-ary-tree-postorder-traversal/README.md) | -| 0592 | [Fraction Addition and Subtraction](https://leetcode.com/problems/fraction-addition-and-subtraction/) | [Python](./0592-fraction-addition-and-subtraction/0592-fraction-addition-and-subtraction.py) | [Medium](./0592-fraction-addition-and-subtraction/README.md) | -| 0595 | [Big Countries](https://leetcode.com/problems/big-countries/) | [SQL](./0595-big-countries/0595-big-countries.sql) | [Easy](./0595-big-countries/README.md) | -| 0606 | [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree/) | [Python](./0606-construct-string-from-binary-tree/0606-construct-string-from-binary-tree.py) | [Easy](./0606-construct-string-from-binary-tree/README.md) | -| 0617 | [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees/) | [C++](./0617-merge-two-binary-trees/0617-merge-two-binary-trees.cpp) | [Easy](./0617-merge-two-binary-trees/README.md) | -| 0621 | [Task Scheduler](https://leetcode.com/problems/task-scheduler/) | [Python](./0621-task-scheduler/0621-task-scheduler.py) | [Medium](./0621-task-scheduler/README.md) | -| 0623 | [Add One Row to Tree](https://leetcode.com/problems/add-one-row-to-tree/) | [Python](./0623-add-one-row-to-tree/0623-add-one-row-to-tree.py) | [Medium](./0623-add-one-row-to-tree/README.md) | -| 0624 | [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays/) | [Python](./0624-maximum-distance-in-arrays/0624-maximum-distance-in-arrays.py) | [Easy](./0624-maximum-distance-in-arrays/README.md) | -| 0629 | [K Inverse Pairs Array](https://leetcode.com/problems/k-inverse-pairs-array/) | [Python](./0629-k-inverse-pairs-array/0629-k-inverse-pairs-array.py) | [Hard](./0629-k-inverse-pairs-array/README.md) | -| 0633 | [Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/) | [Python](./0633-sum-of-square-numbers/0633-sum-of-square-numbers.py) | [Medium](./0633-sum-of-square-numbers/README.md) | -| 0645 | [Set Mismatch](https://leetcode.com/problems/set-mismatch/) | [Python](./0645-set-mismatch/0645-set-mismatch.py) | [Easy](./0645-set-mismatch/README.md) | -| 0646 | [Maximum Length of Pair Chain](https://leetcode.com/problems/maximum-length-of-pair-chain/) | [Python](./0646-maximum-length-of-pair-chain/0646-maximum-length-of-pair-chain.py) | [Medium](./0646-maximum-length-of-pair-chain/README.md) | -| 0647 | [Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/) | [Python](./0647-palindromic-substrings/0647-palindromic-substrings.py) | [Medium](./0647-palindromic-substrings/README.md) | -| 0648 | [Replace Words](https://leetcode.com/problems/replace-words/) | [Python](./0648-replace-words/0648-replace-words.py) | [Medium](./0648-replace-words/README.md) | -| 0650 | [2 Keys Keyboard](https://leetcode.com/problems/2-keys-keyboard/) | [Python](./0650-2-keys-keyboard/0650-2-keys-keyboard.py) | [Medium](./0650-2-keys-keyboard/README.md) | -| 0653 | [Two Sum IV - Input is a BST](https://leetcode.com/problems/two-sum-iv-input-is-a-bst/) | [C++](./0653-two-sum-iv-input-is-a-bst/0653-two-sum-iv-input-is-a-bst.cpp) | [Easy](./0653-two-sum-iv-input-is-a-bst/README.md) | -| 0658 | [Find K Closest Elements](https://leetcode.com/problems/find-k-closest-elements/) | [Python](./0658-find-k-closest-elements/0658-find-k-closest-elements.py) | [Medium](./0658-find-k-closest-elements/README.md) | -| 0661 | [Image Smoother](https://leetcode.com/problems/image-smoother/) | [Python](./0661-image-smoother/0661-image-smoother.py) | [Easy](./0661-image-smoother/README.md) | -| 0664 | [Strange Printer](https://leetcode.com/problems/strange-printer/) | [Python](./0664-strange-printer/0664-strange-printer.py) | [Hard](./0664-strange-printer/README.md) | -| 0678 | [Valid Parenthesis String](https://leetcode.com/problems/valid-parenthesis-string/) | [Python](./0678-valid-parenthesis-string/0678-valid-parenthesis-string.py) | [Medium](./0678-valid-parenthesis-string/README.md) | -| 0695 | [Max Area of Island](https://leetcode.com/problems/max-area-of-island/) | [C++](./0695-max-area-of-island/0695-max-area-of-island.cpp) | [Medium](./0695-max-area-of-island/README.md) | -| 0700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree/) | [C++](./0700-search-in-a-binary-search-tree/0700-search-in-a-binary-search-tree.cpp) | [Easy](./0700-search-in-a-binary-search-tree/README.md) | -| 0701 | [Insert into a Binary Search Tree](https://leetcode.com/problems/insert-into-a-binary-search-tree/) | [C++](./0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp) | [Medium](./0701-insert-into-a-binary-search-tree/README.md) | -| 0703 | [Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream/) | [Python](./0703-kth-largest-element-in-a-stream/0703-kth-largest-element-in-a-stream.py) | [Easy](./0703-kth-largest-element-in-a-stream/README.md) | -| 0704 | [Binary Search](https://leetcode.com/problems/binary-search/) | [Pythoon](./0704-binary-search/0704-binary-search.py), [C++](./0704-binary-search/0704-binary-search.cpp), [Javascript](./0704-binary-search/0704-binary-search.js) | [Easy](./0704-binary-search/README.md) | -| 0706 | [Design HashMap](https://leetcode.com/problems/design-hashmap/) | [Python](./0706-design-hashmap/0706-design-hashmap.py), [C++](./0706-design-hashmap/0706-design-hashmap.cpp) | [Easy](./0706-design-hashmap/README.md) | -| 0712 | [Minimum ASCII Delete Sum for Two Strings](https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/) | [Python](./0712-minimum-ascii-delete-sum-for-two-strings/0712-minimum-ascii-delete-sum-for-two-strings.py) | [Medium](./0712-minimum-ascii-delete-sum-for-two-strings/README.md) | -| 0713 | [Subarray Product Less Than K](https://leetcode.com/problems/subarray-product-less-than-k/) | [Python](./0713-subarray-product-less-than-k/0713-subarray-product-less-than-k.py) | [Medium](./0713-subarray-product-less-than-k/README.md) | -| 0719 | [Find K-th Smallest Pair Distance](https://leetcode.com/problems/find-k-th-smallest-pair-distance/) | [Python](./0719-find-k-th-smallest-pair-distance/0719-find-k-th-smallest-pair-distance.py) | [Hard](./0719-find-k-th-smallest-pair-distance/README.md) | -| 0721 | [Accounts Merge](https://leetcode.com/problems/accounts-merge/) | [Python](./0721-accounts-merge/0721-accounts-merge.py) | [Medium](./0721-accounts-merge/README.md) | -| 0723 | [Candy Crush](https://leetcode.com/problems/candy-crush/) | [Python](./0723-candy-crush/0723-candy-crush.py) | [Medium](./0723-candy-crush/README.md) | -| 0725 | [Split Linked List in Parts](https://leetcode.com/problems/split-linked-list-in-parts/) | [Python](./0725-split-linked-list-in-parts/0725-split-linked-list-in-parts.py) | [Medium](./0725-split-linked-list-in-parts/README.md) | -| 0726 | [Number of Atoms](https://leetcode.com/problems/number-of-atoms/) | [Python](./0726-number-of-atoms/0726-number-of-atoms.py) | [Hard](./0726-number-of-atoms/README.md) | -| 0733 | [Flood Fill](https://leetcode.com/problems/flood-fill/) | [Python](./0733-flood-fill/0733-flood-fill.py), [C++](./0733-flood-fill/0733-flood-fill.cpp) | [Easy](./0733-flood-fill/README.md) | -| 0739 | [Daily Temperatures](https://leetcode.com/problems/daily-temperatures/) | [Python](./0739-daily-temperatures/0739-daily-temperatures.py) | [Medium](./0739-daily-temperatures/README.md) | -| 0741 | [Cherry Pickup](https://leetcode.com/problems/cherry-pickup/) | [Python](./0741-cherry-pickup/0741-cherry-pickup.py) | [Hard](./0741-cherry-pickup/README.md) | -| 0746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/) | [Python](./0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.py), [C++](./0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.cpp) | [Easy](./0746-min-cost-climbing-stairs/README.md) | -| 0752 | [Open the Lock](https://leetcode.com/problems/open-the-lock/) | [Python](./0752-open-the-lock/0752-open-the-lock.py) | [Medium](./0752-open-the-lock/README.md) | -| 0767 | [Reorganize String](https://leetcode.com/problems/reorganize-string/) | [Python](./0767-reorganize-string/0767-reorganize-string.py) | [Medium](./0767-reorganize-string/README.md) | -| 0776 | [Split BST](https://leetcode.com/problems/split-bst/) | [Python](./0776-split-bst/0776-split-bst.py) | [Medium](./0776-split-bst/README.md) | -| 0779 | [K-th Symbol in Grammar](https://leetcode.com/problems/k-th-symbol-in-grammar/) | [Python](./0779-k-th-symbol-in-grammar/0779-k-th-symbol-in-grammar.py) | [Medium](./0779-k-th-symbol-in-grammar/README.md) | -| 0784 | [Letter Case Permutation](https://leetcode.com/problems/letter-case-permutation/) | [C++](./0784-letter-case-permutation/0784-letter-case-permutation.cpp) | [Medium](./0784-letter-case-permutation/README.md) | -| 0786 | [K-th Smallest Prime Fraction](https://leetcode.com/problems/k-th-smallest-prime-fraction/) | [Python](./0786-k-th-smallest-prime-fraction/0786-k-th-smallest-prime-fraction.py) | [Medium](./0786-k-th-smallest-prime-fraction/README.md) | -| 0787 | [Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops/) | [Python](./0787-cheapest-flights-within-k-stops/0787-cheapest-flights-within-k-stops.py) | [Medium](./0787-cheapest-flights-within-k-stops/README.md) | -| 0791 | [Custom Sort String](https://leetcode.com/problems/custom-sort-string/) | [Python](./0791-custom-sort-string/0791-custom-sort-string.py) | [Medium](./0791-custom-sort-string/README.md) | -| 0799 | [Champagne Tower](https://leetcode.com/problems/champagne-tower/) | [Python](./0799-champagne-tower/0799-champagne-tower.py) | [Medium](./0799-champagne-tower/README.md) | -| 0808 | [Soup Servings](https://leetcode.com/problems/soup-servings/) | [Python](./0808-soup-servings/0808-soup-servings.py) | [Medium](./0808-soup-servings/README.md) | -| 0815 | [Bus Routes](https://leetcode.com/problems/bus-routes/) | [Python](./0815-bus-routes/0815-bus-routes.py) | [Hard](./0815-bus-routes/README.md) | -| 0823 | [Binary Trees With Factors](https://leetcode.com/problems/binary-trees-with-factors/) | [Python](./0823-binary-trees-with-factors/0823-binary-trees-with-factors.py) | [Medium](./0823-binary-trees-with-factors/README.md) | -| 0826 | [Most Profit Assigning Work](https://leetcode.com/problems/most-profit-assigning-work/) | [Python](./0826-most-profit-assigning-work/0826-most-profit-assigning-work.py) | [Medium](./0826-most-profit-assigning-work/README.md) | -| 0834 | [Sum of Distances in Tree](https://leetcode.com/problems/sum-of-distances-in-tree/) | [Python](./0834-sum-of-distances-in-tree/0834-sum-of-distances-in-tree.py) | [Hard](./0834-sum-of-distances-in-tree/README.md) | -| 0840 | [Magic Squares In Grid](https://leetcode.com/problems/magic-squares-in-grid/) | [Python](./0840-magic-squares-in-grid/0840-magic-squares-in-grid.py) | [Medium](./0840-magic-squares-in-grid/README.md) | -| 0844 | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare/) | [Python](./0844-backspace-string-compare/0844-backspace-string-compare.py) | [Easy](./0844-backspace-string-compare/README.md) | -| 0846 | [Hand of Straights](https://leetcode.com/problems/hand-of-straights/) | [Python](./0846-hand-of-straights/0846-hand-of-straights.py) | [Medium](./0846-hand-of-straights/README.md) | -| 0847 | [Shortest Path Visiting All Nodes](https://leetcode.com/problems/shortest-path-visiting-all-nodes/) | [Python](./0847-shortest-path-visiting-all-nodes/0847-shortest-path-visiting-all-nodes.py) | [Hard](./0847-shortest-path-visiting-all-nodes/README.md) | -| 0852 | [Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/) | [Python](./0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.py) | [Easy](./0852-peak-index-in-a-mountain-array/README.md) | -| 0857 | [Minimum Cost to Hire K Workers](https://leetcode.com/problems/minimum-cost-to-hire-k-workers/) | [Python](./0857-minimum-cost-to-hire-k-workers/0857-minimum-cost-to-hire-k-workers.py) | [Hard](./0857-minimum-cost-to-hire-k-workers/README.md) | -| 0860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change/) | [Python](./0860-lemonade-change/0860-lemonade-change.py) | [Easy](./0860-lemonade-change/README.md) | -| 0861 | [Score After Flipping Matrix](https://leetcode.com/problems/score-after-flipping-matrix/) | [Python](./0861-score-after-flipping-matrix/0861-score-after-flipping-matrix.py) | [Medium](./0861-score-after-flipping-matrix/README.md) | -| 0867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix/) | [Python](./0867-transpose-matrix/0867-transpose-matrix.py) | [Easy](./0867-transpose-matrix/README.md) | -| 0872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees/) | [Python](./0872-leaf-similar-trees/0872-leaf-similar-trees.py) | [Easy](./0872-leaf-similar-trees/README.md) | -| 0875 | [Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/) | [Python](./0875-koko-eating-bananas/0875-koko-eating-bananas.py) | [Medium](./0875-koko-eating-bananas/README.md) | -| 0876 | [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/) | [Python](./0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.py), [C++](./0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.cpp) | [Easy](./0876-middle-of-the-linked-list/README.md) | -| 0880 | [Decoded String at Index](https://leetcode.com/problems/decoded-string-at-index/) | [Python](./0880-decoded-string-at-index/0880-decoded-string-at-index.py) | [Medium](./0880-decoded-string-at-index/README.md) | -| 0881 | [Boats to Save People](https://leetcode.com/problems/boats-to-save-people/) | [Python](./0881-boats-to-save-people/0881-boats-to-save-people.py) | [Medium](./0881-boats-to-save-people/README.md) | -| 0885 | [Spiral Matrix III](https://leetcode.com/problems/spiral-matrix-iii/) | [Python](./0885-spiral-matrix-iii/0885-spiral-matrix-iii.py) | [Medium](./0885-spiral-matrix-iii/README.md) | -| 0888 | [Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap/) | [Python](./0888-fair-candy-swap/0888-fair-candy-swap.py) | [Easy](./0888-fair-candy-swap/README.md) | -| 0894 | [All Possible Full Binary Trees](https://leetcode.com/problems/all-possible-full-binary-trees/) | [Python](./0894-all-possible-full-binary-trees/0894-all-possible-full-binary-trees.py) | [Medium](./0894-all-possible-full-binary-trees/README.md) | -| 0896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array/) | [Python](./0896-monotonic-array/0896-monotonic-array.py) | [Easy](./0896-monotonic-array/README.md) | -| 0905 | [Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity/) | [Python](./0905-sort-array-by-parity/0905-sort-array-by-parity.py) | [Easy](./0905-sort-array-by-parity/README.md) | -| 0907 | [Sum of Subarray Minimums](https://leetcode.com/problems/sum-of-subarray-minimums/) | [Python](./0907-sum-of-subarray-minimums/0907-sum-of-subarray-minimums.py) | [Medium](./0907-sum-of-subarray-minimums/README.md) | -| 0912 | [Sort an Array](https://leetcode.com/problems/sort-an-array/) | [Python](./0912-sort-an-array/0912-sort-an-array.py) | [Medium](./0912-sort-an-array/README.md) | -| 0920 | [Number of Music Playlists](https://leetcode.com/problems/number-of-music-playlists/) | [Python](./0920-number-of-music-playlists/0920-number-of-music-playlists.py) | [Hard](./0920-number-of-music-playlists/README.md) | -| 0930 | [Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum/) | [Python](./0930-binary-subarrays-with-sum/0930-binary-subarrays-with-sum.py) | [Medium](./0930-binary-subarrays-with-sum/README.md) | -| 0931 | [Minimum Falling Path Sum](https://leetcode.com/problems/minimum-falling-path-sum/) | [Python](./0931-minimum-falling-path-sum/0931-minimum-falling-path-sum.py) | [Medium](./0931-minimum-falling-path-sum/README.md) | -| 0935 | [Knight Dialer](https://leetcode.com/problems/knight-dialer/) | [Python](./0935-knight-dialer/0935-knight-dialer.py) | [Medium](./0935-knight-dialer/README.md) | -| 0938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst/) | [Python](./0938-range-sum-of-bst/0938-range-sum-of-bst.py) | [Easy](./0938-range-sum-of-bst/README.md) | -| 0945 | [Minimum Increment to Make Array Unique](https://leetcode.com/problems/minimum-increment-to-make-array-unique/) | [Python](./0945-minimum-increment-to-make-array-unique/0945-minimum-increment-to-make-array-unique.py) | [Medium](./0945-minimum-increment-to-make-array-unique/README.md) | -| 0948 | [Bag of Tokens](https://leetcode.com/problems/bag-of-tokens/) | [Python](./0948-bag-of-tokens/0948-bag-of-tokens.py) | [Medium](./0948-bag-of-tokens/README.md) | -| 0950 | [Reveal Cards In Increasing Order](https://leetcode.com/problems/reveal-cards-in-increasing-order/) | [Python](./0950-reveal-cards-in-increasing-order/0950-reveal-cards-in-increasing-order.py) | [Medium](./0950-reveal-cards-in-increasing-order/README.md) | -| 0959 | [Regions Cut By Slashes](https://leetcode.com/problems/regions-cut-by-slashes/) | [Python](./0959-regions-cut-by-slashes/0959-regions-cut-by-slashes.py) | [Medium](./0959-regions-cut-by-slashes/README.md) | -| 0973 | [K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/) | [Python](./0973-k-closest-points-to-origin/0973-k-closest-points-to-origin.py) | [Medium](./0973-k-closest-points-to-origin/README.md) | -| 0974 | [Subarray Sums Divisible by K](https://leetcode.com/problems/subarray-sums-divisible-by-k/) | [Python](./0974-subarray-sums-divisible-by-k/0974-subarray-sums-divisible-by-k.py) | [Medium](./0974-subarray-sums-divisible-by-k/README.md) | -| 0977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/) | [Python](./0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.py), [C++](./0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.cpp) | [Easy](./0977-squares-of-a-sorted-array/README.md) | -| 0979 | [Distribute Coins in Binary Tree](https://leetcode.com/problems/distribute-coins-in-binary-tree/) | [Python](./0979-distribute-coins-in-binary-tree/0979-distribute-coins-in-binary-tree.py) | [Medium](./0979-distribute-coins-in-binary-tree/README.md) | -| 0981 | [Time Based Key-Value Store](https://leetcode.com/problems/time-based-key-value-store/) | [Python](./0981-time-based-key-value-store/0981-time-based-key-value-store.py) | [Medium](./0981-time-based-key-value-store/README.md) | -| 0988 | [Smallest String Starting From Leaf](https://leetcode.com/problems/smallest-string-starting-from-leaf/) | [Python](./0988-smallest-string-starting-from-leaf/0988-smallest-string-starting-from-leaf.py) | [Medium](./0988-smallest-string-starting-from-leaf/README.md) | -| 0992 | [Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/) | [Python](./0992-subarrays-with-k-different-integers/0992-subarrays-with-k-different-integers.py) | [Hard](./0992-subarrays-with-k-different-integers/README.md) | -| 0994 | [Rotting Oranges](https://leetcode.com/problems/rotting-oranges/) | [Python](./0994-rotting-oranges/0994-rotting-oranges.py), [C++](./0994-rotting-oranges/0994-rotting-oranges.cpp) | [Medium](./0994-rotting-oranges/README.md) | -| 0995 | [Minimum Number of K Consecutive Bit Flips](https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/) | [Python](./0995-minimum-number-of-k-consecutive-bit-flips/0995-minimum-number-of-k-consecutive-bit-flips.py) | [Hard](./0995-minimum-number-of-k-consecutive-bit-flips/README.md) | -| 0997 | [Find the Town Judge](https://leetcode.com/problems/find-the-town-judge/) | [Python](./0997-find-the-town-judge/0997-find-the-town-judge.py) | [Easy](./0997-find-the-town-judge/README.md) | -| 1002 | [Find Common Characters](https://leetcode.com/problems/find-common-characters/) | [Python](./1002-find-common-characters/1002-find-common-characters.py) | [Easy](./1002-find-common-characters/README.md) | -| 1026 | [Maximum Difference Between Node and Ancestor](https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/) | [Python](./1026-maximum-difference-between-node-and-ancestor/1026-maximum-difference-between-node-and-ancestor.py) | [Medium](./1026-maximum-difference-between-node-and-ancestor/README.md) | -| 1038 | [Binary Search Tree to Greater Sum Tree](https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/) | [Python](./1038-binary-search-tree-to-greater-sum-tree/1038-binary-search-tree-to-greater-sum-tree.py) | [Medium](./1038-binary-search-tree-to-greater-sum-tree/README.md) | -| 1043 | [Partition Array for Maximum Sum](https://leetcode.com/problems/partition-array-for-maximum-sum/) | [Python](./1043-partition-array-for-maximum-sum/1043-partition-array-for-maximum-sum.py) | [Medium](./1043-partition-array-for-maximum-sum/README.md) | -| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight/) | [Python](./1046-last-stone-weight/1046-last-stone-weight.py) | [Easy](./1046-last-stone-weight/README.md) | -| 1048 | [Longest String Chain](https://leetcode.com/problems/longest-string-chain/) | [Python](./1048-longest-string-chain/1048-longest-string-chain.py) | [Medium](./1048-longest-string-chain/README.md) | -| 1051 | [Height Checker](https://leetcode.com/problems/height-checker/) | [Python](./1051-height-checker/1051-height-checker.py) | [Easy](./1051-height-checker/README.md) | -| 1052 | [Grumpy Bookstore Owner](https://leetcode.com/problems/grumpy-bookstore-owner/) | [Python](./1052-grumpy-bookstore-owner/1052-grumpy-bookstore-owner.py) | [Medium](./1052-grumpy-bookstore-owner/README.md) | -| 1057 | [Campus Bikes](https://leetcode.com/problems/campus-bikes/) | [Python](./1057-campus-bikes/1057-campus-bikes.py) | [Medium](./1057-campus-bikes/README.md) | -| 1060 | [Missing Element in Sorted Array](https://leetcode.com/problems/missing-element-in-sorted-array/) | [Python](./1060-missing-element-in-sorted-array/1060-missing-element-in-sorted-array.py) | [Medium](./1060-missing-element-in-sorted-array/README.md) | -| 1062 | [Longest Repeating Substring](https://leetcode.com/problems/longest-repeating-substring/) | [Python](./1062-longest-repeating-substring/1062-longest-repeating-substring.py) | [Medium](./1062-longest-repeating-substring/README.md) | -| 1063 | [Number of Valid Subarrays](https://leetcode.com/problems/number-of-valid-subarrays/) | [Python](./1063-number-of-valid-subarrays/1063-number-of-valid-subarrays.py) | [Hard](./1063-number-of-valid-subarrays/README.md) | -| 1066 | [Campus Bikes II](https://leetcode.com/problems/campus-bikes-ii/) | [Python](./1066-campus-bikes-ii/1066-campus-bikes-ii.py) | [Medium](./1066-campus-bikes-ii/README.md) | -| 1071 | [Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings/) | [Python](./1071-greatest-common-divisor-of-strings/1071-greatest-common-divisor-of-strings.py) | [Easy](./1071-greatest-common-divisor-of-strings/README.md) | -| 1074 | [Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target/) | [Python](./1074-number-of-submatrices-that-sum-to-target/1074-number-of-submatrices-that-sum-to-target.py) | [Hard](./1074-number-of-submatrices-that-sum-to-target/README.md) | -| 1095 | [Find in Mountain Array](https://leetcode.com/problems/find-in-mountain-array/) | [Python](./1095-find-in-mountain-array/1095-find-in-mountain-array.py) | [Hard](./1095-find-in-mountain-array/README.md) | -| 1099 | [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k/) | [Python](./1099-two-sum-less-than-k/1099-two-sum-less-than-k.py) | [Easy](./1099-two-sum-less-than-k/README.md) | -| 1101 | [The Earliest Moment When Everyone Become Friends](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends/) | [Python](./1101-the-earliest-moment-when-everyone-become-friends/1101-the-earliest-moment-when-everyone-become-friends.py) | [Medium](./1101-the-earliest-moment-when-everyone-become-friends/README.md) | -| 1105 | [Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves/) | [Python](./1105-filling-bookcase-shelves/1105-filling-bookcase-shelves.py) | [Medium](./1105-filling-bookcase-shelves/README.md) | -| 1110 | [Delete Nodes And Return Forest](https://leetcode.com/problems/delete-nodes-and-return-forest/) | [Python](./1110-delete-nodes-and-return-forest/1110-delete-nodes-and-return-forest.py) | [Medium](./1110-delete-nodes-and-return-forest/README.md) | -| 1119 | [Remove Vowels from a String](https://leetcode.com/problems/remove-vowels-from-a-string/) | [Python](./1119-remove-vowels-from-a-string/1119-remove-vowels-from-a-string.py) | [Easy](./1119-remove-vowels-from-a-string/README.md) | -| 1120 | [Maximum Average Subtree](https://leetcode.com/problems/maximum-average-subtree/) | [Python](./1120-maximum-average-subtree/1120-maximum-average-subtree.py) | [Medium](./1120-maximum-average-subtree/README.md) | -| 1122 | [Relative Sort Array](https://leetcode.com/problems/relative-sort-array/) | [Python](./1122-relative-sort-array/1122-relative-sort-array.py) | [Easy](./1122-relative-sort-array/README.md) | -| 1136 | [Parallel Courses](https://leetcode.com/problems/parallel-courses/) | [Python](./1136-parallel-courses/1136-parallel-courses.py) | [Hard](./1136-parallel-courses/README.md) | -| 1137 | [N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/) | [Python](./1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.py), [C++](./1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.cpp) | [Easy](./1137-n-th-tribonacci-number/README.md) | -| 1140 | [Stone Game II](https://leetcode.com/problems/stone-game-ii/) | [Python](./1140-stone-game-ii/1140-stone-game-ii.py) | [Medium](./1140-stone-game-ii/README.md) | -| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/) | [Python](./1143-longest-common-subsequence/1143-longest-common-subsequence.py) | [Medium](./1143-longest-common-subsequence/README.md) | -| 1148 | [Article Views I](https://leetcode.com/problems/article-views-i/) | [SQL](./1148-article-views-i/1148-article-views-i.sql) | [Easy](./1148-article-views-i/README.md) | -| 1155 | [Number of Dice Rolls With Target Sum](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/) | [Python](./1155-number-of-dice-rolls-with-target-sum/1155-number-of-dice-rolls-with-target-sum.py) | [Medium](./1155-number-of-dice-rolls-with-target-sum/README.md) | -| 1160 | [Find Words That Can Be Formed by Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/) | [Python](./1160-find-words-that-can-be-formed-by-characters/1160-find-words-that-can-be-formed-by-characters.py) | [Easy](./1160-find-words-that-can-be-formed-by-characters/README.md) | -| 1165 | [Single Row Keyboard](https://leetcode.com/problems/single-row-keyboard/) | [Python](./1165-single-row-keyboard/1165-single-row-keyboard.py) | [Easy](./1165-single-row-keyboard/README.md) | -| 1167 | [Minimum Cost to Connect Sticks](https://leetcode.com/problems/minimum-cost-to-connect-sticks/) | [Python](./1167-minimum-cost-to-connect-sticks/1167-minimum-cost-to-connect-sticks.py) | [Medium](./1167-minimum-cost-to-connect-sticks/README.md) | -| 1171 | [Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/) | [Python](./1171-remove-zero-sum-consecutive-nodes-from-linked-list/1171-remove-zero-sum-consecutive-nodes-from-linked-list.py) | [Medium](./1171-remove-zero-sum-consecutive-nodes-from-linked-list/README.md) | -| 1183 | [Maximum Number of Ones](https://leetcode.com/problems/maximum-number-of-ones/) | [Python](./1183-maximum-number-of-ones/1183-maximum-number-of-ones.py) | [Hard](./1183-maximum-number-of-ones/README.md) | -| 1190 | [Reverse Substrings Between Each Pair of Parentheses](https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses/) | [Python](./1190-reverse-substrings-between-each-pair-of-parentheses/1190-reverse-substrings-between-each-pair-of-parentheses.py) | [Medium](./1190-reverse-substrings-between-each-pair-of-parentheses/README.md) | -| 1197 | [Minimum Knight Moves](https://leetcode.com/problems/minimum-knight-moves/) | [Python](./1197-minimum-knight-moves/1197-minimum-knight-moves.py) | [Medium](./1197-minimum-knight-moves/README.md) | -| 1199 | [Minimum Time to Build Blocks](https://leetcode.com/problems/minimum-time-to-build-blocks/) | [Python](./1199-minimum-time-to-build-blocks/1199-minimum-time-to-build-blocks.py) | [Hard](./1199-minimum-time-to-build-blocks/README.md) | -| 1203 | [Sort Items by Groups Respecting Dependencies](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies/) | [Python](./1203-sort-items-by-groups-respecting-dependencies/1203-sort-items-by-groups-respecting-dependencies.py) | [Hard](./1203-sort-items-by-groups-respecting-dependencies/README.md) | -| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | [Python](./1207-unique-number-of-occurrences/1207-unique-number-of-occurrences.py) | [Easy](./1207-unique-number-of-occurrences/README.md) | -| 1208 | [Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget/) | [Python](./1208-get-equal-substrings-within-budget/1208-get-equal-substrings-within-budget.py) | [Medium](./1208-get-equal-substrings-within-budget/README.md) | -| 1216 | [Valid Palindrome III](https://leetcode.com/problems/valid-palindrome-iii/) | [Python](./1216-valid-palindrome-iii/1216-valid-palindrome-iii.py) | [Hard](./1216-valid-palindrome-iii/README.md) | -| 1219 | [Path with Maximum Gold](https://leetcode.com/problems/path-with-maximum-gold/) | [Python](./1219-path-with-maximum-gold/1219-path-with-maximum-gold.py) | [Medium](./1219-path-with-maximum-gold/README.md) | -| 1220 | [Count Vowels Permutation](https://leetcode.com/problems/count-vowels-permutation/) | [Python](./1220-count-vowels-permutation/1220-count-vowels-permutation.py) | [Hard](./1220-count-vowels-permutation/README.md) | -| 1230 | [Toss Strange Coins](https://leetcode.com/problems/toss-strange-coins/) | [Python](./1230-toss-strange-coins/1230-toss-strange-coins.py) | [Medium](./1230-toss-strange-coins/README.md) | -| 1235 | [Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/) | [Python](./1235-maximum-profit-in-job-scheduling/1235-maximum-profit-in-job-scheduling.py) | [Hard](./1235-maximum-profit-in-job-scheduling/README.md) | -| 1239 | [Maximum Length of a Concatenated String with Unique Characters](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/) | [Python](./1239-maximum-length-of-a-concatenated-string-with-unique-characters/1239-maximum-length-of-a-concatenated-string-with-unique-characters.py) | [Medium](./1239-maximum-length-of-a-concatenated-string-with-unique-characters/README.md) | -| 1245 | [Tree Diameter](https://leetcode.com/problems/tree-diameter/) | [Python](./1245-tree-diameter/1245-tree-diameter.py) | [Medium](./1245-tree-diameter/README.md) | -| 1248 | [Count Number of Nice Subarrays](https://leetcode.com/problems/count-number-of-nice-subarrays/) | [Python](./1248-count-number-of-nice-subarrays/1248-count-number-of-nice-subarrays.py) | [Medium](./1248-count-number-of-nice-subarrays/README.md) | -| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/) | [Python](./1249-minimum-remove-to-make-valid-parentheses/1249-minimum-remove-to-make-valid-parentheses.py) | [Medium](./1249-minimum-remove-to-make-valid-parentheses/README.md) | -| 1255 | [Maximum Score Words Formed by Letters](https://leetcode.com/problems/maximum-score-words-formed-by-letters/) | [Python](./1255-maximum-score-words-formed-by-letters/1255-maximum-score-words-formed-by-letters.py) | [Hard](./1255-maximum-score-words-formed-by-letters/README.md) | -| 1265 | [Print Immutable Linked List in Reverse](https://leetcode.com/problems/print-immutable-linked-list-in-reverse/) | [C++](./1265-print-immutable-linked-list-in-reverse/1265-print-immutable-linked-list-in-reverse.cpp) | [Medium](./1265-print-immutable-linked-list-in-reverse/README.md) | -| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points/) | [Python](./1266-minimum-time-visiting-all-points/1266-minimum-time-visiting-all-points.py) | [Easy](./1266-minimum-time-visiting-all-points/README.md) | -| 1269 | [Number of Ways to Stay in the Same Place After Some Steps](https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps/) | [Python](./1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.py) | [Hard](./1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/README.md) | -| 1272 | [Remove Interval](https://leetcode.com/problems/remove-interval/) | [Python](./1272-remove-interval/1272-remove-interval.py) | [Medium](./1272-remove-interval/README.md) | -| 1282 | [Group the People Given the Group Size They Belong To](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to/) | [Python](./1282-group-the-people-given-the-group-size-they-belong-to/1282-group-the-people-given-the-group-size-they-belong-to.py) | [Medium](./1282-group-the-people-given-the-group-size-they-belong-to/README.md) | -| 1287 | [Element Appearing More Than 25% In Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/) | [Python](./1287-element-appearing-more-than-25-in-sorted-array/1287-element-appearing-more-than-25-in-sorted-array.py) | [Easy](./1287-element-appearing-more-than-25-in-sorted-array/README.md) | -| 1289 | [Minimum Falling Path Sum II](https://leetcode.com/problems/minimum-falling-path-sum-ii/) | [Python](./1289-minimum-falling-path-sum-ii/1289-minimum-falling-path-sum-ii.py) | [Hard](./1289-minimum-falling-path-sum-ii/README.md) | -| 1291 | [Sequential Digits](https://leetcode.com/problems/sequential-digits/) | [Python](./1291-sequential-digits/1291-sequential-digits.py) | [Medium](./1291-sequential-digits/README.md) | -| 1325 | [Delete Leaves With a Given Value](https://leetcode.com/problems/delete-leaves-with-a-given-value/) | [Python](./1325-delete-leaves-with-a-given-value/1325-delete-leaves-with-a-given-value.py) | [Medium](./1325-delete-leaves-with-a-given-value/README.md) | -| 1326 | [Minimum Number of Taps to Open to Water a Garden](https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden/) | [Python](./1326-minimum-number-of-taps-to-open-to-water-a-garden/1326-minimum-number-of-taps-to-open-to-water-a-garden.py) | [Hard](./1326-minimum-number-of-taps-to-open-to-water-a-garden/README.md) | -| 1334 | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/) | [Python](./1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.py) | [Medium](./1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/README.md) | -| 1335 | [Minimum Difficulty of a Job Schedule](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/) | [Python](./1335-minimum-difficulty-of-a-job-schedule/1335-minimum-difficulty-of-a-job-schedule.py) | [Hard](./1335-minimum-difficulty-of-a-job-schedule/README.md) | -| 1337 | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/) | [Python](./1337-the-k-weakest-rows-in-a-matrix/1337-the-k-weakest-rows-in-a-matrix.py) | [Easy](./1337-the-k-weakest-rows-in-a-matrix/README.md) | -| 1347 | [Minimum Number of Steps to Make Two Strings Anagram](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram/) | [Python](./1347-minimum-number-of-steps-to-make-two-strings-anagram/1347-minimum-number-of-steps-to-make-two-strings-anagram.py) | [Medium](./1347-minimum-number-of-steps-to-make-two-strings-anagram/README.md) | -| 1356 | [Sort Integers by The Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/) | [Python](./1356-sort-integers-by-the-number-of-1-bits/1356-sort-integers-by-the-number-of-1-bits.py) | [Easy](./1356-sort-integers-by-the-number-of-1-bits/README.md) | -| 1359 | [Count All Valid Pickup and Delivery Options](https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options/) | [Python](./1359-count-all-valid-pickup-and-delivery-options/1359-count-all-valid-pickup-and-delivery-options.py) | [Hard](./1359-count-all-valid-pickup-and-delivery-options/README.md) | -| 1361 | [Validate Binary Tree Nodes](https://leetcode.com/problems/validate-binary-tree-nodes/) | [Python](./1361-validate-binary-tree-nodes/1361-validate-binary-tree-nodes.py) | [Medium](./1361-validate-binary-tree-nodes/README.md) | -| 1380 | [Lucky Numbers in a Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix/) | [Python](./1380-lucky-numbers-in-a-matrix/1380-lucky-numbers-in-a-matrix.py) | [Easy](./1380-lucky-numbers-in-a-matrix/README.md) | -| 1382 | [Balance a Binary Search Tree](https://leetcode.com/problems/balance-a-binary-search-tree/) | [Python](./1382-balance-a-binary-search-tree/1382-balance-a-binary-search-tree.py) | [Medium](./1382-balance-a-binary-search-tree/README.md) | -| 1395 | [Count Number of Teams](https://leetcode.com/problems/count-number-of-teams/) | [Python](./1395-count-number-of-teams/1395-count-number-of-teams.py) | [Medium](./1395-count-number-of-teams/README.md) | -| 1404 | [Number of Steps to Reduce a Number in Binary Representation to One](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one/) | [Python](./1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.py) | [Medium](./1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/README.md) | -| 1420 | [Build Array Where You Can Find The Maximum Exactly K Comparisons](https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons/) | [Python](./1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.py) | [Hard](./1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/README.md) | -| 1422 | [Maximum Score After Splitting a String](https://leetcode.com/problems/maximum-score-after-splitting-a-string/) | [Python](./1422-maximum-score-after-splitting-a-string/1422-maximum-score-after-splitting-a-string.py) | [Easy](./1422-maximum-score-after-splitting-a-string/README.md) | -| 1424 | [Diagonal Traverse II](https://leetcode.com/problems/diagonal-traverse-ii/) | [Python](./1424-diagonal-traverse-ii/1424-diagonal-traverse-ii.py) | [Medium](./1424-diagonal-traverse-ii/README.md) | -| 1425 | [Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum/) | [Python](./1425-constrained-subsequence-sum/1425-constrained-subsequence-sum.py) | [Hard](./1425-constrained-subsequence-sum/README.md) | -| 1428 | [Leftmost Column with at Least a One](https://leetcode.com/problems/leftmost-column-with-at-least-a-one/) | [Python](./1428-leftmost-column-with-at-least-a-one/1428-leftmost-column-with-at-least-a-one.py) | [Medium](./1428-leftmost-column-with-at-least-a-one/README.md) | -| 1436 | [Destination City](https://leetcode.com/problems/destination-city/) | [Python](./1436-destination-city/1436-destination-city.py) | [Easy](./1436-destination-city/README.md) | -| 1438 | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/) | [Python](./1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.py) | [Medium](./1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/README.md) | -| 1441 | [Build an Array With Stack Operations](https://leetcode.com/problems/build-an-array-with-stack-operations/) | [Python](./1441-build-an-array-with-stack-operations/1441-build-an-array-with-stack-operations.py) | [Easy](./1441-build-an-array-with-stack-operations/README.md) | -| 1442 | [Count Triplets That Can Form Two Arrays of Equal XOR](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/) | [Python](./1442-count-triplets-that-can-form-two-arrays-of-equal-xor/1442-count-triplets-that-can-form-two-arrays-of-equal-xor.py) | [Medium](./1442-count-triplets-that-can-form-two-arrays-of-equal-xor/README.md) | -| 1457 | [Pseudo-Palindromic Paths in a Binary Tree](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree/) | [Python](./1457-pseudo-palindromic-paths-in-a-binary-tree/1457-pseudo-palindromic-paths-in-a-binary-tree.py) | [Medium](./1457-pseudo-palindromic-paths-in-a-binary-tree/README.md) | -| 1458 | [Max Dot Product of Two Subsequences](https://leetcode.com/problems/max-dot-product-of-two-subsequences/) | [Python](./1458-max-dot-product-of-two-subsequences/1458-max-dot-product-of-two-subsequences.py) | [Hard](./1458-max-dot-product-of-two-subsequences/README.md) | -| 1460 | [Make Two Arrays Equal by Reversing Subarrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-subarrays/) | [Python](./1460-make-two-arrays-equal-by-reversing-subarrays/1460-make-two-arrays-equal-by-reversing-subarrays.py) | [Easy](./1460-make-two-arrays-equal-by-reversing-subarrays/README.md) | -| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [Python](./1463-cherry-pickup-ii/1463-cherry-pickup-ii.py) | [Hard](./1463-cherry-pickup-ii/README.md) | -| 1464 | [Maximum Product of Two Elements in an Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/) | [Python](./1464-maximum-product-of-two-elements-in-an-array/1464-maximum-product-of-two-elements-in-an-array.py) | [Easy](./1464-maximum-product-of-two-elements-in-an-array/README.md) | -| 1469 | [Find All The Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes/) | [Python](./1469-find-all-the-lonely-nodes/1469-find-all-the-lonely-nodes.py) | [Easy](./1469-find-all-the-lonely-nodes/README.md) | -| 1470 | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/) | [Python](./1470-shuffle-the-array/1470-shuffle-the-array.py) | [Easy](./1470-shuffle-the-array/README.md) | -| 1481 | [Least Number of Unique Integers after K Removals](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/) | [Python](./1481-least-number-of-unique-integers-after-k-removals/1481-least-number-of-unique-integers-after-k-removals.py) | [Medium](./1481-least-number-of-unique-integers-after-k-removals/README.md) | -| 1482 | [Minimum Number of Days to Make m Bouquets](https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/) | [Python](./1482-minimum-number-of-days-to-make-m-bouquets/1482-minimum-number-of-days-to-make-m-bouquets.py) | [Medium](./1482-minimum-number-of-days-to-make-m-bouquets/README.md) | -| 1489 | [Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/) | [Python](./1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.py) | [Hard](./1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/README.md) | -| 1496 | [Path Crossing](https://leetcode.com/problems/path-crossing/) | [Python](./1496-path-crossing/1496-path-crossing.py) | [Easy](./1496-path-crossing/README.md) | -| 1508 | [Range Sum of Sorted Subarray Sums](https://leetcode.com/problems/range-sum-of-sorted-subarray-sums/) | [Python](./1508-range-sum-of-sorted-subarray-sums/1508-range-sum-of-sorted-subarray-sums.py) | [Medium](./1508-range-sum-of-sorted-subarray-sums/README.md) | -| 1509 | [Minimum Difference Between Largest and Smallest Value in Three Moves](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves/) | [Python](./1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.py) | [Medium](./1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/README.md) | -| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) | [Python](./1512-number-of-good-pairs/1512-number-of-good-pairs.py) | [Easy](./1512-number-of-good-pairs/README.md) | -| 1518 | [Water Bottles](https://leetcode.com/problems/water-bottles/) | [Python](./1518-water-bottles/1518-water-bottles.py) | [Easy](./1518-water-bottles/README.md) | -| 1530 | [Number of Good Leaf Nodes Pairs](https://leetcode.com/problems/number-of-good-leaf-nodes-pairs/) | [Python](./1530-number-of-good-leaf-nodes-pairs/1530-number-of-good-leaf-nodes-pairs.py) | [Medium](./1530-number-of-good-leaf-nodes-pairs/README.md) | -| 1531 | [String Compression II](https://leetcode.com/problems/string-compression-ii/) | [Python](./1531-string-compression-ii/1531-string-compression-ii.py) | [Hard](./1531-string-compression-ii/README.md) | -| 1535 | [Find the Winner of an Array Game](https://leetcode.com/problems/find-the-winner-of-an-array-game/) | [Python](./1535-find-the-winner-of-an-array-game/1535-find-the-winner-of-an-array-game.py) | [Medium](./1535-find-the-winner-of-an-array-game/README.md) | -| 1544 | [Make The String Great](https://leetcode.com/problems/make-the-string-great/) | [Python](./1544-make-the-string-great/1544-make-the-string-great.py) | [Easy](./1544-make-the-string-great/README.md) | -| 1550 | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds/) | [Python](./1550-three-consecutive-odds/1550-three-consecutive-odds.py) | [Medium](./1550-three-consecutive-odds/README.md) | -| 1552 | [Magnetic Force Between Two Balls](https://leetcode.com/problems/magnetic-force-between-two-balls/) | [Python](./1552-magnetic-force-between-two-balls/1552-magnetic-force-between-two-balls.py) | [Medium](./1552-magnetic-force-between-two-balls/README.md) | -| 1561 | [Maximum Number of Coins You Can Get](https://leetcode.com/problems/maximum-number-of-coins-you-can-get/) | [Python](./1561-maximum-number-of-coins-you-can-get/1561-maximum-number-of-coins-you-can-get.py) | [Medium](./1561-maximum-number-of-coins-you-can-get/README.md) | -| 1568 | [Minimum Number of Days to Disconnect Island](https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island/) | [Python](./1568-minimum-number-of-days-to-disconnect-island/1568-minimum-number-of-days-to-disconnect-island.py) | [Hard](./1568-minimum-number-of-days-to-disconnect-island/README.md) | -| 1578 | [Minimum Deletion Cost to Avoid Repeating Letters](https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters/) | [Python](./1578-minimum-deletion-cost-to-avoid-repeating-letters/1578-minimum-deletion-cost-to-avoid-repeating-letters.py) | [Medium](./1578-minimum-deletion-cost-to-avoid-repeating-letters/README.md) | -| 1579 | [Remove Max Number of Edges to Keep Graph Fully Traversable](https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/) | [Python](./1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable.py) | [Hard](./1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/README.md) | -| 1580 | [Put Boxes Into the Warehouse II](https://leetcode.com/problems/put-boxes-into-the-warehouse-ii/) | [Python](./1580-put-boxes-into-the-warehouse-ii/1580-put-boxes-into-the-warehouse-ii.py) | [Medium](./1580-put-boxes-into-the-warehouse-ii/README.md) | -| 1582 | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix/) | [Python](./1582-special-positions-in-a-binary-matrix/1582-special-positions-in-a-binary-matrix.py) | [Easy](./1582-special-positions-in-a-binary-matrix/README.md) | -| 1584 | [Min Cost to Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points/) | [Python](./1584-min-cost-to-connect-all-points/1584-min-cost-to-connect-all-points.py) | [Medium](./1584-min-cost-to-connect-all-points/README.md) | -| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/) | [Python](./1598-crawler-log-folder/1598-crawler-log-folder.py) | [Easy](./1598-crawler-log-folder/README.md) | -| 1605 | [Find Valid Matrix Given Row and Column Sums](https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums/) | [Python](./1605-find-valid-matrix-given-row-and-column-sums/1605-find-valid-matrix-given-row-and-column-sums.py) | [Medium](./1605-find-valid-matrix-given-row-and-column-sums/README.md) | -| 1608 | [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/) | [Python](./1608-special-array-with-x-elements-greater-than-or-equal-x/1608-special-array-with-x-elements-greater-than-or-equal-x.py) | [Easy](./1608-special-array-with-x-elements-greater-than-or-equal-x/README.md) | -| 1609 | [Even Odd Tree](https://leetcode.com/problems/even-odd-tree/) | [Python](./1609-even-odd-tree/1609-even-odd-tree.py) | [Medium](./1609-even-odd-tree/README.md) | -| 1611 | [Minimum One Bit Operations to Make Integers Zero](https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero/) | [Python](./1611-minimum-one-bit-operations-to-make-integers-zero/1611-minimum-one-bit-operations-to-make-integers-zero.py) | [Hard](./1611-minimum-one-bit-operations-to-make-integers-zero/README.md) | -| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/) | [Python](./1614-maximum-nesting-depth-of-the-parentheses/1614-maximum-nesting-depth-of-the-parentheses.py) | [Easy](./1614-maximum-nesting-depth-of-the-parentheses/README.md) | -| 1615 | [Maximal Network Rank](https://leetcode.com/problems/maximal-network-rank/) | [Python](./1615-maximal-network-rank/1615-maximal-network-rank.py) | [Medium](./1615-maximal-network-rank/README.md) | -| 1630 | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/) | [Python](./1630-arithmetic-subarrays/1630-arithmetic-subarrays.py) | [Medium](./1630-arithmetic-subarrays/README.md) | -| 1631 | [Path With Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort/) | [Python](./1631-path-with-minimum-effort/1631-path-with-minimum-effort.py) | [Medium](./1631-path-with-minimum-effort/README.md) | -| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/) | [Python](./1636-sort-array-by-increasing-frequency/1636-sort-array-by-increasing-frequency.py) | [Easy](./1636-sort-array-by-increasing-frequency/README.md) | -| 1637 | [Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/) | [Python](./1637-widest-vertical-area-between-two-points-containing-no-points/1637-widest-vertical-area-between-two-points-containing-no-points.py) | [Medium](./1637-widest-vertical-area-between-two-points-containing-no-points/README.md) | -| 1642 | [Furthest Building You Can Reach](https://leetcode.com/problems/furthest-building-you-can-reach/) | [Python](./1642-furthest-building-you-can-reach/1642-furthest-building-you-can-reach.py) | [Medium](./1642-furthest-building-you-can-reach/README.md) | -| 1647 | [Minimum Deletions to Make Character Frequencies Unique](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/) | [Python](./1647-minimum-deletions-to-make-character-frequencies-unique/1647-minimum-deletions-to-make-character-frequencies-unique.py) | [Medium](./1647-minimum-deletions-to-make-character-frequencies-unique/README.md) | -| 1653 | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/) | [Python](./1653-minimum-deletions-to-make-string-balanced/1653-minimum-deletions-to-make-string-balanced.py) | [Medium](./1653-minimum-deletions-to-make-string-balanced/README.md) | -| 1657 | [Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close/) | [Python](./1657-determine-if-two-strings-are-close/1657-determine-if-two-strings-are-close.py) | [Medium](./1657-determine-if-two-strings-are-close/README.md) | -| 1658 | [Minimum Operations to Reduce X to Zero](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero/) | [Python](./1658-minimum-operations-to-reduce-x-to-zero/1658-minimum-operations-to-reduce-x-to-zero.py) | [Medium](./1658-minimum-operations-to-reduce-x-to-zero/README.md) | -| 1660 | [Correct a Binary Tree](https://leetcode.com/problems/correct-a-binary-tree/) | [Python](./1660-correct-a-binary-tree/1660-correct-a-binary-tree.py) | [Medium](./1660-correct-a-binary-tree/README.md) | -| 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/) | [Python](./1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.py) | [Easy](./1662-check-if-two-string-arrays-are-equivalent/README.md) | -| 1669 | [Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists/) | [Python](./1669-merge-in-between-linked-lists/1669-merge-in-between-linked-lists.py) | [Medium](./1669-merge-in-between-linked-lists/README.md) | -| 1683 | [Invalid Tweets](https://leetcode.com/problems/invalid-tweets/) | [SQL](./1683-invalid-tweets/1683-invalid-tweets.sql) | [Easy](./1683-invalid-tweets/README.md) | -| 1685 | [Sum of Absolute Differences in a Sorted Array](https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array/) | [Python](./1685-sum-of-absolute-differences-in-a-sorted-array/1685-sum-of-absolute-differences-in-a-sorted-array.py) | [Medium](./1685-sum-of-absolute-differences-in-a-sorted-array/README.md) | -| 1688 | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament/) | [Python](./1688-count-of-matches-in-tournament/1688-count-of-matches-in-tournament.py) | [Easy](./1688-count-of-matches-in-tournament/README.md) | -| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/) | [Python](./1700-number-of-students-unable-to-eat-lunch/1700-number-of-students-unable-to-eat-lunch.py) | [Easy](./1700-number-of-students-unable-to-eat-lunch/README.md) | -| 1701 | [Average Waiting Time](https://leetcode.com/problems/average-waiting-time/) | [Python](./1701-average-waiting-time/1701-average-waiting-time.py) | [Medium](./1701-average-waiting-time/README.md) | -| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike/) | [Python](./1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.py) | [Easy](./1704-determine-if-string-halves-are-alike/README.md) | -| 1716 | [Calculate Money in Leetcode Bank](https://leetcode.com/problems/calculate-money-in-leetcode-bank/) | [Python](./1716-calculate-money-in-leetcode-bank/1716-calculate-money-in-leetcode-bank.py) | [Easy](./1716-calculate-money-in-leetcode-bank/README.md) | -| 1717 | [Maximum Score From Removing Substrings](https://leetcode.com/problems/maximum-score-from-removing-substrings/) | [Python](./1717-maximum-score-from-removing-substrings/1717-maximum-score-from-removing-substrings.py) | [Medium](./1717-maximum-score-from-removing-substrings/README.md) | -| 1727 | [Largest Submatrix With Rearrangements](https://leetcode.com/problems/largest-submatrix-with-rearrangements/) | [Python](./1727-largest-submatrix-with-rearrangements/1727-largest-submatrix-with-rearrangements.py) | [Medium](./1727-largest-submatrix-with-rearrangements/README.md) | -| 1740 | [Find Distance in a Binary Tree](https://leetcode.com/problems/find-distance-in-a-binary-tree/) | [Python](./1740-find-distance-in-a-binary-tree/1740-find-distance-in-a-binary-tree.py) | [Medium](./1740-find-distance-in-a-binary-tree/README.md) | -| 1743 | [Restore the Array From Adjacent Pairs](https://leetcode.com/problems/restore-the-array-from-adjacent-pairs/) | [Python](./1743-restore-the-array-from-adjacent-pairs/1743-restore-the-array-from-adjacent-pairs.py) | [Medium](./1743-restore-the-array-from-adjacent-pairs/README.md) | -| 1750 | [Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/) | [Python](./1750-minimum-length-of-string-after-deleting-similar-ends/1750-minimum-length-of-string-after-deleting-similar-ends.py) | [Medium](./1750-minimum-length-of-string-after-deleting-similar-ends/README.md) | -| 1757 | [Recyclable and Low Fat Products](https://leetcode.com/problems/recyclable-and-low-fat-products/) | [SQL](./1757-recyclable-and-low-fat-products/1757-recyclable-and-low-fat-products.sql) | [Medium](./1757-recyclable-and-low-fat-products/README.md) | -| 1758 | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/) | [Python](./1758-minimum-changes-to-make-alternating-binary-string/1758-minimum-changes-to-make-alternating-binary-string.py) | [Easy](./1758-minimum-changes-to-make-alternating-binary-string/README.md) | -| 1759 | [Count Number of Homogenous Substrings](https://leetcode.com/problems/count-number-of-homogenous-substrings/) | [Python](./1759-count-number-of-homogenous-substrings/1759-count-number-of-homogenous-substrings.py) | [Medium](./1759-count-number-of-homogenous-substrings/README.md) | -| 1768 | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately/) | [Python](./1768-merge-strings-alternately/1768-merge-strings-alternately.py) | [Easy](./1768-merge-strings-alternately/README.md) | -| 1791 | [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph/) | [Python](./1791-find-center-of-star-graph/1791-find-center-of-star-graph.py) | [Easy](./1791-find-center-of-star-graph/README.md) | -| 1793 | [Maximum Score of a Good Subarray](https://leetcode.com/problems/maximum-score-of-a-good-subarray/) | [Python](./1793-maximum-score-of-a-good-subarray/1793-maximum-score-of-a-good-subarray.py) | [Hard](./1793-maximum-score-of-a-good-subarray/README.md) | -| 1802 | [Maximum Value at a Given Index in a Bounded Array](https://leetcode.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | [Python](./1802-maximum-value-at-a-given-index-in-a-bounded-array/1802-maximum-value-at-a-given-index-in-a-bounded-array.py) | [Medium](./1802-maximum-value-at-a-given-index-in-a-bounded-array/README.md) | -| 1804 | [Implement Trie II (Prefix Tree)](https://leetcode.com/problems/implement-trie-ii-prefix-tree/) | [Python](./1804-implement-trie-ii-prefix-tree/1804-implement-trie-ii-prefix-tree.py) | [Medium](./1804-implement-trie-ii-prefix-tree/README.md) | -| 1814 | [Count Nice Pairs in an Array](https://leetcode.com/problems/count-nice-pairs-in-an-array/) | [Python](./1814-count-nice-pairs-in-an-array/1814-count-nice-pairs-in-an-array.py) | [Medium](./1814-count-nice-pairs-in-an-array/README.md) | -| 1836 | [Remove Duplicates from an Unsorted Linked List](https://leetcode.com/problems/remove-duplicates-from-an-unsorted-linked-list/) | [Python](./1836-remove-duplicates-from-an-unsorted-linked-list/1836-remove-duplicates-from-an-unsorted-linked-list.py) | [Medium](./1836-remove-duplicates-from-an-unsorted-linked-list/README.md) | -| 1838 | [Frequency of the Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element/) | [Python](./1838-frequency-of-the-most-frequent-element/1838-frequency-of-the-most-frequent-element.py) | [Medium](./1838-frequency-of-the-most-frequent-element/README.md) | -| 1845 | [Seat Reservation Manager](https://leetcode.com/problems/seat-reservation-manager/) | [Python](./1845-seat-reservation-manager/1845-seat-reservation-manager.py) | [Medium](./1845-seat-reservation-manager/README.md) | -| 1846 | [Maximum Element After Decreasing and Rearranging](https://leetcode.com/problems/maximum-element-after-decreasing-and-rearranging/) | [Python](./1846-maximum-element-after-decreasing-and-rearranging/1846-maximum-element-after-decreasing-and-rearranging.py) | [Medium](./1846-maximum-element-after-decreasing-and-rearranging/README.md) | -| 1863 | [Sum of All Subset XOR Totals](https://leetcode.com/problems/sum-of-all-subset-xor-totals/) | [Python](./1863-sum-of-all-subset-xor-totals/1863-sum-of-all-subset-xor-totals.py) | [Easy](./1863-sum-of-all-subset-xor-totals/README.md) | -| 1870 | [Minimum Speed to Arrive on Time](https://leetcode.com/problems/minimum-speed-to-arrive-on-time/) | [Python](./1870-minimum-speed-to-arrive-on-time/1870-minimum-speed-to-arrive-on-time.py) | [Medium](./1870-minimum-speed-to-arrive-on-time/README.md) | -| 1877 | [Minimize Maximum Pair Sum in Array](https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/) | [Python](./1877-minimize-maximum-pair-sum-in-array/1877-minimize-maximum-pair-sum-in-array.py) | [Medium](./1877-minimize-maximum-pair-sum-in-array/README.md) | -| 1885 | [Count Pairs in Two Arrays](https://leetcode.com/problems/count-pairs-in-two-arrays/) | [Python](./1885-count-pairs-in-two-arrays/1885-count-pairs-in-two-arrays.py) | [Medium](./1885-count-pairs-in-two-arrays/README.md) | -| 1887 | [Reduction Operations to Make the Array Elements Equal](https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal/) | [Python](./1887-reduction-operations-to-make-the-array-elements-equal/1887-reduction-operations-to-make-the-array-elements-equal.py) | [Medium](./1887-reduction-operations-to-make-the-array-elements-equal/README.md) | -| 1897 | [Redistribute Characters to Make All Strings Equal](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/) | [Python](./1897-redistribute-characters-to-make-all-strings-equal/1897-redistribute-characters-to-make-all-strings-equal.py) | [Easy](./1897-redistribute-characters-to-make-all-strings-equal/README.md) | -| 1903 | [Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string/) | [Python](./1903-largest-odd-number-in-string/1903-largest-odd-number-in-string.py) | [Easy](./1903-largest-odd-number-in-string/README.md) | -| 1913 | [Maximum Product Difference Between Two Pairs](https://leetcode.com/problems/maximum-product-difference-between-two-pairs/) | [Python](./1913-maximum-product-difference-between-two-pairs/1913-maximum-product-difference-between-two-pairs.py) | [Easy](./1913-maximum-product-difference-between-two-pairs/README.md) | -| 1915 | [Number of Wonderful Substrings](https://leetcode.com/problems/number-of-wonderful-substrings/) | [Python](./1915-number-of-wonderful-substrings/1915-number-of-wonderful-substrings.py) | [Medium](./1915-number-of-wonderful-substrings/README.md) | -| 1920 | [Build Array from Permutation](https://leetcode.com/problems/build-array-from-permutation/) | [C++](./1920-build-array-from-permutation/1920-build-array-from-permutation.cpp) | [Easy](./1920-build-array-from-permutation/README.md) | -| 1921 | [Eliminate Maximum Number of Monsters](https://leetcode.com/problems/eliminate-maximum-number-of-monsters/) | [Python](./1921-eliminate-maximum-number-of-monsters/1921-eliminate-maximum-number-of-monsters.py) | [Medium](./1921-eliminate-maximum-number-of-monsters/README.md) | -| 1930 | [Unique Length-3 Palindromic Subsequences](https://leetcode.com/problems/unique-length-3-palindromic-subsequences/) | [Python](./1930-unique-length-3-palindromic-subsequences/1930-unique-length-3-palindromic-subsequences.py) | [Medium](./1930-unique-length-3-palindromic-subsequences/README.md) | -| 1937 | [Maximum Number of Points with Cost](https://leetcode.com/problems/maximum-number-of-points-with-cost/) | [Python](./1937-maximum-number-of-points-with-cost/1937-maximum-number-of-points-with-cost.py) | [Medium](./1937-maximum-number-of-points-with-cost/README.md) | -| 1940 | [Longest Common Subsequence Between Sorted Arrays](https://leetcode.com/problems/longest-common-subsequence-between-sorted-arrays/) | [Python](./1940-longest-common-subsequence-between-sorted-arrays/1940-longest-common-subsequence-between-sorted-arrays.py) | [Medium](./1940-longest-common-subsequence-between-sorted-arrays/README.md) | -| 1971 | [Find if Path Exists in Graph](https://leetcode.com/problems/find-if-path-exists-in-graph/) | [Python](./1971-find-if-path-exists-in-graph/1971-find-if-path-exists-in-graph.py) | [Easy](./1971-find-if-path-exists-in-graph/README.md) | -| 1973 | [Count Nodes Equal to Sum of Descendants](https://leetcode.com/problems/count-nodes-equal-to-sum-of-descendants/) | [Python](./1973-count-nodes-equal-to-sum-of-descendants/1973-count-nodes-equal-to-sum-of-descendants.py) | [Medium](./1973-count-nodes-equal-to-sum-of-descendants/README.md) | -| 1980 | [Find Unique Binary String](https://leetcode.com/problems/find-unique-binary-string/) | [Python](./1980-find-unique-binary-string/1980-find-unique-binary-string.py) | [Medium](./1980-find-unique-binary-string/README.md) | -| 1992 | [Find All Groups of Farmland](https://leetcode.com/problems/find-all-groups-of-farmland/) | [Python](./1992-find-all-groups-of-farmland/1992-find-all-groups-of-farmland.py) | [Medium](./1992-find-all-groups-of-farmland/README.md) | -| 2000 | [Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word/) | [Python](./2000-reverse-prefix-of-word/2000-reverse-prefix-of-word.py) | [Easy](./2000-reverse-prefix-of-word/README.md) | -| 2009 | [Minimum Number of Operations to Make Array Continuous](https://leetcode.com/problems/minimum-number-of-operations-to-make-array-continuous/) | [Python](./2009-minimum-number-of-operations-to-make-array-continuous/2009-minimum-number-of-operations-to-make-array-continuous.py) | [Hard](./2009-minimum-number-of-operations-to-make-array-continuous/README.md) | -| 2037 | [Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/) | [Python](./2037-minimum-number-of-moves-to-seat-everyone/2037-minimum-number-of-moves-to-seat-everyone.py) | [Easy](./2037-minimum-number-of-moves-to-seat-everyone/README.md) | -| 2038 | [Remove Colored Pieces if Both Neighbors are the Same Color](https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/) | [Python](./2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.py) | [Medium](./2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/README.md) | -| 2045 | [Second Minimum Time to Reach Destination](https://leetcode.com/problems/second-minimum-time-to-reach-destination/) | [Python](./2045-second-minimum-time-to-reach-destination/2045-second-minimum-time-to-reach-destination.py) | [Hard](./2045-second-minimum-time-to-reach-destination/README.md) | -| 2050 | [Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string/) | [Python](./2050-number-of-different-integers-in-a-string/2050-number-of-different-integers-in-a-string.py) | [Easy](./2050-number-of-different-integers-in-a-string/README.md) | -| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array/) | [Python](./2053-kth-distinct-string-in-an-array/2053-kth-distinct-string-in-an-array.py) | [Easy](./2053-kth-distinct-string-in-an-array/README.md) | -| 2058 | [Find the Minimum and Maximum Number of Nodes Between Critical Points](https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/) | [Python](./2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.py) | [Medium](./2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/README.md) | -| 2061 | [Number of Spaces Cleaning Robot Cleaned](https://leetcode.com/problems/number-of-spaces-cleaning-robot-cleaned/) | [Python](./2061-number-of-spaces-cleaning-robot-cleaned/2061-number-of-spaces-cleaning-robot-cleaned.py) | [Medium](./2061-number-of-spaces-cleaning-robot-cleaned/README.md) | -| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets/) | [Python](./2073-time-needed-to-buy-tickets/2073-time-needed-to-buy-tickets.py) | [Easy](./2073-time-needed-to-buy-tickets/README.md) | -| 2083 | [Substrings That Begin and End With the Same Letter](https://leetcode.com/problems/substrings-that-begin-and-end-with-the-same-letter/) | [Python](./2083-substrings-that-begin-and-end-with-the-same-letter/2083-substrings-that-begin-and-end-with-the-same-letter.py) | [Medium](./2083-substrings-that-begin-and-end-with-the-same-letter/README.md) | -| 2092 | [Find All People With Secret](https://leetcode.com/problems/find-all-people-with-secret/) | [Python](./2092-find-all-people-with-secret/2092-find-all-people-with-secret.py) | [Hard](./2092-find-all-people-with-secret/README.md) | -| 2093 | [Minimum Cost to Reach City With Discounts](https://leetcode.com/problems/minimum-cost-to-reach-city-with-discounts/) | [Python](./2093-minimum-cost-to-reach-city-with-discounts/2093-minimum-cost-to-reach-city-with-discounts.py) | [Medium](./2093-minimum-cost-to-reach-city-with-discounts/README.md) | -| 2096 | [Step-By-Step Directions From a Binary Tree Node to Another](https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another/) | [Python](./2096-step-by-step-directions-from-a-binary-tree-node-to-another/2096-step-by-step-directions-from-a-binary-tree-node-to-another.py) | [Medium](./2096-step-by-step-directions-from-a-binary-tree-node-to-another/README.md) | -| 2108 | [Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array/) | [Python](./2108-find-first-palindromic-string-in-the-array/2108-find-first-palindromic-string-in-the-array.py) | [Medium](./2108-find-first-palindromic-string-in-the-array/README.md) | -| 2125 | [Number of Laser Beams in a Bank](https://leetcode.com/problems/number-of-laser-beams-in-a-bank/) | [Python](./2125-number-of-laser-beams-in-a-bank/2125-number-of-laser-beams-in-a-bank.py) | [Medium](./2125-number-of-laser-beams-in-a-bank/README.md) | -| 2134 | [Minimum Swaps to Group All 1's Together II](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/) | [Python](./2134-minimum-swaps-to-group-all-1s-together-ii/2134-minimum-swaps-to-group-all-1s-together-ii.py) | [Medium](./2134-minimum-swaps-to-group-all-1s-together-ii/README.md) | -| 2141 | [Maximum Running Time of N Computers](https://leetcode.com/problems/maximum-running-time-of-n-computers/) | [Python](./2141-maximum-running-time-of-n-computers/2141-maximum-running-time-of-n-computers.py) | [Hard](./2141-maximum-running-time-of-n-computers/README.md) | -| 2147 | [Number of Ways to Divide a Long Corridor](https://leetcode.com/problems/number-of-ways-to-divide-a-long-corridor/) | [Python](./2147-number-of-ways-to-divide-a-long-corridor/2147-number-of-ways-to-divide-a-long-corridor.py) | [Hard](./2147-number-of-ways-to-divide-a-long-corridor/README.md) | -| 2149 | [Rearrange Array Elements by Sign](https://leetcode.com/problems/rearrange-array-elements-by-sign/) | [Python](./2149-rearrange-array-elements-by-sign/2149-rearrange-array-elements-by-sign.py) | [Medium](./2149-rearrange-array-elements-by-sign/README.md) | -| 2181 | [Merge Nodes in Between Zeros](https://leetcode.com/problems/merge-nodes-in-between-zeros/) | [Python](./2181-merge-nodes-in-between-zeros/2181-merge-nodes-in-between-zeros.py) | [Medium](./2181-merge-nodes-in-between-zeros/README.md) | -| 2192 | [All Ancestors of a Node in a Directed Acyclic Graph](https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/) | [Python](./2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph.py) | [Medium](./2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/README.md) | -| 2196 | [Create Binary Tree From Descriptions](https://leetcode.com/problems/create-binary-tree-from-descriptions/) | [Python](./2196-create-binary-tree-from-descriptions/2196-create-binary-tree-from-descriptions.py) | [Medium](./2196-create-binary-tree-from-descriptions/README.md) | -| 2225 | [Find Players With Zero or One Losses](https://leetcode.com/problems/find-players-with-zero-or-one-losses/) | [Python](./2225-find-players-with-zero-or-one-losses/2225-find-players-with-zero-or-one-losses.py) | [Medium](./2225-find-players-with-zero-or-one-losses/README.md) | -| 2251 | [Number of Flowers in Full Bloom](https://leetcode.com/problems/number-of-flowers-in-full-bloom/) | [Python](./2251-number-of-flowers-in-full-bloom/2251-number-of-flowers-in-full-bloom.py) | [Hard](./2251-number-of-flowers-in-full-bloom/README.md) | -| 2264 | [Largest 3-Same-Digit Number in String](https://leetcode.com/problems/largest-3-same-digit-number-in-string/) | [Python](./2264-largest-3-same-digit-number-in-string/2264-largest-3-same-digit-number-in-string.py) | [Easy](./2264-largest-3-same-digit-number-in-string/README.md) | -| 2265 | [Count Nodes Equal to Average of Subtree](https://leetcode.com/problems/count-nodes-equal-to-average-of-subtree/) | [Python](./2265-count-nodes-equal-to-average-of-subtree/2265-count-nodes-equal-to-average-of-subtree.py) | [Medium](./2265-count-nodes-equal-to-average-of-subtree/README.md) | -| 2285 | [Maximum Total Importance of Roads](https://leetcode.com/problems/maximum-total-importance-of-roads/) | [Python](./2285-maximum-total-importance-of-roads/2285-maximum-total-importance-of-roads.py) | [Medium](./2285-maximum-total-importance-of-roads/README.md) | -| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree/) | [Python](./2331-evaluate-boolean-binary-tree/2331-evaluate-boolean-binary-tree.py) | [Easy](./2331-evaluate-boolean-binary-tree/README.md) | -| 2353 | [Design a Food Rating System](https://leetcode.com/problems/design-a-food-rating-system/) | [Python](./2353-design-a-food-rating-system/2353-design-a-food-rating-system.py) | [Medium](./2353-design-a-food-rating-system/README.md) | -| 2355 | [Maximum Number of Books You Can Take](https://leetcode.com/problems/maximum-number-of-books-you-can-take/) | [Python](./2355-maximum-number-of-books-you-can-take/2355-maximum-number-of-books-you-can-take.py) | [Hard](./2355-maximum-number-of-books-you-can-take/README.md) | -| 2361 | [Minimum Costs Using the Train Line](https://leetcode.com/problems/minimum-costs-using-the-train-line/) | [Python](./2361-minimum-costs-using-the-train-line/2361-minimum-costs-using-the-train-line.py) | [Hard](./2361-minimum-costs-using-the-train-line/README.md) | -| 2366 | [Minimum Replacements to Sort the Array](https://leetcode.com/problems/minimum-replacements-to-sort-the-array/) | [Python](./2366-minimum-replacements-to-sort-the-array/2366-minimum-replacements-to-sort-the-array.py) | [Hard](./2366-minimum-replacements-to-sort-the-array/README.md) | -| 2369 | [Check If There Is a Valid Partition for the Array](https://leetcode.com/problems/check-if-there-is-a-valid-partition-for-the-array/) | [Python](./2369-check-if-there-is-a-valid-partition-for-the-array/2369-check-if-there-is-a-valid-partition-for-the-array.py) | [Medium](./2369-check-if-there-is-a-valid-partition-for-the-array/README.md) | -| 2370 | [Longest Ideal Subsequence](https://leetcode.com/problems/longest-ideal-subsequence/) | [Python](./2370-longest-ideal-subsequence/2370-longest-ideal-subsequence.py) | [Medium](./2370-longest-ideal-subsequence/README.md) | -| 2373 | [Largest Local Values in a Matrix](https://leetcode.com/problems/largest-local-values-in-a-matrix/) | [Python](./2373-largest-local-values-in-a-matrix/2373-largest-local-values-in-a-matrix.py) | [Easy](./2373-largest-local-values-in-a-matrix/README.md) | -| 2385 | [Amount of Time for Binary Tree to be Infected](https://leetcode.com/problems/amount-of-time-for-binary-tree-to-be-infected/) | [Python](./2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.py) | [Medium](./2385-amount-of-time-for-binary-tree-to-be-infected/README.md) | -| 2391 | [Minimum Amount of Time to Collect Garbage](https://leetcode.com/problems/minimum-amount-of-time-to-collect-garbage/) | [Python](./2391-minimum-amount-of-time-to-collect-garbage/2391-minimum-amount-of-time-to-collect-garbage.py) | [Medium](./2391-minimum-amount-of-time-to-collect-garbage/README.md) | -| 2392 | [Build a Matrix With Conditions](https://leetcode.com/problems/build-a-matrix-with-conditions/) | [Python](./2392-build-a-matrix-with-conditions/2392-build-a-matrix-with-conditions.py) | [Hard](./2392-build-a-matrix-with-conditions/README.md) | -| 2393 | [Count Strictly Increasing Subarrays](https://leetcode.com/problems/count-strictly-increasing-subarrays/) | [Python](./2393-count-strictly-increasing-subarrays/2393-count-strictly-increasing-subarrays.py) | [Medium](./2393-count-strictly-increasing-subarrays/README.md) | -| 2402 | [Meeting Rooms III](https://leetcode.com/problems/meeting-rooms-iii/) | [Python](./2402-meeting-rooms-iii/2402-meeting-rooms-iii.py) | [Hard](./2402-meeting-rooms-iii/README.md) | -| 2418 | [Sort the People](https://leetcode.com/problems/sort-the-people/) | [Python](./2418-sort-the-people/2418-sort-the-people.py) | [Easy](./2418-sort-the-people/README.md) | -| 2433 | [Find the Original Array of Prefix XOR](https://leetcode.com/problems/find-the-original-array-of-prefix-xor/) | [Python](./2433-find-the-original-array-of-prefix-xor/2433-find-the-original-array-of-prefix-xor.py) | [Medium](./2433-find-the-original-array-of-prefix-xor/README.md) | -| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/) | [Python](./2441-largest-positive-integer-that-exists-with-its-negative/2441-largest-positive-integer-that-exists-with-its-negative.py) | [Easy](./2441-largest-positive-integer-that-exists-with-its-negative/README.md) | -| 2444 | [Count Subarrays with Fixed Bounds](https://leetcode.com/problems/count-subarrays-with-fixed-bounds/) | [Python](./2444-count-subarrays-with-fixed-bounds/2444-count-subarrays-with-fixed-bounds.py) | [Hard](./2444-count-subarrays-with-fixed-bounds/README.md) | -| 2473 | [Minimum Cost to Buy Apples](https://leetcode.com/problems/minimum-cost-to-buy-apples/) | [Python](./2473-minimum-cost-to-buy-apples/2473-minimum-cost-to-buy-apples.py) | [Medium](./2473-minimum-cost-to-buy-apples/README.md) | -| 2482 | [Difference Between Ones and Zeros in Row and Column](https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column/) | [Python](./2482-difference-between-ones-and-zeros-in-row-and-column/2482-difference-between-ones-and-zeros-in-row-and-column.py) | [Medium](./2482-difference-between-ones-and-zeros-in-row-and-column/README.md) | -| 2483 | [Minimum Penalty for a Shop](https://leetcode.com/problems/minimum-penalty-for-a-shop/) | [Python](./2483-minimum-penalty-for-a-shop/2483-minimum-penalty-for-a-shop.py) | [Medium](./2483-minimum-penalty-for-a-shop/README.md) | -| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer/) | [Python](./2485-find-the-pivot-integer/2485-find-the-pivot-integer.py) | [Easy](./2485-find-the-pivot-integer/README.md) | -| 2486 | [Append Characters to String to Make Subsequence](https://leetcode.com/problems/append-characters-to-string-to-make-subsequence/) | [Python](./2486-append-characters-to-string-to-make-subsequence/2486-append-characters-to-string-to-make-subsequence.py) | [Medium](./2486-append-characters-to-string-to-make-subsequence/README.md) | -| 2487 | [Remove Nodes from Linked List](https://leetcode.com/problems/remove-nodes-from-linked-list/) | [Python](./2487-remove-nodes-from-linked-list/2487-remove-nodes-from-linked-list.py) | [Medium](./2487-remove-nodes-from-linked-list/README.md) | -| 2505 | [Bitwise OR of All Subarrays](https://leetcode.com/problems/bitwise-or-of-all-subarrays/) | [Python](./2505-bitwise-or-of-all-subsequence-sums/2505-bitwise-or-of-all-subsequence-sums.py) | [Medium](./2505-bitwise-or-of-all-subsequence-sums/README.md) | -| 2540 | [Minimum Common Value](https://leetcode.com/problems/minimum-common-value/) | [Python](./2540-minimum-common-value/2540-minimum-common-value.py) | [Easy](./2540-minimum-common-value/README.md) | -| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow/) | [Python](./2582-pass-the-pillow/2582-pass-the-pillow.py) | [Easy](./2582-pass-the-pillow/README.md) | -| 2597 | [The Number of Beautiful Subsets](https://leetcode.com/problems/the-number-of-beautiful-subsets/) | [Python](./2597-the-number-of-beautiful-subsets/2597-the-number-of-beautiful-subsets.py) | [Medium](./2597-the-number-of-beautiful-subsets/README.md) | -| 2610 | [Convert an Array into a 2D Array with Conditions](https://leetcode.com/problems/convert-an-array-into-a-2d-array-with-conditions/) | [Python](./2610-convert-an-array-into-a-2d-array-with-conditions/2610-convert-an-array-into-a-2d-array-with-conditions.py) | [Medium](./2610-convert-an-array-into-a-2d-array-with-conditions/README.md) | -| 2616 | [Minimize the Maximum Difference of Pairs](https://leetcode.com/problems/minimize-the-maximum-difference-of-pairs/) | [Python](./2616-minimize-the-maximum-difference-of-pairs/2616-minimize-the-maximum-difference-of-pairs.py) | [Medium](./2616-minimize-the-maximum-difference-of-pairs/README.md) | -| 2618 | [Check if Object Instance of Class](https://leetcode.com/problems/check-if-object-instance-of-class/) | [TypeScript](./2618-check-if-object-instance-of-class/2618-check-if-object-instance-of-class.ts) | [Medium](./2618-check-if-object-instance-of-class/README.md) | -| 2619 | [Array.prototype.last](https://leetcode.com/problems/array-prototype-last/) | [JavaScript](./2619-array-prototype-last/2619-array-prototype-last.js), [TypeScript](./2619-array-prototype-last/2619-array-prototype-last.ts) | [Easy](./2619-array-prototype-last/README.md) | -| 2620 | [Counter](https://leetcode.com/problems/counter/) | [JavaScript](./2620-counter/2620-counter.js), [TypeScript](./2620-counter/2620-counter.ts) | [Easy](./2620-counter/README.md) | -| 2621 | [Sleep](https://leetcode.com/problems/sleep/) | [JavaScript](./2621-sleep/2621-sleep.js), [TypeScript](./2621-sleep/2621-sleep.ts) | [Easy](./2621-sleep/README.md) | -| 2622 | [Cache with Time Limit](https://leetcode.com/problems/cache-with-time-limit/) | [JavaScript](./2622-cache-with-time-limit/2622-cache-with-time-limit.js), [TypeScript](./2622-cache-with-time-limit/2622-cache-with-time-limit.ts) | [Medium](./2622-cache-with-time-limit/README.md) | -| 2623 | [Memoize](https://leetcode.com/problems/memoize/) | [JavaScript](./2623-memoize/2623-memoize.js), [TypeScript](./2623-memoize/2623-memoize.ts) | [Medium](./2623-memoize/README.md) | -| 2624 | [Snail Traversal](https://leetcode.com/problems/snail-traversal/) | [TypeScript](./2624-snail-traversal/2624-snail-traversal.ts) | [Medium](./2624-snail-traversal/README.md) | -| 2625 | [Flatten Deeply Nested Array](https://leetcode.com/problems/flatten-deeply-nested-array/) | [JavaScript](./2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.js), [TypeScript](./2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.ts) | [Medium](./2625-flatten-deeply-nested-array/README.md) | -| 2626 | [Array Reduce Transformation](https://leetcode.com/problems/array-reduce-transformation/) | [JavaScript](./2626-array-reduce-transformation/2626-array-reduce-transformation.js), [TypeScript](./2626-array-reduce-transformation/2626-array-reduce-transformation.ts) | [Easy](./2626-array-reduce-transformation/README.md) | -| 2627 | [Debounce](https://leetcode.com/problems/debounce/) | [JavaScript](./2627-debounce/2627-debounce.js), [TypeScript](./2627-debounce/2627-debounce.ts) | [Medium](./2627-debounce/README.md) | -| 2628 | [JSON Deep Equal](https://leetcode.com/problems/json-deep-equal/) | [JavaScript](./2628-json-deep-equal/2628-json-deep-equal.js), [TypeScript](./2628-json-deep-equal/2628-json-deep-equal.ts) | [Medium](./2628-json-deep-equal/README.md) | -| 2629 | [Function Composition](https://leetcode.com/problems/function-composition/) | [JavaScript](./2629-function-composition/2629-function-composition.js), [TypeScript](./2629-function-composition/2629-function-composition.ts) | [Easy](./2629-function-composition/README.md) | -| 2630 | [Memoize II](https://leetcode.com/problems/memoize-ii/) | [TypeScript](./2630-memoize-ii/2630-memoize-ii.ts) | [Hard](./2630-memoize-ii/README.md) | -| 2631 | [Group By](https://leetcode.com/problems/group-by/) | [JavaScript](./2631-group-by/2631-group-by.js), [TypeScript](./2631-group-by/2631-group-by.ts) | [Medium](./2631-group-by/README.md) | -| 2632 | [Curry](https://leetcode.com/problems/curry/) | [JavaScript](./2632-curry/2632-curry.js), [TypeScript](./2632-curry/2632-curry.ts) | [Medium](./2632-curry/README.md) | -| 2633 | [Convert Object to JSON String](https://leetcode.com/problems/convert-object-to-json-string/) | [JavaScript](./2633-convert-object-to-json-string/2633-convert-object-to-json-string.js), [TypeScript](./2633-convert-object-to-json-string/2633-convert-object-to-json-string.ts) | [Medium](./2633-convert-object-to-json-string/README.md) | -| 2634 | [Filter Elements from Array](https://leetcode.com/problems/filter-elements-from-array/) | [JavaScript](./2634-filter-elements-from-array/2634-filter-elements-from-array.js), [TypeScript](./2634-filter-elements-from-array/2634-filter-elements-from-array.ts) | [Easy](./2634-filter-elements-from-array/README.md) | -| 2635 | [Apply Transform over Each Element in Array](https://leetcode.com/problems/apply-transform-over-each-element-in-array/) | [JavaScript](./2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.js), [TypeScript](./2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.ts) | [Easy](./2635-apply-transform-over-each-element-in-array/README.md) | -| 2636 | [Promise Pool](https://leetcode.com/problems/promise-pool/) | [JavaScript](./2636-promise-pool/2636-promise-pool.js), [TypeScript](./2636-promise-pool/2636-promise-pool.ts) | [Medium](./2636-promise-pool/README.md) | -| 2637 | [Promise Time Limit](https://leetcode.com/problems/promise-time-limit/) | [JavaScript](./2637-promise-time-limit/2637-promise-time-limit.js), [TypeScript](./2637-promise-time-limit/2637-promise-time-limit.ts) | [Medium](./2637-promise-time-limit/README.md) | -| 2642 | [Design Graph with Shortest Path Calculator](https://leetcode.com/problems/design-graph-with-shortest-path-calculator/) | [Python](./2642-design-graph-with-shortest-path-calculator/2642-design-graph-with-shortest-path-calculator.py) | [Hard](./2642-design-graph-with-shortest-path-calculator/README.md) | -| 2648 | [Generate Fibonacci Sequence](https://leetcode.com/problems/generate-fibonacci-sequence/) | [TypeScript](./2648-generate-fibonacci-sequence/2648-generate-fibonacci-sequence.ts) | [Easy](./2648-generate-fibonacci-sequence/README.md) | -| 2649 | [Nested Array Generator](https://leetcode.com/problems/nested-array-generator/) | [TypeScript](./2649-nested-array-generator/2649-nested-array-generator.ts) | [Medium](./2649-nested-array-generator/README.md) | -| 2650 | [Design Cancellable Function](https://leetcode.com/problems/design-cancellable-function/) | [TypeScript](./2650-design-cancellable-function/2650-design-cancellable-function.ts) | [Hard](./2650-design-cancellable-function/README.md) | -| 2665 | [Counter II](https://leetcode.com/problems/counter-ii/) | [JavaScript](./2665-counter-ii/2665-counter-ii.js), [TypeScript](./2665-counter-ii/2665-counter-ii.ts) | [Easy](./2665-counter-ii/README.md) | -| 2666 | [Allow One Function Call](https://leetcode.com/problems/allow-one-function-call/) | [JavaScript](./2666-allow-one-function-call/2666-allow-one-function-call.js), [TypeScript](./2666-allow-one-function-call/2666-allow-one-function-call.ts) | [Easy](./2666-allow-one-function-call/README.md) | -| 2667 | [Create Hello World Function](https://leetcode.com/problems/create-hello-world-function/) | [JavaScript](./2667-create-hello-world-function/2667-create-hello-world-function.js), [TypeScript](./2667-create-hello-world-function/2667-create-hello-world-function.ts) | [Easy](./2667-create-hello-world-function/README.md) | -| 2675 | [Array of Objects to Matrix](https://leetcode.com/problems/array-of-objects-to-matrix/) | [TypeScript](./2675-array-of-objects-to-matrix/2675-array-of-objects-to-matrix.ts) | [Hard](./2675-array-of-objects-to-matrix/README.md) | -| 2676 | [Throttle](https://leetcode.com/problems/throttle/) | [JavaScript](./2676-throttle/2676-throttle.js), [TypeScript](./2676-throttle/2676-throttle.ts) | [Medium](./2676-throttle/README.md) | -| 2677 | [Chunk Array](https://leetcode.com/problems/chunk-array/) | [JavaScript](./2677-chunk-array/2677-chunk-array.js), [TypeScript](./2677-chunk-array/2677-chunk-array.ts) | [Easy](./2677-chunk-array/README.md) | -| 2678 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens/) | [Python](./2678-number-of-senior-citizens/2678-number-of-senior-citizens.py) | [Easy](./2678-number-of-senior-citizens/README.md) | -| 2690 | [Infinite Method Object](https://leetcode.com/problems/infinite-method-object/) | [TypeScript](./2690-infinite-method-object/2690-infinite-method-object.ts) | [Easy](./2690-infinite-method-object/README.md) | -| 2692 | [Make Object Immutable](https://leetcode.com/problems/make-object-immutable/) | [TypeScript](./2692-make-object-immutable/2692-make-object-immutable.ts) | [Medium](./2692-make-object-immutable/README.md) | -| 2694 | [Event Emitter](https://leetcode.com/problems/event-emitter/) | [JavaScript](./2694-event-emitter/2694-event-emitter.js) | [Medium](./2694-event-emitter/README.md) | -| 2695 | [Array Wrapper](https://leetcode.com/problems/array-wrapper/) | [JavaScript](./2695-array-wrapper/2695-array-wrapper.js) | [Easy](./2695-array-wrapper/README.md) | -| 2703 | [Return Length of Arguments Passed](https://leetcode.com/problems/return-length-of-arguments-passed/) | [JavaScript](./2703-return-length-of-arguments-passed/2703-return-length-of-arguments-passed.js) | [Easy](./2703-return-length-of-arguments-passed/README.md) | -| 2704 | [To Be or Not To Be](https://leetcode.com/problems/to-be-or-not-to-be/) | [JavaScript](./2704-to-be-or-not-to-be/2704-to-be-or-not-to-be.js) | [Easy](./2704-to-be-or-not-to-be/README.md) | -| 2705 | [Compact Object](https://leetcode.com/problems/compact-object/) | [JavaScript](./2705-compact-object/2705-compact-object.js) | [Medium](./2705-compact-object/README.md) | -| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates/) | [Python](./2706-buy-two-chocolates/2706-buy-two-chocolates.py) | [Easy](./2706-buy-two-chocolates/README.md) | -| 2707 | [Extra Characters in a String](https://leetcode.com/problems/extra-characters-in-a-string/) | [Python](./2707-extra-characters-in-a-string/2707-extra-characters-in-a-string.py) | [Medium](./2707-extra-characters-in-a-string/README.md) | -| 2709 | [Greatest Common Divisor Traversal](https://leetcode.com/problems/greatest-common-divisor-traversal/) | [Python](./2709-greatest-common-divisor-traversal/2709-greatest-common-divisor-traversal.py) | [Hard](./2709-greatest-common-divisor-traversal/README.md) | -| 2715 | [Execute Cancellable Function with Delay](https://leetcode.com/problems/execute-cancellable-function-with-delay/) | [JavaScript](./2715-execute-cancellable-function-with-delay/2715-execute-cancellable-function-with-delay.js) | [Easy](./2715-execute-cancellable-function-with-delay/README.md) | -| 2721 | [Execute Asynchronous Functions in Parallel](https://leetcode.com/problems/execute-asynchronous-functions-in-parallel/) | [JavaScript](./2721-execute-asynchronous-functions-in-parallel/2721-execute-asynchronous-functions-in-parallel.js) | [Medium](./2721-execute-asynchronous-functions-in-parallel/README.md) | -| 2722 | [Join Two Arrays by ID](https://leetcode.com/problems/join-two-arrays-by-id/) | [JavaScript](./2722-join-two-arrays-by-id/2722-join-two-arrays-by-id.js) | [Medium](./2722-join-two-arrays-by-id/README.md) | -| 2723 | [Add Two Promises](https://leetcode.com/problems/add-two-promises/) | [JavaScript](./2723-add-two-promises/2723-add-two-promises.js) | [Easy](./2723-add-two-promises/README.md) | -| 2724 | [Sort By](https://leetcode.com/problems/sort-by/) | [JavaScript](./2724-sort-by/2724-sort-by.js) | [Easy](./2724-sort-by/README.md) | -| 2725 | [Interval Cancellation](https://leetcode.com/problems/interval-cancellation/) | [JavaScript](./2725-interval-cancellation/2725-interval-cancellation.js) | [Easy](./2725-interval-cancellation/README.md) | -| 2726 | [Calculator with Method Chaining](https://leetcode.com/problems/calculator-with-method-chaining/) | [JavaScript](./2726-calculator-with-method-chaining/2726-calculator-with-method-chaining.js) | [Easy](./2726-calculator-with-method-chaining/README.md) | -| 2727 | [Is Object Empty](https://leetcode.com/problems/is-object-empty/) | [JavaScript](./2727-is-object-empty/2727-is-object-empty.js) | [Easy](./2727-is-object-empty/README.md) | -| 2742 | [Painting the Walls](https://leetcode.com/problems/painting-the-walls/) | [Python](./2742-painting-the-walls/2742-painting-the-walls.py) | [Hard](./2742-painting-the-walls/README.md) | -| 2743 | [Count Substrings Without Repeating Character](https://leetcode.com/problems/count-substrings-without-repeating-character/) | [Python](./2743-count-substrings-without-repeating-character/2743-count-substrings-without-repeating-character.py) | [Medium](./2743-count-substrings-without-repeating-character/README.md) | -| 2751 | [Robot Collisions](https://leetcode.com/problems/robot-collisions/) | [Python](./2751-robot-collisions/2751-robot-collisions.py) | [Hard](./2751-robot-collisions/README.md) | -| 2762 | [Continuous Subarrays](https://leetcode.com/problems/continuous-subarrays/) | [Python](./2762-continuous-subarrays/2762-continuous-subarrays.py) | [Medium](./2762-continuous-subarrays/README.md) | -| 2778 | [Sum of Squares of Special Elements](https://leetcode.com/problems/sum-of-squares-of-special-elements/) | [Python](./2778-sum-of-squares-of-special-elements/2778-sum-of-squares-of-special-elements.py) | [Easy](./2778-sum-of-squares-of-special-elements/README.md) | -| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good/) | [Python](./2784-check-if-array-is-good/2784-check-if-array-is-good.py) | [Easy](./2784-check-if-array-is-good/README.md) | -| 2785 | [Sort Vowels in a String](https://leetcode.com/problems/sort-vowels-in-a-string/) | [Python](./2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py) | [Medium](./2785-sort-vowels-in-a-string/README.md) | -| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator/) | [Python](./2788-split-strings-by-separator/2788-split-strings-by-separator.py) | [Easy](./2788-split-strings-by-separator/README.md) | -| 2789 | [Largest Element in an Array after Merge Operations](https://leetcode.com/problems/largest-element-in-an-array-after-merge-operations/) | [Python](./2789-largest-element-in-an-array-after-merge-operations/2789-largest-element-in-an-array-after-merge-operations.py) | [Medium](./2789-largest-element-in-an-array-after-merge-operations/README.md) | -| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target/) | [Python](./2798-number-of-employees-who-met-the-target/2798-number-of-employees-who-met-the-target.py) | [Easy](./2798-number-of-employees-who-met-the-target/README.md) | -| 2802 | [Find the K-th Lucky Number](https://leetcode.com/problems/find-the-k-th-lucky-number/) | [Python](./2802-find-the-k-th-lucky-number/2802-find-the-k-th-lucky-number.py) | [Medium](./2802-find-the-k-th-lucky-number/README.md) | -| 2806 | [Account Balance after Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase/) | [Python](./2806-account-balance-after-rounded-purchase/2806-account-balance-after-rounded-purchase.py) | [Easy](./2806-account-balance-after-rounded-purchase/README.md) | -| 2807 | [Insert Greatest Common Divisors in Linked List](https://leetcode.com/problems/insert-greatest-common-divisors-in-linked-list/) | [Python](./2807-insert-greatest-common-divisors-in-linked-list/2807-insert-greatest-common-divisors-in-linked-list.py) | [Medium](./2807-insert-greatest-common-divisors-in-linked-list/README.md) | -| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard/) | [Python](./2810-faulty-keyboard/2810-faulty-keyboard.py) | [Easy](./2810-faulty-keyboard/README.md) | -| 2811 | [Check If It Is Possible to Split Array](https://leetcode.com/problems/check-if-it-is-possible-to-split-array/) | [Python](./2811-check-if-it-is-possible-to-split-array/2811-check-if-it-is-possible-to-split-array.py) | [Medium](./2811-check-if-it-is-possible-to-split-array/README.md) | -| 2812 | [Find the Safest Path in a Grid](https://leetcode.com/problems/find-the-safest-path-in-a-grid/) | [Python](./2812-find-the-safest-path-in-a-grid/2812-find-the-safest-path-in-a-grid.py) | [Medium](./2812-find-the-safest-path-in-a-grid/README.md) | -| 2816 | [Double a Number Represented as a Linked List](https://leetcode.com/problems/double-a-number-represented-as-a-linked-list/) | [Python](./2816-double-a-number-represented-as-a-linked-list/2816-double-a-number-represented-as-a-linked-list.py) | [Medium](./2816-double-a-number-represented-as-a-linked-list/README.md) | -| 2824 | [Count Pairs Whose Sum Is Less Than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target/) | [Python](./2824-count-pairs-whose-sum-is-less-than-target/2824-count-pairs-whose-sum-is-less-than-target.py) | [Easy](./2824-count-pairs-whose-sum-is-less-than-target/README.md) | -| 2825 | [Make String A Subsequence Using Cyclic Increments](https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/) | [Python](./2825-make-string-a-subsequence-using-cyclic-increments/2825-make-string-a-subsequence-using-cyclic-increments.py) | [Medium](./2825-make-string-a-subsequence-using-cyclic-increments/README.md) | -| 2833 | [Furthest Point from Origin](https://leetcode.com/problems/furthest-point-from-origin/) | [Python](./2833-furthest-point-from-origin/2833-furthest-point-from-origin.py) | [Easy](./2833-furthest-point-from-origin/README.md) | -| 2834 | [Find the Minimum Possible Sum of a Beautiful Array](https://leetcode.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array/) | [Python](./2834-find-the-minimum-possible-sum-of-a-beautiful-array/2834-find-the-minimum-possible-sum-of-a-beautiful-array.py) | [Medium](./2834-find-the-minimum-possible-sum-of-a-beautiful-array/README.md) | -| 2849 | [Determine if a Cell is Reachable at a Given Time](https://leetcode.com/problems/determine-if-a-cell-is-reachable-at-a-given-time/) | [Python](./2849-determine-if-a-cell-is-reachable-at-a-given-time/2849-determine-if-a-cell-is-reachable-at-a-given-time.py) | [Medium](./2849-determine-if-a-cell-is-reachable-at-a-given-time/README.md) | -| 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/) | [Python](./2864-maximum-odd-binary-number/2864-maximum-odd-binary-number.py) | [Easy](./2864-maximum-odd-binary-number/README.md) | -| 2870 | [Minimum Number of Operations to Make Array Empty](https://leetcode.com/problems/minimum-number-of-operations-to-make-array-empty/) | [Python](./2870-minimum-number-of-operations-to-make-array-empty/2870-minimum-number-of-operations-to-make-array-empty.py) | [Medium](./2870-minimum-number-of-operations-to-make-array-empty/README.md) | -| 2958 | [Length of Longest Subarray with at Most K Frequency](https://leetcode.com/problems/length-of-longest-subarray-with-at-most-k-frequencies/) | [Python](./2958-length-of-longest-subarray-with-at-most-k-frequency/2958-length-of-longest-subarray-with-at-most-k-frequency.py) | [Medium](./2958-length-of-longest-subarray-with-at-most-k-frequency/README.md) | -| 2962 | [Count Subarrays Where Max Element Appears at Least K Times](https://leetcode.com/problems/count-subarrays-where-maximum-element-appears-at-least-k-times/) | [Python](./2962-count-subarrays-where-max-element-appears-at-least-k-times/2962-count-subarrays-where-max-element-appears-at-least-k-times.py) | [Medium](./2962-count-subarrays-where-max-element-appears-at-least-k-times/README.md) | -| 2966 | [Divide Array into Arrays with Max Difference](https://leetcode.com/problems/divide-array-into-arrays-with-max-difference/) | [Python](./2966-divide-array-into-arrays-with-max-difference/2966-divide-array-into-arrays-with-max-difference.py) | [Medium](./2966-divide-array-into-arrays-with-max-difference/README.md) | -| 2971 | [Find Polygon with the Largest Perimeter](https://leetcode.com/problems/find-polygon-with-the-largest-perimeter/) | [Python](./2971-find-polygon-with-the-largest-perimeter/2971-find-polygon-with-the-largest-perimeter.py) | [Medium](./2971-find-polygon-with-the-largest-perimeter/README.md) | -| 2976 | [Minimum Cost to Convert String I](https://leetcode.com/problems/minimum-cost-to-convert-string-i/) | [Python](./2976-minimum-cost-to-convert-string-i/2976-minimum-cost-to-convert-string-i.py) | [Medium](./2976-minimum-cost-to-convert-string-i/README.md) | -| 2997 | [Minimum Number of Operations to Make Array XOR Equal to Zero](https://leetcode.com/problems/minimum-number-of-operations-to-make-array-xor-equal-to-k/) | [Python](./2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.py) | [Medium](./2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/README.md) | -| 3005 | [Count Elements with Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency/) | [Python](./3005-count-elements-with-maximum-frequency/3005-count-elements-with-maximum-frequency.py) | [Easy](./3005-count-elements-with-maximum-frequency/README.md) | -| 3016 | [Minimum Number of Pushes to Type Word II](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii/) | [Python](./3016-minimum-number-of-pushes-to-type-word-ii/3016-minimum-number-of-pushes-to-type-word-ii.py) | [Medium](./3016-minimum-number-of-pushes-to-type-word-ii/README.md) | -| 3062 | [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game/) | [Python](./3062-winner-of-the-linked-list-game/3062-winner-of-the-linked-list-game.py) | [Easy](./3062-winner-of-the-linked-list-game/README.md) | -| 3063 | [Linked List Frequency](https://leetcode.com/problems/linked-list-frequency/) | [Python](./3063-linked-list-frequency/3063-linked-list-frequency.py) | [Medium](./3063-linked-list-frequency/README.md) | -| 3068 | [Find the Maximum Sum of Node Values](https://leetcode.com/problems/find-the-maximum-sum-of-node-values/) | [Python](./3068-find-the-maximum-sum-of-node-values/3068-find-the-maximum-sum-of-node-values.py) | [Hard](./3068-find-the-maximum-sum-of-node-values/README.md) | -| 3075 | [Maximize Happiness of Selected Children](https://leetcode.com/problems/maximize-happiness-of-selected-children/) | [Python](./3075-maximize-happiness-of-selected-children/3075-maximize-happiness-of-selected-children.py) | [Medium](./3075-maximize-happiness-of-selected-children/README.md) | -| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string/) | [Python](./3110-score-of-a-string/3110-score-of-a-string.py) | [Easy](./3110-score-of-a-string/README.md) | -| 3189 | [Minimum Moves to Get a Peaceful Board](https://leetcode.com/problems/minimum-moves-to-get-a-peaceful-board/) | [Python](./3189-minimum-moves-to-get-a-peaceful-board/3189-minimum-moves-to-get-a-peaceful-board.py) | [Medium](./3189-minimum-moves-to-get-a-peaceful-board/README.md) | - -## How to Use - -1. Clone the repository: - -```bash -git clone https://github.com/hogan.tech/leetcode-solutions.git -``` - -2. Choose a Problem: - -Browse the folders to find the LeetCode problem you want to solve. - -3. Select a Language: - -Inside each problem folder, you'll find solutions in various programming languages. Choose the language you prefer. - -4. Read the ReadMe: - -Each problem folder contains a README file with a problem description, approach, and code explanation. Read this to understand the solution. - -5. Explore the Code: - -Open the code file to view the implementation. Study the code and adapt it as needed for your use case. - -6. Run the Code: - -You can run the code on your local machine to test and modify it as needed. - -7. Contribute: - -If you have a better solution or want to contribute in any way, feel free to submit a pull request. - -8. Share Your Feedback: - -Welcome feedback and suggestions. If you have any ideas to improve the solutions or find any errors, please let me know. - -Happy coding! 🚀 - -By following these steps, users can easily navigate and utilize your LeetCode solutions repository for their coding needs. diff --git a/__pycache__/copy.cpython-312.pyc b/__pycache__/copy.cpython-312.pyc new file mode 100644 index 000000000..2ccd7a97f Binary files /dev/null and b/__pycache__/copy.cpython-312.pyc differ diff --git a/amazon_6months.txt b/amazon_6months.txt new file mode 100644 index 000000000..96294b7fa --- /dev/null +++ b/amazon_6months.txt @@ -0,0 +1,1486 @@ +3. Longest Substring Without Repeating Characters +Med. + +146. LRU Cache +Med. + +200. Number of Islands +Med. + +2340. Minimum Adjacent Swaps to Make a Valid Array +Med. + +875. Koko Eating Bananas +Med. + +49. Group Anagrams +Med. + +56. Merge Intervals +Med. + +15. 3Sum +Med. + +2. Add Two Numbers +Med. + +5. Longest Palindromic Substring +Med. + +1152. Analyze User Website Visit Pattern +Med. + +11. Container With Most Water +Med. + +210. Course Schedule II +Med. + +236. Lowest Common Ancestor of a Binary Tree +Med. + +767. Reorganize String +Med. + +55. Jump Game +Med. + +53. Maximum Subarray +Med. + +238. Product of Array Except Self +Med. + +347. Top K Frequent Elements +Med. + +994. Rotting Oranges +Med. + +17. Letter Combinations of a Phone Number +Med. + +138. Copy List with Random Pointer +Med. + +215. Kth Largest Element in an Array +Med. + +560. Subarray Sum Equals K +Med. + +128. Longest Consecutive Sequence +Med. + +2055. Plates Between Candles +Med. + +22. Generate Parentheses +Med. + +48. Rotate Image +Med. + +54. Spiral Matrix +Med. + +134. Gas Station +Med. + +7. Reverse Integer +Med. + +33. Search in Rotated Sorted Array +Med. + +207. Course Schedule +Med. + +253. Meeting Rooms II +Med. + +36. Valid Sudoku +Med. + +189. Rotate Array +Med. + +322. Coin Change +Med. + +103. Binary Tree Zigzag Level Order Traversal +Med. + +122. Best Time to Buy and Sell Stock II +Med. + +3016. Minimum Number of Pushes to Type Word II +Med. + +31. Next Permutation +Med. + +198. House Robber +Med. + +503. Next Greater Element II +Med. + +380. Insert Delete GetRandom O(1) +Med. + +442. Find All Duplicates in an Array +Med. + +739. Daily Temperatures +Med. + +40. Combination Sum II +Med. + +74. Search a 2D Matrix +Med. + +75. Sort Colors +Med. + +78. Subsets +Med. + +79. Word Search +Med. + +131. Palindrome Partitioning +Med. + +139. Word Break +Med. + +162. Find Peak Element +Med. + +399. Evaluate Division +Med. + +950. Reveal Cards In Increasing Order +Med. + +1004. Max Consecutive Ones III +Med. + +1268. Search Suggestions System +Med. + +19. Remove Nth Node From End of List +Med. + +50. Pow(x, n) +Med. + +62. Unique Paths +Med. + +150. Evaluate Reverse Polish Notation +Med. + +300. Longest Increasing Subsequence +Med. + +2952. Minimum Number of Coins to be Added +Med. + +8. String to Integer (atoi) +Med. + +18. 4Sum +Med. + +90. Subsets II +Med. + +152. Maximum Product Subarray +Med. + +227. Basic Calculator II +Med. + +424. Longest Repeating Character Replacement +Med. + +881. Boats to Save People +Med. + +912. Sort an Array +Med. + +945. Minimum Increment to Make Array Unique +Med. + +2268. Minimum Number of Keypresses +Med. + +2961. Double Modular Exponentiation +Med. + +39. Combination Sum +Med. + +45. Jump Game II +Med. + +71. Simplify Path +Med. + +402. Remove K Digits +Med. + +540. Single Element in a Sorted Array +Med. + +547. Number of Provinces +Med. + +621. Task Scheduler +Med. + +852. Peak Index in a Mountain Array +Med. + +981. Time Based Key-Value Store +Med. + +1492. The kth Factor of n +Med. + +2134. Minimum Swaps to Group All 1's Together II +Med. + +73. Set Matrix Zeroes +Med. + +264. Ugly Number II +Med. + +279. Perfect Squares +Med. + +523. Continuous Subarray Sum +Med. + +545. Boundary of Binary Tree +Med. + +570. Managers with at Least 5 Direct Reports +Med. + +735. Asteroid Collision +Med. + +528. Random Pick with Weight +Med. + +1509. Minimum Difference Between Largest and Smallest Value in Three Moves +Med. + +2149. Rearrange Array Elements by Sign +Med. + +92. Reverse Linked List II +Med. + +105. Construct Binary Tree from Preorder and Inorder Traversal +Med. + +155. Min Stack +Med. + +211. Design Add and Search Words Data Structure +Med. + +395. Longest Substring with At Least K Repeating Characters +Med. + +416. Partition Equal Subset Sum +Med. + +633. Sum of Square Numbers +Med. + +694. Number of Distinct Islands +Med. + +826. Most Profit Assigning Work +Med. + +863. All Nodes Distance K in Binary Tree +Med. + +973. K Closest Points to Origin +Med. + +1248. Count Number of Nice Subarrays +Med. + +1249. Minimum Remove to Make Valid Parentheses +Med. + +12. Integer to Roman +Med. + +64. Minimum Path Sum +Med. + +91. Decode Ways +Med. + +93. Restore IP Addresses +Med. + +98. Validate Binary Search Tree +Med. + +120. Triangle +Med. + +153. Find Minimum in Rotated Sorted Array +Med. + +167. Two Sum II - Input Array Is Sorted +Med. + +199. Binary Tree Right Side View +Med. + +204. Count Primes +Med. + +532. K-diff Pairs in an Array +Med. + +542. 01 Matrix +Med. + +662. Maximum Width of Binary Tree +Med. + +692. Top K Frequent Words +Med. + +901. Online Stock Span +Med. + +907. Sum of Subarray Minimums +Med. + +930. Binary Subarrays With Sum +Med. + +1011. Capacity To Ship Packages Within D Days +Med. + +1143. Longest Common Subsequence +Med. + +1382. Balance a Binary Search Tree +Med. + +1429. First Unique Number +Med. + +1482. Minimum Number of Days to Make m Bouquets +Med. + +29. Divide Two Integers +Med. + +34. Find First and Last Position of Element in Sorted Array +Med. + +46. Permutations +Med. + +57. Insert Interval +Med. + +61. Rotate List +Med. + +86. Partition List +Med. + +102. Binary Tree Level Order Traversal +Med. + +151. Reverse Words in a String +Med. + +165. Compare Version Numbers +Med. + +235. Lowest Common Ancestor of a Binary Search Tree +Med. + +237. Delete Node in a Linked List +Med. + +260. Single Number III +Med. + +348. Design Tic-Tac-Toe +Med. + +394. Decode String +Med. + +443. String Compression +Med. + +525. Contiguous Array +Med. + +1721. Swapping Nodes in a Linked List +Med. + +678. Valid Parenthesis String +Med. + +695. Max Area of Island +Med. + +791. Custom Sort String +Med. + +1105. Filling Bookcase Shelves +Med. + +1140. Stone Game II +Med. + +1193. Monthly Transactions I +Med. + +2191. Sort the Jumbled Numbers +Med. + +1395. Count Number of Teams +Med. + +1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit +Med. + +1485. Clone Binary Tree With Random Pointer +Med. + +1650. Lowest Common Ancestor of a Binary Tree III +Med. + +2256. Minimum Average Difference +Med. + +2288. Apply Discount to Prices +Med. + +2486. Append Characters to String to Make Subsequence +Med. + +2487. Remove Nodes From Linked List +Med. + +3075. Maximize Happiness of Selected Children +Med. + +16. 3Sum Closest +Med. + +24. Swap Nodes in Pairs +Med. + +43. Multiply Strings +Med. + +77. Combinations +Med. + +137. Single Number II +Med. + +143. Reorder List +Med. + +148. Sort List +Med. + +179. Largest Number +Med. + +186. Reverse Words in a String II +Med. + +208. Implement Trie (Prefix Tree) +Med. + +286. Walls and Gates +Med. + +287. Find the Duplicate Number +Med. + +328. Odd Even Linked List +Med. + +438. Find All Anagrams in a String +Med. + +450. Delete Node in a BST +Med. + +538. Convert BST to Greater Tree +Med. + +658. Find K Closest Elements +Med. + +721. Accounts Merge +Med. + +752. Open the Lock +Med. + +909. Snakes and Ladders +Med. + +937. Reorder Data in Log Files +Med. + +959. Regions Cut By Slashes +Med. + +979. Distribute Coins in Binary Tree +Med. + +1135. Connecting Cities With Minimum Cost +Med. + +1038. Binary Search Tree to Greater Sum Tree +Med. + +1052. Grumpy Bookstore Owner +Med. + +1070. Product Sales Analysis III +Med. + +1209. Remove All Adjacent Duplicates in String II +Med. + +2305. Fair Distribution of Cookies +Med. + +1457. Pseudo-Palindromic Paths in a Binary Tree +Med. + +2125. Number of Laser Beams in a Bank +Med. + +2250. Count Number of Rectangles Containing Each Point +Med. + +2390. Removing Stars From a String +Med. + +3211. Generate Binary Strings Without Adjacent Zeros +Med. + +6. Zigzag Conversion +Med. + +80. Remove Duplicates from Sorted Array II +Med. + +129. Sum Root to Leaf Numbers +Med. + +133. Clone Graph +Med. + +142. Linked List Cycle II +Med. + +177. Nth Highest Salary +Med. + +180. Consecutive Numbers +Med. + +184. Department Highest Salary +Med. + +230. Kth Smallest Element in a BST +Med. + +274. H-Index +Med. + +299. Bulls and Cows +Med. + +304. Range Sum Query 2D - Immutable +Med. + +310. Minimum Height Trees +Med. + +316. Remove Duplicate Letters +Med. + +368. Largest Divisible Subset +Med. + +437. Path Sum III +Med. + +449. Serialize and Deserialize BST +Med. + +451. Sort Characters By Frequency +Med. + +475. Heaters +Med. + +494. Target Sum +Med. + +508. Most Frequent Subtree Sum +Med. + +516. Longest Palindromic Subsequence +Med. + +536. Construct Binary Tree from String +Med. + +556. Next Greater Element III +Med. + +581. Shortest Unsorted Continuous Subarray +Med. + +582. Kill Process +Med. + +650. 2 Keys Keyboard +Med. + +670. Maximum Swap +Med. + +725. Split Linked List in Parts +Med. + +742. Closest Leaf in a Binary Tree +Med. + +701. Insert into a Binary Search Tree +Med. + +785. Is Graph Bipartite? +Med. + +797. All Paths From Source to Target +Med. + +802. Find Eventual Safe States +Med. + +708. Insert into a Sorted Circular Linked List +Med. + +921. Minimum Add to Make Parentheses Valid +Med. + +974. Subarray Sums Divisible by K +Med. + +1060. Missing Element in Sorted Array +Med. + +1029. Two City Scheduling +Med. + +1045. Customers Who Bought All Products +Med. + +550. Game Play Analysis IV +Med. + +1129. Shortest Path with Alternating Colors +Med. + +1146. Snapshot Array +Med. + +1155. Number of Dice Rolls With Target Sum +Med. + +1204. Last Person to Fit in the Bus +Med. + +1219. Path with Maximum Gold +Med. + +1283. Find the Smallest Divisor Given a Threshold +Med. + +1305. All Elements in Two Binary Search Trees +Med. + +1325. Delete Leaves With a Given Value +Med. + +1358. Number of Substrings Containing All Three Characters +Med. + +1404. Number of Steps to Reduce a Number in Binary Representation to One +Med. + +1456. Maximum Number of Vowels in a Substring of Given Length +Med. + +1466. Reorder Routes to Make All Paths Lead to the City Zero +Med. + +1493. Longest Subarray of 1's After Deleting One Element +Med. + +1590. Make Sum Divisible by P +Med. + +1613. Find the Missing IDs +Med. + +1669. Merge In Between Linked Lists +Med. + +1701. Average Waiting Time +Med. + +1762. Buildings With an Ocean View +Med. + +1922. Count Good Numbers +Med. + +1958. Check if Move is Legal +Med. + +2104. Sum of Subarray Ranges +Med. + +2221. Find Triangular Sum of an Array +Med. + +2214. Minimum Health to Beat Game +Med. + +2285. Maximum Total Importance of Roads +Med. + +2385. Amount of Time for Binary Tree to Be Infected +Med. + +2405. Optimal Partition of String +Med. + +2461. Maximum Sum of Distinct Subarrays With Length K +Med. + +2502. Design Memory Allocator +Med. + +2575. Find the Divisibility Array of a String +Med. + +2816. Double a Number Represented as a Linked List +Med. + +2802. Find The K-th Lucky Number +Med. + +2870. Minimum Number of Operations to Make Array Empty +Med. + +2947. Count Beautiful Substrings I +Med. + +2962. Count Subarrays Where Max Element Appears at Least K Times +Med. + +2958. Length of Longest Subarray With at Most K Frequency +Med. + +3092. Most Frequent IDs +Med. + +3121. Count the Number of Special Characters II +Med. + +3152. Special Array II +Med. + +38. Count and Say +Med. + +47. Permutations II +Med. + +81. Search in Rotated Sorted Array II +Med. + +89. Gray Code +Med. + +99. Recover Binary Search Tree +Med. + +113. Path Sum II +Med. + +117. Populating Next Right Pointers in Each Node II +Med. + +130. Surrounded Regions +Med. + +176. Second Highest Salary +Med. + +209. Minimum Size Subarray Sum +Med. + +229. Majority Element II +Med. + +240. Search a 2D Matrix II +Med. + +289. Game of Life +Med. + +319. Bulb Switcher +Med. + +323. Number of Connected Components in an Undirected Graph +Med. + +324. Wiggle Sort II +Med. + +334. Increasing Triplet Subsequence +Med. + +340. Longest Substring with At Most K Distinct Characters +Med. + +355. Design Twitter +Med. + +373. Find K Pairs with Smallest Sums +Med. + +378. Kth Smallest Element in a Sorted Matrix +Med. + +390. Elimination Game +Med. + +396. Rotate Function +Med. + +413. Arithmetic Slices +Med. + +419. Battleships in a Board +Med. + +433. Minimum Genetic Mutation +Med. + +435. Non-overlapping Intervals +Med. + +456. 132 Pattern +Med. + +468. Validate IP Address +Med. + +2036. Maximum Alternating Subarray Sum +Med. + +518. Coin Change II +Med. + +529. Minesweeper +Med. + +535. Encode and Decode TinyURL +Med. + +537. Complex Number Multiplication +Med. + +553. Optimal Division +Med. + +567. Permutation in String +Med. + +592. Fraction Addition and Subtraction +Med. + +606. Construct String from Binary Tree +Med. + +624. Maximum Distance in Arrays +Med. + +640. Solve the Equation +Med. + +646. Maximum Length of Pair Chain +Med. + +647. Palindromic Substrings +Med. + +648. Replace Words +Med. + +663. Equal Tree Partition +Med. + +714. Best Time to Buy and Sell Stock with Transaction Fee +Med. + +738. Monotone Increasing Digits +Med. + +743. Network Delay Time +Med. + +430. Flatten a Multilevel Doubly Linked List +Med. + +763. Partition Labels +Med. + +775. Global and Local Inversions +Med. + +776. Split BST +Med. + +779. K-th Symbol in Grammar +Med. + +786. K-th Smallest Prime Fraction +Med. + +787. Cheapest Flights Within K Stops +Med. + +790. Domino and Tromino Tiling +Med. + +707. Design Linked List +Med. + +840. Magic Squares In Grid +Med. + +842. Split Array into Fibonacci Sequence +Med. + +851. Loud and Rich +Med. + +885. Spiral Matrix III +Med. + +890. Find and Replace Pattern +Med. + +894. All Possible Full Binary Trees +Med. + +934. Shortest Bridge +Med. + +948. Bag of Tokens +Med. + +957. Prison Cells After N Days +Med. + +958. Check Completeness of a Binary Tree +Med. + +1062. Longest Repeating Substring +Med. + +1100. Find K-Length Substrings With No Repeated Characters +Med. + +1120. Maximum Average Subtree +Med. + +1026. Maximum Difference Between Node and Ancestor +Med. + +1102. Path With Maximum Minimum Value +Med. + +1035. Uncrossed Lines +Med. + +1054. Distant Barcodes +Med. + +1214. Two Sum BSTs +Med. + +1080. Insufficient Nodes in Root to Leaf Paths +Med. + +1081. Smallest Subsequence of Distinct Characters +Med. + +1079. Letter Tile Possibilities +Med. + +1229. Meeting Scheduler +Med. + +1091. Shortest Path in Binary Matrix +Med. + +1244. Design A Leaderboard +Med. + +1117. Building H2O +Med. + +1288. Remove Covered Intervals +Med. + +1315. Sum of Nodes with Even-Valued Grandparent +Med. + +1171. Remove Zero Sum Consecutive Nodes from Linked List +Med. + +1362. Closest Divisors +Med. + +1164. Product Price at a Given Date +Med. + +1954. Minimum Garden Perimeter to Collect Enough Apples +Med. + +1282. Group the People Given the Group Size They Belong To +Med. + +1311. Get Watched Videos by Your Friends +Med. + +1319. Number of Operations to Make Network Connected +Med. + +1344. Angle Between Hands of a Clock +Med. + +1321. Restaurant Growth +Med. + +1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance +Med. + +1372. Longest ZigZag Path in a Binary Tree +Med. + +1353. Maximum Number of Events That Can Be Attended +Med. + +1409. Queries on a Permutation With Key +Med. + +1423. Maximum Points You Can Obtain from Cards +Med. + +1454. Active Users +Med. + +1472. Design Browser History +Med. + +1508. Range Sum of Sorted Subarray Sums +Med. + +1498. Number of Subsequences That Satisfy the Given Sum Condition +Med. + +1490. Clone N-ary Tree +Med. + +1558. Minimum Numbers of Function Calls to Make Target Array +Med. + +1533. Find the Index of the Large Integer +Med. + +1574. Shortest Subarray to be Removed to Make Array Sorted +Med. + +1570. Dot Product of Two Sparse Vectors +Med. + +1621. Number of Sets of K Non-Overlapping Line Segments +Med. + +1653. Minimum Deletions to Make String Balanced +Med. + +1654. Minimum Jumps to Reach Home +Med. + +1670. Design Front Middle Back Queue +Med. + +1628. Design an Expression Tree With Evaluate Function +Med. + +1634. Add Two Polynomials Represented as Linked Lists +Med. + +1680. Concatenation of Consecutive Binary Numbers +Med. + +1689. Partitioning Into Minimum Number Of Deci-Binary Numbers +Med. + +1676. Lowest Common Ancestor of a Binary Tree IV +Med. + +1734. Decode XORed Permutation +Med. + +1699. Number of Calls Between Two Persons +Med. + +1750. Minimum Length of String After Deleting Similar Ends +Med. + +1764. Form Array by Concatenating Subarrays of Another Array +Med. + +1740. Find Distance in a Binary Tree +Med. + +1781. Sum of Beauty of All Substrings +Med. + +1792. Maximum Average Pass Ratio +Med. + +1772. Sort Features by Popularity +Med. + +1783. Grand Slam Titles +Med. + +1846. Maximum Element After Decreasing and Rearranging +Med. + +1811. Find Interview Candidates +Med. + +1838. Frequency of the Most Frequent Element +Med. + +1852. Distinct Numbers in Each Subarray +Med. + +1882. Process Tasks Using Servers +Med. + +1926. Nearest Exit from Entrance in Maze +Med. + +1915. Number of Wonderful Substrings +Med. + +1942. The Number of the Smallest Unoccupied Chair +Med. + +2297. Jump Game VIII +Med. + +1937. Maximum Number of Points with Cost +Med. + +1950. Maximum of Minimum Values in All Subarrays +Med. + +1981. Minimize the Difference Between Target and Chosen Elements +Med. + +2012. Sum of Beauty in the Array +Med. + +2028. Find Missing Observations +Med. + +2058. Find the Minimum and Maximum Number of Nodes Between Critical Points +Med. + +2075. Decode the Slanted Ciphertext +Med. + +2100. Find Good Days to Rob the Bank +Med. + +2095. Delete the Middle Node of a Linked List +Med. + +2096. Step-By-Step Directions From a Binary Tree Node to Another +Med. + +2116. Check if a Parentheses String Can Be Valid +Med. + +2109. Adding Spaces to a String +Med. + +2110. Number of Smooth Descent Periods of a Stock +Med. + +2145. Count the Hidden Sequences +Med. + +2161. Partition Array According to Given Pivot +Med. + +2195. Append K Integers With Minimal Sum +Med. + +2196. Create Binary Tree From Descriptions +Med. + +2207. Maximize Number of Subsequences in a String +Med. + +2222. Number of Ways to Select Buildings +Med. + +2261. K Divisible Elements Subarrays +Med. + +2266. Count Number of Texts +Med. + +2274. Maximum Consecutive Floors Without Special Floors +Med. + +2270. Number of Ways to Split Array +Med. + +2244. Minimum Rounds to Complete All Tasks +Med. + +2279. Maximum Bags With Full Capacity of Rocks +Med. + +2219. Maximum Sum Score of Array +Med. + +2228. Users With Two Purchases Within Seven Days +Med. + +2238. Number of Times a Driver Was a Passenger +Med. + +2294. Partition Array Such That Maximum Difference Is K +Med. + +2295. Replace Elements in an Array +Med. + +2316. Count Unreachable Pairs of Nodes in an Undirected Graph +Med. + +2336. Smallest Number in Infinite Set +Med. + +2337. Move Pieces to Obtain a String +Med. + +2333. Minimum Sum of Squared Difference +Med. + +2352. Equal Row and Column Pairs +Med. + +2353. Design a Food Rating System +Med. + +2292. Products With Three or More Orders in Two Consecutive Years +Med. + +2370. Longest Ideal Subsequence +Med. + +2324. Product Sales Analysis IV +Med. + +2375. Construct Smallest Number From DI String +Med. + +2323. Find Minimum Time to Finish All Jobs II +Med. + +2380. Time Needed to Rearrange a Binary String +Med. + +2330. Valid Palindrome IV +Med. + +2391. Minimum Amount of Time to Collect Garbage +Med. + +2342. Max Sum of a Pair With Equal Sum of Digits +Med. + +2396. Strictly Palindromic Number +Med. + +2410. Maximum Matching of Players With Trainers +Med. + +2411. Smallest Subarrays With Maximum Bitwise OR +Med. + +2433. Find The Original Array of Prefix Xor +Med. + +2434. Using a Robot to Print the Lexicographically Smallest String +Med. + +2394. Employees With Deductions +Med. + +2443. Sum of Number and Its Reverse +Med. + +2408. Design SQL +Med. + +2471. Minimum Number of Operations to Sort a Binary Tree by Level +Med. + +2422. Merge Operations to Turn Array Into a Palindrome +Med. + +2477. Minimum Fuel Cost to Report to the Capital +Med. + +2501. Longest Square Streak in an Array +Med. + +2497. Maximum Star Sum of a Graph +Med. + +2482. Difference Between Ones and Zeros in Row and Column +Med. + +2527. Find Xor-Beauty of Array +Med. + +2583. Kth Largest Sum in a Binary Tree +Med. + +2606. Find the Substring With Maximum Cost +Med. + +2641. Cousins in Binary Tree II +Med. + +2597. The Number of Beautiful Subsets +Med. + +2638. Count the Number of K-Free Subsets +Med. + +2653. Sliding Subarray Beauty +Med. + +2694. Event Emitter +Med. + +2766. Relocate Marbles +Med. + +2841. Maximum Sum of Almost Unique Subarray +Med. + +2830. Maximize the Profit as the Salesman +Med. + +2782. Number of Unique Categories +Med. + +2825. Make String a Subsequence Using Cyclic Increments +Med. + +2832. Maximal Range That Each Element Is Maximum in It +Med. + +2915. Length of the Longest Subsequence That Sums to Target +Med. + +2898. Maximum Linear Stock Score +Med. + +2929. Distribute Candies Among Children II +Med. + +2976. Minimum Cost to Convert String I +Med. + +2997. Minimum Number of Operations to Make Array XOR Equal to K +Med. + +2979. Most Expensive Item That Can Not Be Bought +Med. + +3020. Find the Maximum Number of Elements in Subset +Med. + +3081. Replace Question Marks in String to Minimize Its Value +Med. + +3133. Minimum Array End +Med. + +3144. Minimum Substring Partition of Equal Character Frequency +Med. + +3191. Minimum Operations to Make Binary Array Elements Equal to One I +Med. + +3215. Count Triplets with Even XOR Set Bits II +Med. + +Amazon - LeetCode diff --git a/0002-add-two-numbers/README.md b/amazon_6months/0002-add-two-numbers.html similarity index 100% rename from 0002-add-two-numbers/README.md rename to amazon_6months/0002-add-two-numbers.html diff --git a/0003-longest-substring-without-repeating-characters/README.md b/amazon_6months/0003-longest-substring-without-repeating-characters.html similarity index 100% rename from 0003-longest-substring-without-repeating-characters/README.md rename to amazon_6months/0003-longest-substring-without-repeating-characters.html diff --git a/0005-longest-palindromic-substring/README.md b/amazon_6months/0005-longest-palindromic-substring.html similarity index 100% rename from 0005-longest-palindromic-substring/README.md rename to amazon_6months/0005-longest-palindromic-substring.html diff --git a/0006-zigzag-conversion/README.md b/amazon_6months/0006-zigzag-conversion.html similarity index 100% rename from 0006-zigzag-conversion/README.md rename to amazon_6months/0006-zigzag-conversion.html diff --git a/0007-reverse-integer/README.md b/amazon_6months/0007-reverse-integer.html similarity index 100% rename from 0007-reverse-integer/README.md rename to amazon_6months/0007-reverse-integer.html diff --git a/0008-string-to-integer-atoi/README.md b/amazon_6months/0008-string-to-integer-atoi.html similarity index 100% rename from 0008-string-to-integer-atoi/README.md rename to amazon_6months/0008-string-to-integer-atoi.html diff --git a/0011-container-with-most-water/README.md b/amazon_6months/0011-container-with-most-water.html similarity index 100% rename from 0011-container-with-most-water/README.md rename to amazon_6months/0011-container-with-most-water.html diff --git a/0012-integer-to-roman/README.md b/amazon_6months/0012-integer-to-roman.html similarity index 100% rename from 0012-integer-to-roman/README.md rename to amazon_6months/0012-integer-to-roman.html diff --git a/0015-3sum/README.md b/amazon_6months/0015-3sum.html similarity index 100% rename from 0015-3sum/README.md rename to amazon_6months/0015-3sum.html diff --git a/0016-3sum-closest/README.md b/amazon_6months/0016-3sum-closest.html similarity index 100% rename from 0016-3sum-closest/README.md rename to amazon_6months/0016-3sum-closest.html diff --git a/0017-letter-combinations-of-a-phone-number/README.md b/amazon_6months/0017-letter-combinations-of-a-phone-number.html similarity index 100% rename from 0017-letter-combinations-of-a-phone-number/README.md rename to amazon_6months/0017-letter-combinations-of-a-phone-number.html diff --git a/0018-4sum/README.md b/amazon_6months/0018-4sum.html similarity index 100% rename from 0018-4sum/README.md rename to amazon_6months/0018-4sum.html diff --git a/0019-remove-nth-node-from-end-of-list/README.md b/amazon_6months/0019-remove-nth-node-from-end-of-list.html similarity index 100% rename from 0019-remove-nth-node-from-end-of-list/README.md rename to amazon_6months/0019-remove-nth-node-from-end-of-list.html diff --git a/0022-generate-parentheses/README.md b/amazon_6months/0022-generate-parentheses.html similarity index 100% rename from 0022-generate-parentheses/README.md rename to amazon_6months/0022-generate-parentheses.html diff --git a/0024-swap-nodes-in-pairs/README.md b/amazon_6months/0024-swap-nodes-in-pairs.html similarity index 100% rename from 0024-swap-nodes-in-pairs/README.md rename to amazon_6months/0024-swap-nodes-in-pairs.html diff --git a/0029-divide-two-integers/README.md b/amazon_6months/0029-divide-two-integers.html similarity index 100% rename from 0029-divide-two-integers/README.md rename to amazon_6months/0029-divide-two-integers.html diff --git a/0031-next-permutation/README.md b/amazon_6months/0031-next-permutation.html similarity index 100% rename from 0031-next-permutation/README.md rename to amazon_6months/0031-next-permutation.html diff --git a/0033-search-in-rotated-sorted-array/README.md b/amazon_6months/0033-search-in-rotated-sorted-array.html similarity index 100% rename from 0033-search-in-rotated-sorted-array/README.md rename to amazon_6months/0033-search-in-rotated-sorted-array.html diff --git a/0034-find-first-and-last-position-of-element-in-sorted-array/README.md b/amazon_6months/0034-find-first-and-last-position-of-element-in-sorted-array.html similarity index 100% rename from 0034-find-first-and-last-position-of-element-in-sorted-array/README.md rename to amazon_6months/0034-find-first-and-last-position-of-element-in-sorted-array.html diff --git a/0036-valid-sudoku/README.md b/amazon_6months/0036-valid-sudoku.html similarity index 100% rename from 0036-valid-sudoku/README.md rename to amazon_6months/0036-valid-sudoku.html diff --git a/0039-combination-sum/README.md b/amazon_6months/0039-combination-sum.html similarity index 100% rename from 0039-combination-sum/README.md rename to amazon_6months/0039-combination-sum.html diff --git a/0040-combination-sum-ii/README.md b/amazon_6months/0040-combination-sum-ii.html similarity index 100% rename from 0040-combination-sum-ii/README.md rename to amazon_6months/0040-combination-sum-ii.html diff --git a/0045-jump-game-ii/README.md b/amazon_6months/0045-jump-game-ii.html similarity index 100% rename from 0045-jump-game-ii/README.md rename to amazon_6months/0045-jump-game-ii.html diff --git a/0046-permutations/README.md b/amazon_6months/0046-permutations.html similarity index 100% rename from 0046-permutations/README.md rename to amazon_6months/0046-permutations.html diff --git a/0048-rotate-image/README.md b/amazon_6months/0048-rotate-image.html similarity index 100% rename from 0048-rotate-image/README.md rename to amazon_6months/0048-rotate-image.html diff --git a/0049-group-anagrams/README.md b/amazon_6months/0049-group-anagrams.html similarity index 100% rename from 0049-group-anagrams/README.md rename to amazon_6months/0049-group-anagrams.html diff --git a/0050-powx-n/README.md b/amazon_6months/0050-powx-n.html similarity index 100% rename from 0050-powx-n/README.md rename to amazon_6months/0050-powx-n.html diff --git a/0053-maximum-subarray/README.md b/amazon_6months/0053-maximum-subarray.html similarity index 100% rename from 0053-maximum-subarray/README.md rename to amazon_6months/0053-maximum-subarray.html diff --git a/0054-spiral-matrix/README.md b/amazon_6months/0054-spiral-matrix.html similarity index 100% rename from 0054-spiral-matrix/README.md rename to amazon_6months/0054-spiral-matrix.html diff --git a/amazon_6months/0055-jump-game.html b/amazon_6months/0055-jump-game.html new file mode 100644 index 000000000..e69de29bb diff --git a/0056-merge-intervals/README.md b/amazon_6months/0056-merge-intervals.html similarity index 100% rename from 0056-merge-intervals/README.md rename to amazon_6months/0056-merge-intervals.html diff --git a/0057-insert-interval/README.md b/amazon_6months/0057-insert-interval.html similarity index 100% rename from 0057-insert-interval/README.md rename to amazon_6months/0057-insert-interval.html diff --git a/0061-rotate-list/README.md b/amazon_6months/0061-rotate-list.html similarity index 100% rename from 0061-rotate-list/README.md rename to amazon_6months/0061-rotate-list.html diff --git a/0062-unique-paths/README.md b/amazon_6months/0062-unique-paths.html similarity index 100% rename from 0062-unique-paths/README.md rename to amazon_6months/0062-unique-paths.html diff --git a/0064-minimum-path-sum/README.md b/amazon_6months/0064-minimum-path-sum.html similarity index 100% rename from 0064-minimum-path-sum/README.md rename to amazon_6months/0064-minimum-path-sum.html diff --git a/0073-set-matrix-zeroes/README.md b/amazon_6months/0073-set-matrix-zeroes.html similarity index 100% rename from 0073-set-matrix-zeroes/README.md rename to amazon_6months/0073-set-matrix-zeroes.html diff --git a/0074-search-a-2d-matrix/README.md b/amazon_6months/0074-search-a-2d-matrix.html similarity index 100% rename from 0074-search-a-2d-matrix/README.md rename to amazon_6months/0074-search-a-2d-matrix.html diff --git a/0075-sort-colors/README.md b/amazon_6months/0075-sort-colors.html similarity index 100% rename from 0075-sort-colors/README.md rename to amazon_6months/0075-sort-colors.html diff --git a/0077-combinations/README.md b/amazon_6months/0077-combinations.html similarity index 100% rename from 0077-combinations/README.md rename to amazon_6months/0077-combinations.html diff --git a/0078-subsets/README.md b/amazon_6months/0078-subsets.html similarity index 100% rename from 0078-subsets/README.md rename to amazon_6months/0078-subsets.html diff --git a/0079-word-search/README.md b/amazon_6months/0079-word-search.html similarity index 100% rename from 0079-word-search/README.md rename to amazon_6months/0079-word-search.html diff --git a/0081-search-in-rotated-sorted-array-ii/README.md b/amazon_6months/0081-search-in-rotated-sorted-array-ii.html similarity index 100% rename from 0081-search-in-rotated-sorted-array-ii/README.md rename to amazon_6months/0081-search-in-rotated-sorted-array-ii.html diff --git a/0086-partition-list/README.md b/amazon_6months/0086-partition-list.html similarity index 100% rename from 0086-partition-list/README.md rename to amazon_6months/0086-partition-list.html diff --git a/0090-subsets-ii/README.md b/amazon_6months/0090-subsets-ii.html similarity index 100% rename from 0090-subsets-ii/README.md rename to amazon_6months/0090-subsets-ii.html diff --git a/0091-decode-ways/README.md b/amazon_6months/0091-decode-ways.html similarity index 100% rename from 0091-decode-ways/README.md rename to amazon_6months/0091-decode-ways.html diff --git a/0092-reverse-linked-list-ii/README.md b/amazon_6months/0092-reverse-linked-list-ii.html similarity index 100% rename from 0092-reverse-linked-list-ii/README.md rename to amazon_6months/0092-reverse-linked-list-ii.html diff --git a/0098-validate-binary-search-tree/README.md b/amazon_6months/0098-validate-binary-search-tree.html similarity index 100% rename from 0098-validate-binary-search-tree/README.md rename to amazon_6months/0098-validate-binary-search-tree.html diff --git a/0102-binary-tree-level-order-traversal/README.md b/amazon_6months/0102-binary-tree-level-order-traversal.html similarity index 100% rename from 0102-binary-tree-level-order-traversal/README.md rename to amazon_6months/0102-binary-tree-level-order-traversal.html diff --git a/0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md b/amazon_6months/0105-construct-binary-tree-from-preorder-and-inorder-traversal.html similarity index 100% rename from 0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md rename to amazon_6months/0105-construct-binary-tree-from-preorder-and-inorder-traversal.html diff --git a/0120-triangle/README.md b/amazon_6months/0120-triangle.html similarity index 100% rename from 0120-triangle/README.md rename to amazon_6months/0120-triangle.html diff --git a/0128-longest-consecutive-sequence/README.md b/amazon_6months/0128-longest-consecutive-sequence.html similarity index 100% rename from 0128-longest-consecutive-sequence/README.md rename to amazon_6months/0128-longest-consecutive-sequence.html diff --git a/0129-sum-root-to-leaf-numbers/README.md b/amazon_6months/0129-sum-root-to-leaf-numbers.html similarity index 100% rename from 0129-sum-root-to-leaf-numbers/README.md rename to amazon_6months/0129-sum-root-to-leaf-numbers.html diff --git a/0131-palindrome-partitioning/README.md b/amazon_6months/0131-palindrome-partitioning.html similarity index 100% rename from 0131-palindrome-partitioning/README.md rename to amazon_6months/0131-palindrome-partitioning.html diff --git a/0133-clone-graph/README.md b/amazon_6months/0133-clone-graph.html similarity index 100% rename from 0133-clone-graph/README.md rename to amazon_6months/0133-clone-graph.html diff --git a/0137-single-number-ii/README.md b/amazon_6months/0137-single-number-ii.html similarity index 100% rename from 0137-single-number-ii/README.md rename to amazon_6months/0137-single-number-ii.html diff --git a/0138-copy-list-with-random-pointer/README.md b/amazon_6months/0138-copy-list-with-random-pointer.html similarity index 100% rename from 0138-copy-list-with-random-pointer/README.md rename to amazon_6months/0138-copy-list-with-random-pointer.html diff --git a/0139-word-break/README.md b/amazon_6months/0139-word-break.html similarity index 100% rename from 0139-word-break/README.md rename to amazon_6months/0139-word-break.html diff --git a/0143-reorder-list/README.md b/amazon_6months/0143-reorder-list.html similarity index 100% rename from 0143-reorder-list/README.md rename to amazon_6months/0143-reorder-list.html diff --git a/0146-lru-cache/README.md b/amazon_6months/0146-lru-cache.html similarity index 100% rename from 0146-lru-cache/README.md rename to amazon_6months/0146-lru-cache.html diff --git a/0148-sort-list/README.md b/amazon_6months/0148-sort-list.html similarity index 100% rename from 0148-sort-list/README.md rename to amazon_6months/0148-sort-list.html diff --git a/0150-evaluate-reverse-polish-notation/README.md b/amazon_6months/0150-evaluate-reverse-polish-notation.html similarity index 100% rename from 0150-evaluate-reverse-polish-notation/README.md rename to amazon_6months/0150-evaluate-reverse-polish-notation.html diff --git a/0153-find-minimum-in-rotated-sorted-array/README.md b/amazon_6months/0153-find-minimum-in-rotated-sorted-array.html similarity index 100% rename from 0153-find-minimum-in-rotated-sorted-array/README.md rename to amazon_6months/0153-find-minimum-in-rotated-sorted-array.html diff --git a/0155-min-stack/README.md b/amazon_6months/0155-min-stack.html similarity index 100% rename from 0155-min-stack/README.md rename to amazon_6months/0155-min-stack.html diff --git a/0162-find-peak-element/README.md b/amazon_6months/0162-find-peak-element.html similarity index 100% rename from 0162-find-peak-element/README.md rename to amazon_6months/0162-find-peak-element.html diff --git a/amazon_6months/0165-compare-version-numbers.html b/amazon_6months/0165-compare-version-numbers.html new file mode 100644 index 000000000..e69de29bb diff --git a/0167-two-sum-ii-input-array-is-sorted/README.md b/amazon_6months/0167-two-sum-ii-input-array-is-sorted.html similarity index 100% rename from 0167-two-sum-ii-input-array-is-sorted/README.md rename to amazon_6months/0167-two-sum-ii-input-array-is-sorted.html diff --git a/0189-rotate-array/README.md b/amazon_6months/0189-rotate-array.html similarity index 100% rename from 0189-rotate-array/README.md rename to amazon_6months/0189-rotate-array.html diff --git a/0198-house-robber/README.md b/amazon_6months/0198-house-robber.html similarity index 100% rename from 0198-house-robber/README.md rename to amazon_6months/0198-house-robber.html diff --git a/amazon_6months/0199-binary-tree-right-side-view.html b/amazon_6months/0199-binary-tree-right-side-view.html new file mode 100644 index 000000000..e69de29bb diff --git a/0200-number-of-islands/README.md b/amazon_6months/0200-number-of-islands.html similarity index 100% rename from 0200-number-of-islands/README.md rename to amazon_6months/0200-number-of-islands.html diff --git a/0207-course-schedule/README.md b/amazon_6months/0207-course-schedule.html similarity index 100% rename from 0207-course-schedule/README.md rename to amazon_6months/0207-course-schedule.html diff --git a/0208-implement-trie-prefix-tree/README.md b/amazon_6months/0208-implement-trie-prefix-tree.html similarity index 100% rename from 0208-implement-trie-prefix-tree/README.md rename to amazon_6months/0208-implement-trie-prefix-tree.html diff --git a/0215-kth-largest-element-in-an-array/README.md b/amazon_6months/0215-kth-largest-element-in-an-array.html similarity index 100% rename from 0215-kth-largest-element-in-an-array/README.md rename to amazon_6months/0215-kth-largest-element-in-an-array.html diff --git a/0229-majority-element-ii/README.md b/amazon_6months/0229-majority-element-ii.html similarity index 100% rename from 0229-majority-element-ii/README.md rename to amazon_6months/0229-majority-element-ii.html diff --git a/0230-kth-smallest-element-in-a-bst/README.md b/amazon_6months/0230-kth-smallest-element-in-a-bst.html similarity index 100% rename from 0230-kth-smallest-element-in-a-bst/README.md rename to amazon_6months/0230-kth-smallest-element-in-a-bst.html diff --git a/0235-lowest-common-ancestor-of-a-binary-search-tree/README.md b/amazon_6months/0235-lowest-common-ancestor-of-a-binary-search-tree.html similarity index 100% rename from 0235-lowest-common-ancestor-of-a-binary-search-tree/README.md rename to amazon_6months/0235-lowest-common-ancestor-of-a-binary-search-tree.html diff --git a/0236-lowest-common-ancestor-of-a-binary-tree/README.md b/amazon_6months/0236-lowest-common-ancestor-of-a-binary-tree.html similarity index 100% rename from 0236-lowest-common-ancestor-of-a-binary-tree/README.md rename to amazon_6months/0236-lowest-common-ancestor-of-a-binary-tree.html diff --git a/0237-delete-node-in-a-linked-list/README.md b/amazon_6months/0237-delete-node-in-a-linked-list.html similarity index 100% rename from 0237-delete-node-in-a-linked-list/README.md rename to amazon_6months/0237-delete-node-in-a-linked-list.html diff --git a/0238-product-of-array-except-self/README.md b/amazon_6months/0238-product-of-array-except-self.html similarity index 100% rename from 0238-product-of-array-except-self/README.md rename to amazon_6months/0238-product-of-array-except-self.html diff --git a/0253-meeting-rooms-ii/README.md b/amazon_6months/0253-meeting-rooms-ii.html similarity index 100% rename from 0253-meeting-rooms-ii/README.md rename to amazon_6months/0253-meeting-rooms-ii.html diff --git a/0260-single-number-iii/README.md b/amazon_6months/0260-single-number-iii.html similarity index 100% rename from 0260-single-number-iii/README.md rename to amazon_6months/0260-single-number-iii.html diff --git a/0264-ugly-number-ii/README.md b/amazon_6months/0264-ugly-number-ii.html similarity index 100% rename from 0264-ugly-number-ii/README.md rename to amazon_6months/0264-ugly-number-ii.html diff --git a/0279-perfect-squares/README.md b/amazon_6months/0279-perfect-squares.html similarity index 100% rename from 0279-perfect-squares/README.md rename to amazon_6months/0279-perfect-squares.html diff --git a/0287-find-the-duplicate-number/README.md b/amazon_6months/0287-find-the-duplicate-number.html similarity index 100% rename from 0287-find-the-duplicate-number/README.md rename to amazon_6months/0287-find-the-duplicate-number.html diff --git a/0300-longest-increasing-subsequence/README.md b/amazon_6months/0300-longest-increasing-subsequence.html similarity index 100% rename from 0300-longest-increasing-subsequence/README.md rename to amazon_6months/0300-longest-increasing-subsequence.html diff --git a/0310-minimum-height-trees/README.md b/amazon_6months/0310-minimum-height-trees.html similarity index 100% rename from 0310-minimum-height-trees/README.md rename to amazon_6months/0310-minimum-height-trees.html diff --git a/0316-remove-duplicate-letters/README.md b/amazon_6months/0316-remove-duplicate-letters.html similarity index 100% rename from 0316-remove-duplicate-letters/README.md rename to amazon_6months/0316-remove-duplicate-letters.html diff --git a/0322-coin-change/README.md b/amazon_6months/0322-coin-change.html similarity index 100% rename from 0322-coin-change/README.md rename to amazon_6months/0322-coin-change.html diff --git a/0340-longest-substring-with-at-most-k-distinct-characters/README.md b/amazon_6months/0340-longest-substring-with-at-most-k-distinct-characters.html similarity index 100% rename from 0340-longest-substring-with-at-most-k-distinct-characters/README.md rename to amazon_6months/0340-longest-substring-with-at-most-k-distinct-characters.html diff --git a/0347-top-k-frequent-elements/README.md b/amazon_6months/0347-top-k-frequent-elements.html similarity index 100% rename from 0347-top-k-frequent-elements/README.md rename to amazon_6months/0347-top-k-frequent-elements.html diff --git a/0368-largest-divisible-subset/README.md b/amazon_6months/0368-largest-divisible-subset.html similarity index 100% rename from 0368-largest-divisible-subset/README.md rename to amazon_6months/0368-largest-divisible-subset.html diff --git a/0380-insert-delete-getrandom-o1/README.md b/amazon_6months/0380-insert-delete-getrandom-o1.html similarity index 100% rename from 0380-insert-delete-getrandom-o1/README.md rename to amazon_6months/0380-insert-delete-getrandom-o1.html diff --git a/0402-remove-k-digits/README.md b/amazon_6months/0402-remove-k-digits.html similarity index 100% rename from 0402-remove-k-digits/README.md rename to amazon_6months/0402-remove-k-digits.html diff --git a/0416-partition-equal-subset-sum/README.md b/amazon_6months/0416-partition-equal-subset-sum.html similarity index 100% rename from 0416-partition-equal-subset-sum/README.md rename to amazon_6months/0416-partition-equal-subset-sum.html diff --git a/0438-find-all-anagrams-in-a-string/README.md b/amazon_6months/0438-find-all-anagrams-in-a-string.html similarity index 100% rename from 0438-find-all-anagrams-in-a-string/README.md rename to amazon_6months/0438-find-all-anagrams-in-a-string.html diff --git a/0442-find-all-duplicates-in-an-array/README.md b/amazon_6months/0442-find-all-duplicates-in-an-array.html similarity index 100% rename from 0442-find-all-duplicates-in-an-array/README.md rename to amazon_6months/0442-find-all-duplicates-in-an-array.html diff --git a/0451-sort-characters-by-frequency/README.md b/amazon_6months/0451-sort-characters-by-frequency.html similarity index 100% rename from 0451-sort-characters-by-frequency/README.md rename to amazon_6months/0451-sort-characters-by-frequency.html diff --git a/0456-132-pattern/README.md b/amazon_6months/0456-132-pattern.html similarity index 100% rename from 0456-132-pattern/README.md rename to amazon_6months/0456-132-pattern.html diff --git a/0518-coin-change-ii/README.md b/amazon_6months/0518-coin-change-ii.html similarity index 100% rename from 0518-coin-change-ii/README.md rename to amazon_6months/0518-coin-change-ii.html diff --git a/0523-continuous-subarray-sum/README.md b/amazon_6months/0523-continuous-subarray-sum.html similarity index 100% rename from 0523-continuous-subarray-sum/README.md rename to amazon_6months/0523-continuous-subarray-sum.html diff --git a/0525-contiguous-array/README.md b/amazon_6months/0525-contiguous-array.html similarity index 100% rename from 0525-contiguous-array/README.md rename to amazon_6months/0525-contiguous-array.html diff --git a/0532-k-diff-pairs-in-an-array/README.md b/amazon_6months/0532-k-diff-pairs-in-an-array.html similarity index 100% rename from 0532-k-diff-pairs-in-an-array/README.md rename to amazon_6months/0532-k-diff-pairs-in-an-array.html diff --git a/0540-single-element-in-a-sorted-array/README.md b/amazon_6months/0540-single-element-in-a-sorted-array.html similarity index 100% rename from 0540-single-element-in-a-sorted-array/README.md rename to amazon_6months/0540-single-element-in-a-sorted-array.html diff --git a/0542-01-matrix/README.md b/amazon_6months/0542-01-matrix.html similarity index 100% rename from 0542-01-matrix/README.md rename to amazon_6months/0542-01-matrix.html diff --git a/0567-permutation-in-string/README.md b/amazon_6months/0567-permutation-in-string.html similarity index 100% rename from 0567-permutation-in-string/README.md rename to amazon_6months/0567-permutation-in-string.html diff --git a/0592-fraction-addition-and-subtraction/README.md b/amazon_6months/0592-fraction-addition-and-subtraction.html similarity index 100% rename from 0592-fraction-addition-and-subtraction/README.md rename to amazon_6months/0592-fraction-addition-and-subtraction.html diff --git a/0606-construct-string-from-binary-tree/README.md b/amazon_6months/0606-construct-string-from-binary-tree.html similarity index 100% rename from 0606-construct-string-from-binary-tree/README.md rename to amazon_6months/0606-construct-string-from-binary-tree.html diff --git a/0621-task-scheduler/README.md b/amazon_6months/0621-task-scheduler.html similarity index 100% rename from 0621-task-scheduler/README.md rename to amazon_6months/0621-task-scheduler.html diff --git a/0624-maximum-distance-in-arrays/README.md b/amazon_6months/0624-maximum-distance-in-arrays.html similarity index 100% rename from 0624-maximum-distance-in-arrays/README.md rename to amazon_6months/0624-maximum-distance-in-arrays.html diff --git a/0633-sum-of-square-numbers/README.md b/amazon_6months/0633-sum-of-square-numbers.html similarity index 100% rename from 0633-sum-of-square-numbers/README.md rename to amazon_6months/0633-sum-of-square-numbers.html diff --git a/0646-maximum-length-of-pair-chain/README.md b/amazon_6months/0646-maximum-length-of-pair-chain.html similarity index 100% rename from 0646-maximum-length-of-pair-chain/README.md rename to amazon_6months/0646-maximum-length-of-pair-chain.html diff --git a/0647-palindromic-substrings/README.md b/amazon_6months/0647-palindromic-substrings.html similarity index 100% rename from 0647-palindromic-substrings/README.md rename to amazon_6months/0647-palindromic-substrings.html diff --git a/0648-replace-words/README.md b/amazon_6months/0648-replace-words.html similarity index 100% rename from 0648-replace-words/README.md rename to amazon_6months/0648-replace-words.html diff --git a/0650-2-keys-keyboard/README.md b/amazon_6months/0650-2-keys-keyboard.html similarity index 100% rename from 0650-2-keys-keyboard/README.md rename to amazon_6months/0650-2-keys-keyboard.html diff --git a/amazon_6months/0658-find-k-closest-elements.html b/amazon_6months/0658-find-k-closest-elements.html new file mode 100644 index 000000000..e69de29bb diff --git a/0678-valid-parenthesis-string/README.md b/amazon_6months/0678-valid-parenthesis-string.html similarity index 100% rename from 0678-valid-parenthesis-string/README.md rename to amazon_6months/0678-valid-parenthesis-string.html diff --git a/0695-max-area-of-island/README.md b/amazon_6months/0695-max-area-of-island.html similarity index 100% rename from 0695-max-area-of-island/README.md rename to amazon_6months/0695-max-area-of-island.html diff --git a/0701-insert-into-a-binary-search-tree/README.md b/amazon_6months/0701-insert-into-a-binary-search-tree.html similarity index 100% rename from 0701-insert-into-a-binary-search-tree/README.md rename to amazon_6months/0701-insert-into-a-binary-search-tree.html diff --git a/0721-accounts-merge/README.md b/amazon_6months/0721-accounts-merge.html similarity index 100% rename from 0721-accounts-merge/README.md rename to amazon_6months/0721-accounts-merge.html diff --git a/0725-split-linked-list-in-parts/README.md b/amazon_6months/0725-split-linked-list-in-parts.html similarity index 100% rename from 0725-split-linked-list-in-parts/README.md rename to amazon_6months/0725-split-linked-list-in-parts.html diff --git a/0739-daily-temperatures/README.md b/amazon_6months/0739-daily-temperatures.html similarity index 100% rename from 0739-daily-temperatures/README.md rename to amazon_6months/0739-daily-temperatures.html diff --git a/0752-open-the-lock/README.md b/amazon_6months/0752-open-the-lock.html similarity index 100% rename from 0752-open-the-lock/README.md rename to amazon_6months/0752-open-the-lock.html diff --git a/0767-reorganize-string/README.md b/amazon_6months/0767-reorganize-string.html similarity index 100% rename from 0767-reorganize-string/README.md rename to amazon_6months/0767-reorganize-string.html diff --git a/0776-split-bst/README.md b/amazon_6months/0776-split-bst.html similarity index 100% rename from 0776-split-bst/README.md rename to amazon_6months/0776-split-bst.html diff --git a/0779-k-th-symbol-in-grammar/README.md b/amazon_6months/0779-k-th-symbol-in-grammar.html similarity index 100% rename from 0779-k-th-symbol-in-grammar/README.md rename to amazon_6months/0779-k-th-symbol-in-grammar.html diff --git a/0786-k-th-smallest-prime-fraction/README.md b/amazon_6months/0786-k-th-smallest-prime-fraction.html similarity index 100% rename from 0786-k-th-smallest-prime-fraction/README.md rename to amazon_6months/0786-k-th-smallest-prime-fraction.html diff --git a/0787-cheapest-flights-within-k-stops/README.md b/amazon_6months/0787-cheapest-flights-within-k-stops.html similarity index 100% rename from 0787-cheapest-flights-within-k-stops/README.md rename to amazon_6months/0787-cheapest-flights-within-k-stops.html diff --git a/0791-custom-sort-string/README.md b/amazon_6months/0791-custom-sort-string.html similarity index 100% rename from 0791-custom-sort-string/README.md rename to amazon_6months/0791-custom-sort-string.html diff --git a/0826-most-profit-assigning-work/README.md b/amazon_6months/0826-most-profit-assigning-work.html similarity index 100% rename from 0826-most-profit-assigning-work/README.md rename to amazon_6months/0826-most-profit-assigning-work.html diff --git a/0840-magic-squares-in-grid/README.md b/amazon_6months/0840-magic-squares-in-grid.html similarity index 100% rename from 0840-magic-squares-in-grid/README.md rename to amazon_6months/0840-magic-squares-in-grid.html diff --git a/0852-peak-index-in-a-mountain-array/README.md b/amazon_6months/0852-peak-index-in-a-mountain-array.html similarity index 100% rename from 0852-peak-index-in-a-mountain-array/README.md rename to amazon_6months/0852-peak-index-in-a-mountain-array.html diff --git a/0875-koko-eating-bananas/README.md b/amazon_6months/0875-koko-eating-bananas.html similarity index 100% rename from 0875-koko-eating-bananas/README.md rename to amazon_6months/0875-koko-eating-bananas.html diff --git a/0881-boats-to-save-people/README.md b/amazon_6months/0881-boats-to-save-people.html similarity index 100% rename from 0881-boats-to-save-people/README.md rename to amazon_6months/0881-boats-to-save-people.html diff --git a/0885-spiral-matrix-iii/README.md b/amazon_6months/0885-spiral-matrix-iii.html similarity index 100% rename from 0885-spiral-matrix-iii/README.md rename to amazon_6months/0885-spiral-matrix-iii.html diff --git a/0894-all-possible-full-binary-trees/README.md b/amazon_6months/0894-all-possible-full-binary-trees.html similarity index 100% rename from 0894-all-possible-full-binary-trees/README.md rename to amazon_6months/0894-all-possible-full-binary-trees.html diff --git a/0907-sum-of-subarray-minimums/README.md b/amazon_6months/0907-sum-of-subarray-minimums.html similarity index 100% rename from 0907-sum-of-subarray-minimums/README.md rename to amazon_6months/0907-sum-of-subarray-minimums.html diff --git a/0912-sort-an-array/README.md b/amazon_6months/0912-sort-an-array.html similarity index 100% rename from 0912-sort-an-array/README.md rename to amazon_6months/0912-sort-an-array.html diff --git a/0930-binary-subarrays-with-sum/README.md b/amazon_6months/0930-binary-subarrays-with-sum.html similarity index 100% rename from 0930-binary-subarrays-with-sum/README.md rename to amazon_6months/0930-binary-subarrays-with-sum.html diff --git a/0945-minimum-increment-to-make-array-unique/README.md b/amazon_6months/0945-minimum-increment-to-make-array-unique.html similarity index 100% rename from 0945-minimum-increment-to-make-array-unique/README.md rename to amazon_6months/0945-minimum-increment-to-make-array-unique.html diff --git a/0948-bag-of-tokens/README.md b/amazon_6months/0948-bag-of-tokens.html similarity index 100% rename from 0948-bag-of-tokens/README.md rename to amazon_6months/0948-bag-of-tokens.html diff --git a/0950-reveal-cards-in-increasing-order/README.md b/amazon_6months/0950-reveal-cards-in-increasing-order.html similarity index 100% rename from 0950-reveal-cards-in-increasing-order/README.md rename to amazon_6months/0950-reveal-cards-in-increasing-order.html diff --git a/0959-regions-cut-by-slashes/README.md b/amazon_6months/0959-regions-cut-by-slashes.html similarity index 100% rename from 0959-regions-cut-by-slashes/README.md rename to amazon_6months/0959-regions-cut-by-slashes.html diff --git a/0973-k-closest-points-to-origin/README.md b/amazon_6months/0973-k-closest-points-to-origin.html similarity index 100% rename from 0973-k-closest-points-to-origin/README.md rename to amazon_6months/0973-k-closest-points-to-origin.html diff --git a/0974-subarray-sums-divisible-by-k/README.md b/amazon_6months/0974-subarray-sums-divisible-by-k.html similarity index 100% rename from 0974-subarray-sums-divisible-by-k/README.md rename to amazon_6months/0974-subarray-sums-divisible-by-k.html diff --git a/0979-distribute-coins-in-binary-tree/README.md b/amazon_6months/0979-distribute-coins-in-binary-tree.html similarity index 100% rename from 0979-distribute-coins-in-binary-tree/README.md rename to amazon_6months/0979-distribute-coins-in-binary-tree.html diff --git a/0981-time-based-key-value-store/README.md b/amazon_6months/0981-time-based-key-value-store.html similarity index 100% rename from 0981-time-based-key-value-store/README.md rename to amazon_6months/0981-time-based-key-value-store.html diff --git a/0994-rotting-oranges/README.md b/amazon_6months/0994-rotting-oranges.html similarity index 100% rename from 0994-rotting-oranges/README.md rename to amazon_6months/0994-rotting-oranges.html diff --git a/1026-maximum-difference-between-node-and-ancestor/README.md b/amazon_6months/1026-maximum-difference-between-node-and-ancestor.html similarity index 100% rename from 1026-maximum-difference-between-node-and-ancestor/README.md rename to amazon_6months/1026-maximum-difference-between-node-and-ancestor.html diff --git a/amazon_6months/1038-binary-search-tree-to-greater-sum-tree.html b/amazon_6months/1038-binary-search-tree-to-greater-sum-tree.html new file mode 100644 index 000000000..e69de29bb diff --git a/1052-grumpy-bookstore-owner/README.md b/amazon_6months/1052-grumpy-bookstore-owner.html similarity index 100% rename from 1052-grumpy-bookstore-owner/README.md rename to amazon_6months/1052-grumpy-bookstore-owner.html diff --git a/1060-missing-element-in-sorted-array/README.md b/amazon_6months/1060-missing-element-in-sorted-array.html similarity index 100% rename from 1060-missing-element-in-sorted-array/README.md rename to amazon_6months/1060-missing-element-in-sorted-array.html diff --git a/1062-longest-repeating-substring/README.md b/amazon_6months/1062-longest-repeating-substring.html similarity index 100% rename from 1062-longest-repeating-substring/README.md rename to amazon_6months/1062-longest-repeating-substring.html diff --git a/1105-filling-bookcase-shelves/README.md b/amazon_6months/1105-filling-bookcase-shelves.html similarity index 100% rename from 1105-filling-bookcase-shelves/README.md rename to amazon_6months/1105-filling-bookcase-shelves.html diff --git a/1120-maximum-average-subtree/README.md b/amazon_6months/1120-maximum-average-subtree.html similarity index 100% rename from 1120-maximum-average-subtree/README.md rename to amazon_6months/1120-maximum-average-subtree.html diff --git a/1140-stone-game-ii/README.md b/amazon_6months/1140-stone-game-ii.html similarity index 100% rename from 1140-stone-game-ii/README.md rename to amazon_6months/1140-stone-game-ii.html diff --git a/1143-longest-common-subsequence/README.md b/amazon_6months/1143-longest-common-subsequence.html similarity index 100% rename from 1143-longest-common-subsequence/README.md rename to amazon_6months/1143-longest-common-subsequence.html diff --git a/1155-number-of-dice-rolls-with-target-sum/README.md b/amazon_6months/1155-number-of-dice-rolls-with-target-sum.html similarity index 100% rename from 1155-number-of-dice-rolls-with-target-sum/README.md rename to amazon_6months/1155-number-of-dice-rolls-with-target-sum.html diff --git a/1171-remove-zero-sum-consecutive-nodes-from-linked-list/README.md b/amazon_6months/1171-remove-zero-sum-consecutive-nodes-from-linked-list.html similarity index 100% rename from 1171-remove-zero-sum-consecutive-nodes-from-linked-list/README.md rename to amazon_6months/1171-remove-zero-sum-consecutive-nodes-from-linked-list.html diff --git a/1219-path-with-maximum-gold/README.md b/amazon_6months/1219-path-with-maximum-gold.html similarity index 100% rename from 1219-path-with-maximum-gold/README.md rename to amazon_6months/1219-path-with-maximum-gold.html diff --git a/1248-count-number-of-nice-subarrays/README.md b/amazon_6months/1248-count-number-of-nice-subarrays.html similarity index 100% rename from 1248-count-number-of-nice-subarrays/README.md rename to amazon_6months/1248-count-number-of-nice-subarrays.html diff --git a/1249-minimum-remove-to-make-valid-parentheses/README.md b/amazon_6months/1249-minimum-remove-to-make-valid-parentheses.html similarity index 100% rename from 1249-minimum-remove-to-make-valid-parentheses/README.md rename to amazon_6months/1249-minimum-remove-to-make-valid-parentheses.html diff --git a/1282-group-the-people-given-the-group-size-they-belong-to/README.md b/amazon_6months/1282-group-the-people-given-the-group-size-they-belong-to.html similarity index 100% rename from 1282-group-the-people-given-the-group-size-they-belong-to/README.md rename to amazon_6months/1282-group-the-people-given-the-group-size-they-belong-to.html diff --git a/1325-delete-leaves-with-a-given-value/README.md b/amazon_6months/1325-delete-leaves-with-a-given-value.html similarity index 100% rename from 1325-delete-leaves-with-a-given-value/README.md rename to amazon_6months/1325-delete-leaves-with-a-given-value.html diff --git a/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/README.md b/amazon_6months/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.html similarity index 100% rename from 1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/README.md rename to amazon_6months/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.html diff --git a/amazon_6months/1382-balance-a-binary-search-tree.html b/amazon_6months/1382-balance-a-binary-search-tree.html new file mode 100644 index 000000000..e69de29bb diff --git a/1395-count-number-of-teams/README.md b/amazon_6months/1395-count-number-of-teams.html similarity index 100% rename from 1395-count-number-of-teams/README.md rename to amazon_6months/1395-count-number-of-teams.html diff --git a/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/README.md b/amazon_6months/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.html similarity index 100% rename from 1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/README.md rename to amazon_6months/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.html diff --git a/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/README.md b/amazon_6months/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.html similarity index 100% rename from 1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/README.md rename to amazon_6months/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.html diff --git a/1457-pseudo-palindromic-paths-in-a-binary-tree/README.md b/amazon_6months/1457-pseudo-palindromic-paths-in-a-binary-tree.html similarity index 100% rename from 1457-pseudo-palindromic-paths-in-a-binary-tree/README.md rename to amazon_6months/1457-pseudo-palindromic-paths-in-a-binary-tree.html diff --git a/1482-minimum-number-of-days-to-make-m-bouquets/README.md b/amazon_6months/1482-minimum-number-of-days-to-make-m-bouquets.html similarity index 100% rename from 1482-minimum-number-of-days-to-make-m-bouquets/README.md rename to amazon_6months/1482-minimum-number-of-days-to-make-m-bouquets.html diff --git a/1508-range-sum-of-sorted-subarray-sums/README.md b/amazon_6months/1508-range-sum-of-sorted-subarray-sums.html similarity index 100% rename from 1508-range-sum-of-sorted-subarray-sums/README.md rename to amazon_6months/1508-range-sum-of-sorted-subarray-sums.html diff --git a/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/README.md b/amazon_6months/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.html similarity index 100% rename from 1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/README.md rename to amazon_6months/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.html diff --git a/1653-minimum-deletions-to-make-string-balanced/README.md b/amazon_6months/1653-minimum-deletions-to-make-string-balanced.html similarity index 100% rename from 1653-minimum-deletions-to-make-string-balanced/README.md rename to amazon_6months/1653-minimum-deletions-to-make-string-balanced.html diff --git a/1669-merge-in-between-linked-lists/README.md b/amazon_6months/1669-merge-in-between-linked-lists.html similarity index 100% rename from 1669-merge-in-between-linked-lists/README.md rename to amazon_6months/1669-merge-in-between-linked-lists.html diff --git a/1701-average-waiting-time/README.md b/amazon_6months/1701-average-waiting-time.html similarity index 100% rename from 1701-average-waiting-time/README.md rename to amazon_6months/1701-average-waiting-time.html diff --git a/1740-find-distance-in-a-binary-tree/README.md b/amazon_6months/1740-find-distance-in-a-binary-tree.html similarity index 100% rename from 1740-find-distance-in-a-binary-tree/README.md rename to amazon_6months/1740-find-distance-in-a-binary-tree.html diff --git a/1750-minimum-length-of-string-after-deleting-similar-ends/README.md b/amazon_6months/1750-minimum-length-of-string-after-deleting-similar-ends.html similarity index 100% rename from 1750-minimum-length-of-string-after-deleting-similar-ends/README.md rename to amazon_6months/1750-minimum-length-of-string-after-deleting-similar-ends.html diff --git a/1838-frequency-of-the-most-frequent-element/README.md b/amazon_6months/1838-frequency-of-the-most-frequent-element.html similarity index 100% rename from 1838-frequency-of-the-most-frequent-element/README.md rename to amazon_6months/1838-frequency-of-the-most-frequent-element.html diff --git a/1846-maximum-element-after-decreasing-and-rearranging/README.md b/amazon_6months/1846-maximum-element-after-decreasing-and-rearranging.html similarity index 100% rename from 1846-maximum-element-after-decreasing-and-rearranging/README.md rename to amazon_6months/1846-maximum-element-after-decreasing-and-rearranging.html diff --git a/1915-number-of-wonderful-substrings/README.md b/amazon_6months/1915-number-of-wonderful-substrings.html similarity index 100% rename from 1915-number-of-wonderful-substrings/README.md rename to amazon_6months/1915-number-of-wonderful-substrings.html diff --git a/1937-maximum-number-of-points-with-cost/README.md b/amazon_6months/1937-maximum-number-of-points-with-cost.html similarity index 100% rename from 1937-maximum-number-of-points-with-cost/README.md rename to amazon_6months/1937-maximum-number-of-points-with-cost.html diff --git a/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/README.md b/amazon_6months/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.html similarity index 100% rename from 2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/README.md rename to amazon_6months/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.html diff --git a/amazon_6months/2096-step-by-step-directions-from-a-binary-tree-node-to-another.html b/amazon_6months/2096-step-by-step-directions-from-a-binary-tree-node-to-another.html new file mode 100644 index 000000000..e69de29bb diff --git a/2125-number-of-laser-beams-in-a-bank/README.md b/amazon_6months/2125-number-of-laser-beams-in-a-bank.html similarity index 100% rename from 2125-number-of-laser-beams-in-a-bank/README.md rename to amazon_6months/2125-number-of-laser-beams-in-a-bank.html diff --git a/2134-minimum-swaps-to-group-all-1s-together-ii/README.md b/amazon_6months/2134-minimum-swaps-to-group-all-1s-together-ii.html similarity index 100% rename from 2134-minimum-swaps-to-group-all-1s-together-ii/README.md rename to amazon_6months/2134-minimum-swaps-to-group-all-1s-together-ii.html diff --git a/2149-rearrange-array-elements-by-sign/README.md b/amazon_6months/2149-rearrange-array-elements-by-sign.html similarity index 100% rename from 2149-rearrange-array-elements-by-sign/README.md rename to amazon_6months/2149-rearrange-array-elements-by-sign.html diff --git a/2191-sort-the-jumbled-numbers/README.md b/amazon_6months/2191-sort-the-jumbled-numbers.html similarity index 100% rename from 2191-sort-the-jumbled-numbers/README.md rename to amazon_6months/2191-sort-the-jumbled-numbers.html diff --git a/2196-create-binary-tree-from-descriptions/README.md b/amazon_6months/2196-create-binary-tree-from-descriptions.html similarity index 100% rename from 2196-create-binary-tree-from-descriptions/README.md rename to amazon_6months/2196-create-binary-tree-from-descriptions.html diff --git a/amazon_6months/2285-maximum-total-importance-of-roads.html b/amazon_6months/2285-maximum-total-importance-of-roads.html new file mode 100644 index 000000000..e69de29bb diff --git a/2353-design-a-food-rating-system/README.md b/amazon_6months/2353-design-a-food-rating-system.html similarity index 100% rename from 2353-design-a-food-rating-system/README.md rename to amazon_6months/2353-design-a-food-rating-system.html diff --git a/2370-longest-ideal-subsequence/README.md b/amazon_6months/2370-longest-ideal-subsequence.html similarity index 100% rename from 2370-longest-ideal-subsequence/README.md rename to amazon_6months/2370-longest-ideal-subsequence.html diff --git a/2385-amount-of-time-for-binary-tree-to-be-infected/README.md b/amazon_6months/2385-amount-of-time-for-binary-tree-to-be-infected.html similarity index 100% rename from 2385-amount-of-time-for-binary-tree-to-be-infected/README.md rename to amazon_6months/2385-amount-of-time-for-binary-tree-to-be-infected.html diff --git a/2391-minimum-amount-of-time-to-collect-garbage/README.md b/amazon_6months/2391-minimum-amount-of-time-to-collect-garbage.html similarity index 100% rename from 2391-minimum-amount-of-time-to-collect-garbage/README.md rename to amazon_6months/2391-minimum-amount-of-time-to-collect-garbage.html diff --git a/2433-find-the-original-array-of-prefix-xor/README.md b/amazon_6months/2433-find-the-original-array-of-prefix-xor.html similarity index 100% rename from 2433-find-the-original-array-of-prefix-xor/README.md rename to amazon_6months/2433-find-the-original-array-of-prefix-xor.html diff --git a/2482-difference-between-ones-and-zeros-in-row-and-column/README.md b/amazon_6months/2482-difference-between-ones-and-zeros-in-row-and-column.html similarity index 100% rename from 2482-difference-between-ones-and-zeros-in-row-and-column/README.md rename to amazon_6months/2482-difference-between-ones-and-zeros-in-row-and-column.html diff --git a/2486-append-characters-to-string-to-make-subsequence/README.md b/amazon_6months/2486-append-characters-to-string-to-make-subsequence.html similarity index 100% rename from 2486-append-characters-to-string-to-make-subsequence/README.md rename to amazon_6months/2486-append-characters-to-string-to-make-subsequence.html diff --git a/amazon_6months/2487-remove-nodes-from-linked-list.html b/amazon_6months/2487-remove-nodes-from-linked-list.html new file mode 100644 index 000000000..e69de29bb diff --git a/2597-the-number-of-beautiful-subsets/README.md b/amazon_6months/2597-the-number-of-beautiful-subsets.html similarity index 100% rename from 2597-the-number-of-beautiful-subsets/README.md rename to amazon_6months/2597-the-number-of-beautiful-subsets.html diff --git a/2694-event-emitter/README.md b/amazon_6months/2694-event-emitter.html similarity index 100% rename from 2694-event-emitter/README.md rename to amazon_6months/2694-event-emitter.html diff --git a/2802-find-the-k-th-lucky-number/README.md b/amazon_6months/2802-find-the-k-th-lucky-number.html similarity index 100% rename from 2802-find-the-k-th-lucky-number/README.md rename to amazon_6months/2802-find-the-k-th-lucky-number.html diff --git a/2816-double-a-number-represented-as-a-linked-list/README.md b/amazon_6months/2816-double-a-number-represented-as-a-linked-list.html similarity index 100% rename from 2816-double-a-number-represented-as-a-linked-list/README.md rename to amazon_6months/2816-double-a-number-represented-as-a-linked-list.html diff --git a/2825-make-string-a-subsequence-using-cyclic-increments/README.md b/amazon_6months/2825-make-string-a-subsequence-using-cyclic-increments.html similarity index 100% rename from 2825-make-string-a-subsequence-using-cyclic-increments/README.md rename to amazon_6months/2825-make-string-a-subsequence-using-cyclic-increments.html diff --git a/2870-minimum-number-of-operations-to-make-array-empty/README.md b/amazon_6months/2870-minimum-number-of-operations-to-make-array-empty.html similarity index 100% rename from 2870-minimum-number-of-operations-to-make-array-empty/README.md rename to amazon_6months/2870-minimum-number-of-operations-to-make-array-empty.html diff --git a/2958-length-of-longest-subarray-with-at-most-k-frequency/README.md b/amazon_6months/2958-length-of-longest-subarray-with-at-most-k-frequency.html similarity index 100% rename from 2958-length-of-longest-subarray-with-at-most-k-frequency/README.md rename to amazon_6months/2958-length-of-longest-subarray-with-at-most-k-frequency.html diff --git a/2962-count-subarrays-where-max-element-appears-at-least-k-times/README.md b/amazon_6months/2962-count-subarrays-where-max-element-appears-at-least-k-times.html similarity index 100% rename from 2962-count-subarrays-where-max-element-appears-at-least-k-times/README.md rename to amazon_6months/2962-count-subarrays-where-max-element-appears-at-least-k-times.html diff --git a/2976-minimum-cost-to-convert-string-i/README.md b/amazon_6months/2976-minimum-cost-to-convert-string-i.html similarity index 100% rename from 2976-minimum-cost-to-convert-string-i/README.md rename to amazon_6months/2976-minimum-cost-to-convert-string-i.html diff --git a/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/README.md b/amazon_6months/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.html similarity index 100% rename from 2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/README.md rename to amazon_6months/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.html diff --git a/3016-minimum-number-of-pushes-to-type-word-ii/README.md b/amazon_6months/3016-minimum-number-of-pushes-to-type-word-ii.html similarity index 100% rename from 3016-minimum-number-of-pushes-to-type-word-ii/README.md rename to amazon_6months/3016-minimum-number-of-pushes-to-type-word-ii.html diff --git a/3075-maximize-happiness-of-selected-children/README.md b/amazon_6months/3075-maximize-happiness-of-selected-children.html similarity index 100% rename from 3075-maximize-happiness-of-selected-children/README.md rename to amazon_6months/3075-maximize-happiness-of-selected-children.html diff --git a/copy.py b/copy.py new file mode 100644 index 000000000..5f8012520 --- /dev/null +++ b/copy.py @@ -0,0 +1,59 @@ +import os +import shutil + +# Assign directory +directory = r"./problems" +destination = r"./final/" + +# Iterate over files in directory +count = 0 +list = [] +for folder in os.listdir(directory): + print("!folder " + folder) + # Open file + newfolder = "./problems/" + folder + #print("!newfolder " + newfolder) + #for name in os.listdir(newfolder): + #print("name " + name) + filename = os.path.join(newfolder, "README.md") + print("filename " + filename) + if os.path.exists(filename) is True: + with open(filename) as f: + #print(f"Content of '{name}'") + # Read content of file + #print(f.read()) + newfilename = destination + folder + '.html' + shutil.copyfile(filename, newfilename) + #print("True") + count = count + 1 + + else: + + newfilename = destination + folder + '.html' + with open(newfilename, 'w') as fp: + pass + list.append(newfilename) + +print("Count: ", count) + + +''' +#convert html to pdf +from pyhtml2pdf import converter + +for folder in os.listdir(directory): + print("!folder " + folder) + # Open file + newfolder = "./problems/" + folder + #print("!newfolder " + newfolder) + #for name in os.listdir(newfolder): + #print("name " + name) + filename = os.path.join(newfolder, "README.md") + print("filename " + filename) + newfilename = destination + folder + '.html' + newfilenamePdf = destination + folder + '.pdf' + path = os.path.abspath(newfilename) + converter.convert(f'file:///{path}', f'file:///{newfilenamePdf}') +''' + + diff --git a/fastPrep/amazon/1.java b/fastPrep/amazon/1.java new file mode 100644 index 000000000..f61d7970d --- /dev/null +++ b/fastPrep/amazon/1.java @@ -0,0 +1,109 @@ +/* +Minimize Sum of Distances to Warehouses +🔥 FULLTIME +📚 +RELATED PROBLEMS +Amazon has recently established n distribution centers in a new location. +They want to set up 2 warehouses to serve these distribution centers. Note that the centers and warehouses are all built along a straight line. A distribution center has its demands met by the warehouse that is closest to it. A logistics team wants to choose the location of the warehouses such that the sum of the distances of the distribution centers to their closest warehouses is minimized. + +Given an array dist_centers, that represent the positions of the distribution centers, return the minimum sum of distances to their closest warehouses if the warehouses are positioned optimally. + +Function Description + +Complete the function minSumDistancesToWarehouses in the editor. + +minSumDistancesToWarehouses has the following parameter: + +int[] dist_centers: an array of integers representing the positions of the distribution centers +Returns + +int: the minimum sum of distances to their closest warehouses + +Example 1: + +Input: dist_centers = [1, 6] +Output: 0 +Explanation: +Optimal solution: Place one warehouse at x1 = 1 and the other at x2 = 6. The sum of distances to the nearest warehouse is 0 + 0 = 0. + + +Example 2: + +Input: dist_centers = [1, 2, 5, 6] +Output: 2 +Explanation: + + + + Optimal solution: Place one warehouse at x1 = 1 and the other at x2 = 6. The distances to the nearest warehouse are [0, 0, 1, 0], resulting in a total distance sum of 2. + + +*/ + + +//solution +public int minSumDistancesToWarehouses(int[] dist_centers) +{ + //Base Check + if(dist_centers == null) + { + return -1; + } + + //Init + int value; + + //Compute + /** sort the given array */ + Arrays.sort(dist_centers); + + /** compute the global minimim distance */ + int globalMin = Integer.MAX_VALUE; + for(int i = 0; i < dist_centers.length - 1; i++) + { + for(int j = i + 1; j < dist_centers.length; j++) + { + //Current pair {i, j} + int localMin = minDist(i, j, dist_centers); + + //update globalMin; + globalMin = Math.min(globalMin, localMin); + + }// for + + }// for + + /** update value */ + value = globalMin; + + //Return + return value; + +}// + + +public int minDist(int i, int j, int[] dist_centers) +{ + //Base check + if(dist_centers == null) + { + return 0; + } + + //Init + int value; + + //Compute + int sum = 0; + for(int k = 0; k < dist_centers.length; k++) + { + sum += Math.min(Math.abs(dist_centers[k] - dist_centers[i]), Math.abs(dist_centers[k] - dist_centers[j])); + } + + /** update value */ + value = sum; + + //Return + return value; + +} \ No newline at end of file diff --git a/fastPrep/amazon/2.java b/fastPrep/amazon/2.java new file mode 100644 index 000000000..bca937d8e --- /dev/null +++ b/fastPrep/amazon/2.java @@ -0,0 +1,117 @@ +/* +Reduce Gifts +🔥 FULLTIME +📚 +RELATED PROBLEMS +New Year's Day is around the corner and Amazon is having a sale. They have a list of items they are considering but they may need to remove some of them. Determine the minimum number of items to remove from an array of prices so that the sum of prices of any k items does not exceed a threshold. + +Note: If the number of items in the list is less than k, then there is no need to remove any more items. + +Function Description + +Complete the function reduceGifts in the editor. + +reduceGifts has the following parameters: + +1. int prices[n]: the prices of each item +2. int k: the number of items to sum +3. int threshold: the maximum price of k items +Returns + +int: the minimum number of items to remove + +🌷ଓ༉。゚Credit to ꒰ა buddi ໒꒱ + +Example 1: + +Input: prices = [3, 2, 1, 4, 6, 5], k = 3, threshold = 14 +Output: 1 +Explanation: + + + +The sum of prices for every k = 3 items must not be more than threshold = 14. The sum of the prices of the last three items is 6 + 5 + 4 = 15. The item priced $6 can be removed leaving: + + + +No 3 items' prices sum to greater than 14. Only 1 item needs to be removed. + +Example 2: + +Input: prices = [9, 6, 7, 2, 7, 2], k = 2, threshold = 13 +Output: 2 +Explanation: + +Items with prices 9 and 7 have a sum larger than 13. After removing these two items, prices' = [6, 2, 7, 2]. + +No k items have a sum of prices greater than threshold. + +Example 3: + +Input: prices = [9, 6, 3, 2, 9, 10, 10, 11], k = 4, threshold = 1 +Output: 5 +Explanation: + +Since no price is less than or equal to threshold, the sum of any k elements will always be greater than threshold. + +The threshold only applies to goups of k items. Now the goal is to reduce the arr length to k - 1 which requires the removal of 5 elements. + +Constraints: +1 <= k <= n <= 105 +1 <= threshold <= 109 +1 <= prices[i] <= 100 + +*/ + +public int reduceGifts(int[] prices, int k, int threshold) +{ + //Base Check + if(prices == null || prices.length < k) + { + return 0; + } + + //Init + int value; + + //Compute + /** Sort the given array */ + Arrays.sort(prices); + + /** Find the minimum number of elements to be removed */ + int prevSum = 0; + for(int i = prices.length - 1; i >= prices.length - (k - 1); i--) + { + prevSum += prices[i]; + } + + int index = k - 2; + for(int i = prices.length - 1; i >= k - 1; i --) + { + //current subaray of size k + /** compute the sum of elements in the current subarray */ + int currentSum = prevSum; + currentSum -= i + 1 == prices.length ? 0 : prices[i + 1]; + currentSum += prices[i - (k - 1)]; + + /** check if the current subarray satisfies the requirement */ + if(currentSum <= threshold) + { + index = i; + break; + } + + //update prevSum + prevSum = currentSum; + + } + + /** update value */ + value = (prices.length - 1) - index; + + //Return + return value; + +} + + diff --git a/fastPrep/amazon/3.java b/fastPrep/amazon/3.java new file mode 100644 index 000000000..ae8cfdd6d --- /dev/null +++ b/fastPrep/amazon/3.java @@ -0,0 +1,90 @@ +public int maximizeNegativePnLMonths(int[] PnL) +{ + //Base Check + if(PnL == null || PnL[0] <= 0) + { + return 0; + } + + //Init + int value; + + //Compute + int count = 0, prevSum = PnL[0]; + PriorityQueue pq = new PriorityQueue<>((a, b) -> b.compareTo(a)); + for(int i = 1; i < PnL.length; i++) + { + //current sum + int currentSum = prevSum + PnL[i]; + if(prevSum - PnL[i] > 0) + { + currentSum = prevSum - PnL[i]; + pq.offer(PnL[i]); + count++; + } + else + { + if(!pq.isEmpty()) + { + /** + * why is there another condition "(pq.peek() - PnL[i] > 0)" + * reason: we must make sure that the total sum after the conversion must be greater than the sum without change current element + * to a negative element. + * That is to say that (prevSum + pq.peek() * 2 - PnL[i] > 0) - (prevSum + PnL[i]) > 0 + * (prevSum + pq.peek() * 2 - PnL[i] > 0) - (prevSum + PnL[i]) > 0 + * ==> 2 * pq.peek() - 2 * PnL[i] > 0 + * ==> pq.peek() > PnL[i] + */ + + if((prevSum + pq.peek() * 2 - PnL[i] > 0) && (pq.peek() - PnL[i] > 0)) + { + currentSum = prevSum + pq.peek() * 2 - PnL[i]; + pq.poll(); + pq.offer(PnL[i]); + + }// if + + }// if + + }// else + + //update currentSum + prevSum = currentSum; + + }// for + + /** update velue */ + value = count; + + //Return + return value; + +} + + +/* + * + * Maximize Negative PnL Months +🔥 FULLTIME +📚 +RELATED PROBLEMS +You are analyzing the market trends of Amazon stocks. An AWS financial service model returned an array of integers, PnL (Profit and Loss), for your portfolio representing that in the ith month, you will either gain or lose PnL[i]. All reported PnL values are positive, representing gains. + +As part of the analysis, you will perform the following operation on the PnL array any number of times: + +Choose any month (0 ≤ i < n) and multiply PnL[i] by -1 +Find the maximum number of months you can afford to face a loss, i.e., have a negative PnL, such that the cumulative PnL for each of the n months remains strictly positive i.e. remains greater than 0. + +Note: The cumulative PnL for the ith month is defined as the sum of PnL from the starting month up to the ith month. For example, the cumulative PnL for the PnL = [3, -2, 5, -6, 1] is [3, 1, 6, 0, 1]. + +Function Description + +Complete the function maximizeNegativePnLMonths in the editor. + +maximizeNegativePnLMonths has the following parameter: + +int[] PnL: an array of integers representing the Profit and Loss for each month +Returns + +int: the maximum number of months with a negative PnL such that the cumulative PnL remains positive + */ diff --git a/fastPrep/amazon/4.java b/fastPrep/amazon/4.java new file mode 100644 index 000000000..2c9dac303 --- /dev/null +++ b/fastPrep/amazon/4.java @@ -0,0 +1,100 @@ + +public int calculateBeautyValues(int[] arr, int[][] pairs) +{ + //Base Check + if(arr.length == 0) + { + return 0; + } + + //Init + int value; + + //Compuate + /** find the used indices */ + Set set = new HashSet<>(); + List bList = new ArrayList<>(); + for(int[] pair : pairs) + { + //update set + set.add(pair[0]); + set.add(pair[1]); + + //update bList + if(pair[0] != pair[1]) + { + bList.add(arr[pair[0]]); + bList.add(arr[pair[1]]); + } + else + { + bList.add(arr[pair[0]]); + } + + }// + + /** get all the unused indicies */ + Set unused = new HashSet<>(); + for(int i = 0; i < arr.length; i++) + { + if(!set.contains(i)) + { + unused.add(i); + } + + }// for + + /** compute the freqeuncey for each element at the used index */ + Map freqMap = new HashMap<>(); + for(int num : bList) + { + freqMap.put(num, freqMap.getOrDefault(num, 0) + 1); + } + + /** count the total number of elements that are greater than elements at the unused indicies */ + int count = 0; + for(int key : freqMap.keySet()) + { + //current key + int localCount = 0; + for(int index : unused) + { + if(key < arr[index]) + { + localCount += freqMap.get(key); + } + + }// for + + //update count + count += localCount; + + }// for + + /** update value */ + value = count; + + //Return + return value; + +} + + +/** + * Calculate Beauty Values +📚 +RELATED PROBLEMS +Given an array arr of size n and pairs of size m * 2, where each pair represents the starting and ending index of a subarray, we need to calculate the beauty of the array. The process of calculating the beauty involves creating a beautiful array by processing each pair and appending the subarray defined by the pair to the beautiful array. After processing all pairs, we need to return the summation of the count of values exactly lesser than the values at the unused indexes in the original array. + +Function Description + +Complete the function calculateBeautyValues in the editor. + +calculateBeautyValues has the following parameters: + +1. int arr[n]: an array of integers +2. int pairs[m][2]: an array of pairs representing subarray indexes +Returns + +int: the sum of counts of values less than the values at unused indexes + */ \ No newline at end of file diff --git a/fastPrep/amazon/5.java b/fastPrep/amazon/5.java new file mode 100644 index 000000000..401a9d275 --- /dev/null +++ b/fastPrep/amazon/5.java @@ -0,0 +1,64 @@ +/* +Get Minimum Boxes +🔥 FULLTIME +📚 +RELATED PROBLEMS +The supply chain manager at one of Amazon's warehouses is shipping the last container of the day. All n boxes have been loaded into the truck with their sizes represented in the array boxes. The truck may not have enough capacity to store all the boxes though, so some of the boxes may have to be unloaded. The remaining boxes must satisfy the condition max(boxes) ≤ capacity * min(boxes). + +Given the array, boxes, and capacity, find the minimum number of boxes that need to be unloaded. + +Function Description + +Complete the function getMinimumBoxes in the editor. + +getMinimumBoxes has the following parameters: + +1. int[] boxes: an array of integers representing the sizes of the boxes +2. int capacity: the capacity of the truck +Returns + +int: the minimum number of boxes that need to be unloaded +*/ + +//brute force +public int getMinimumBoxes(int[] boxes, int capacity) +{ + //Base Check + if(boxes == null) + { + return 0; + } + + //Init + int value; + + //Compute + /** sort the given array */ + Arrays.sort(boxes); + + /** find the maximum number of boxes to be loaded */ + int longest = Integer.MIN_VALUE; + for(int i = 0; i < boxes.length - 1; i++) + { + for(int j = i; j < boxes.length; j++) + { + //current pair (min, max) + int localLen = Integer.MIN_VALUE; + if(boxes[j] <= capacity * boxes[i]) + { + localLen = j - i + 1; + } + + //Update longest + longest = Math.max(longest, localLen); + + }// for + + }// for + + /** update value */ + value = boxes.length - longest; + + //Return + return value; +} diff --git a/final/.git.html b/final/.git.html new file mode 100644 index 000000000..e69de29bb diff --git a/final/.github.html b/final/.github.html new file mode 100644 index 000000000..e69de29bb diff --git a/0001-two-sum/README.md b/final/0001-two-sum.html similarity index 100% rename from 0001-two-sum/README.md rename to final/0001-two-sum.html diff --git a/final/0002-add-two-numbers.html b/final/0002-add-two-numbers.html new file mode 100644 index 000000000..0ec64b7cf --- /dev/null +++ b/final/0002-add-two-numbers.html @@ -0,0 +1,33 @@ +

2. Add Two Numbers

Medium


You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

+ +

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

+ +

 

+

Example 1:

+ +
Input: l1 = [2,4,3], l2 = [5,6,4]
+Output: [7,0,8]
+Explanation: 342 + 465 = 807.
+
+ +

Example 2:

+ +
Input: l1 = [0], l2 = [0]
+Output: [0]
+
+ +

Example 3:

+ +
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
+Output: [8,9,9,9,0,0,0,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 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 diff --git a/final/0003-longest-substring-without-repeating-characters.html b/final/0003-longest-substring-without-repeating-characters.html new file mode 100644 index 000000000..857ec8b40 --- /dev/null +++ b/final/0003-longest-substring-without-repeating-characters.html @@ -0,0 +1,33 @@ +

3. Longest Substring Without Repeating Characters

Medium


Given a string s, find the length of the longest substring without repeating characters.

+ +

 

+

Example 1:

+ +
Input: s = "abcabcbb"
+Output: 3
+Explanation: The answer is "abc", with the length of 3.
+
+ +

Example 2:

+ +
Input: s = "bbbbb"
+Output: 1
+Explanation: The answer is "b", with the length of 1.
+
+ +

Example 3:

+ +
Input: s = "pwwkew"
+Output: 3
+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.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= s.length <= 5 * 104
  • +
  • s consists of English letters, digits, symbols and spaces.
  • +
+
\ No newline at end of file diff --git a/0004-median-of-two-sorted-arrays/README.md b/final/0004-median-of-two-sorted-arrays.html similarity index 100% rename from 0004-median-of-two-sorted-arrays/README.md rename to final/0004-median-of-two-sorted-arrays.html diff --git a/final/0005-longest-palindromic-substring.html b/final/0005-longest-palindromic-substring.html new file mode 100644 index 000000000..ea3d65712 --- /dev/null +++ b/final/0005-longest-palindromic-substring.html @@ -0,0 +1,24 @@ +

5. Longest Palindromic Substring

Medium


Given a string s, return the longest palindromic substring in s.

+ +

 

+

Example 1:

+ +
Input: s = "babad"
+Output: "bab"
+Explanation: "aba" is also a valid answer.
+
+ +

Example 2:

+ +
Input: s = "cbbd"
+Output: "bb"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consist of only digits and English letters.
  • +
+
\ No newline at end of file diff --git a/final/0006-zigzag-conversion.html b/final/0006-zigzag-conversion.html new file mode 100644 index 000000000..b4396e037 --- /dev/null +++ b/final/0006-zigzag-conversion.html @@ -0,0 +1,47 @@ +

6. Zigzag Conversion

Medium


The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

+ +
P   A   H   N
+A P L S I I G
+Y   I   R
+
+ +

And then read line by line: "PAHNAPLSIIGYIR"

+ +

Write the code that will take a string and make this conversion given a number of rows:

+ +
string convert(string s, int numRows);
+
+ +

 

+

Example 1:

+ +
Input: s = "PAYPALISHIRING", numRows = 3
+Output: "PAHNAPLSIIGYIR"
+
+ +

Example 2:

+ +
Input: s = "PAYPALISHIRING", numRows = 4
+Output: "PINALSIGYAHRPI"
+Explanation:
+P     I    N
+A   L S  I G
+Y A   H R
+P     I
+
+ +

Example 3:

+ +
Input: s = "A", numRows = 1
+Output: "A"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consists of English letters (lower-case and upper-case), ',' and '.'.
  • +
  • 1 <= numRows <= 1000
  • +
+
\ No newline at end of file diff --git a/final/0007-reverse-integer.html b/final/0007-reverse-integer.html new file mode 100644 index 000000000..db5afe4a5 --- /dev/null +++ b/final/0007-reverse-integer.html @@ -0,0 +1,30 @@ +

7. Reverse Integer

Medium


Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

+ +

Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

+ +

 

+

Example 1:

+ +
Input: x = 123
+Output: 321
+
+ +

Example 2:

+ +
Input: x = -123
+Output: -321
+
+ +

Example 3:

+ +
Input: x = 120
+Output: 21
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= x <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/final/0008-string-to-integer-atoi.html b/final/0008-string-to-integer-atoi.html new file mode 100644 index 000000000..4bb3ba712 --- /dev/null +++ b/final/0008-string-to-integer-atoi.html @@ -0,0 +1,74 @@ +

8. String to Integer (atoi)

Medium


Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).

+ +

The algorithm for myAtoi(string s) is as follows:

+ +
    +
  1. Read in and ignore any leading whitespace.
  2. +
  3. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
  4. +
  5. Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.
  6. +
  7. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
  8. +
  9. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
  10. +
  11. Return the integer as the final result.
  12. +
+ +

Note:

+ +
    +
  • Only the space character ' ' is considered a whitespace character.
  • +
  • Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.
  • +
+ +

 

+

Example 1:

+ +
Input: s = "42"
+Output: 42
+Explanation: The underlined characters are what is read in, the caret is the current reader position.
+Step 1: "42" (no characters read because there is no leading whitespace)
+         ^
+Step 2: "42" (no characters read because there is neither a '-' nor '+')
+         ^
+Step 3: "42" ("42" is read in)
+           ^
+The parsed integer is 42.
+Since 42 is in the range [-231, 231 - 1], the final result is 42.
+
+ +

Example 2:

+ +
Input: s = "   -42"
+Output: -42
+Explanation:
+Step 1: "   -42" (leading whitespace is read and ignored)
+            ^
+Step 2: "   -42" ('-' is read, so the result should be negative)
+             ^
+Step 3: "   -42" ("42" is read in)
+               ^
+The parsed integer is -42.
+Since -42 is in the range [-231, 231 - 1], the final result is -42.
+
+ +

Example 3:

+ +
Input: s = "4193 with words"
+Output: 4193
+Explanation:
+Step 1: "4193 with words" (no characters read because there is no leading whitespace)
+         ^
+Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+')
+         ^
+Step 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit)
+             ^
+The parsed integer is 4193.
+Since 4193 is in the range [-231, 231 - 1], the final result is 4193.
+
+ +

 

+

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 diff --git a/0009-palindrome-number/README.md b/final/0009-palindrome-number.html similarity index 100% rename from 0009-palindrome-number/README.md rename to final/0009-palindrome-number.html diff --git a/0010-regular-expression-matching/README.md b/final/0010-regular-expression-matching.html similarity index 100% rename from 0010-regular-expression-matching/README.md rename to final/0010-regular-expression-matching.html diff --git a/final/0011-container-with-most-water.html b/final/0011-container-with-most-water.html new file mode 100644 index 000000000..6c932927c --- /dev/null +++ b/final/0011-container-with-most-water.html @@ -0,0 +1,31 @@ +

11. Container With Most Water

Medium


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.

+ +

 

+

Example 1:

+ +
Input: height = [1,8,6,2,5,4,8,3,7]
+Output: 49
+Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
+
+ +

Example 2:

+ +
Input: height = [1,1]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • n == height.length
  • +
  • 2 <= n <= 105
  • +
  • 0 <= height[i] <= 104
  • +
+
\ No newline at end of file diff --git a/final/0012-integer-to-roman.html b/final/0012-integer-to-roman.html new file mode 100644 index 000000000..627b4bb1f --- /dev/null +++ b/final/0012-integer-to-roman.html @@ -0,0 +1,52 @@ +

12. Integer to Roman

Medium


Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

+ +
Symbol       Value
+I             1
+V             5
+X             10
+L             50
+C             100
+D             500
+M             1000
+ +

For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

+ +

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

+ +
    +
  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • +
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • +
  • C can be placed before D (500) and M (1000) to make 400 and 900.
  • +
+ +

Given an integer, convert it to a roman numeral.

+ +

 

+

Example 1:

+ +
Input: num = 3
+Output: "III"
+Explanation: 3 is represented as 3 ones.
+
+ +

Example 2:

+ +
Input: num = 58
+Output: "LVIII"
+Explanation: L = 50, V = 5, III = 3.
+
+ +

Example 3:

+ +
Input: num = 1994
+Output: "MCMXCIV"
+Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= num <= 3999
  • +
+
\ No newline at end of file diff --git a/0013-roman-to-integer/README.md b/final/0013-roman-to-integer.html similarity index 100% rename from 0013-roman-to-integer/README.md rename to final/0013-roman-to-integer.html diff --git a/0014-longest-common-prefix/README.md b/final/0014-longest-common-prefix.html similarity index 100% rename from 0014-longest-common-prefix/README.md rename to final/0014-longest-common-prefix.html diff --git a/final/0015-3sum.html b/final/0015-3sum.html new file mode 100644 index 000000000..6dd16400f --- /dev/null +++ b/final/0015-3sum.html @@ -0,0 +1,39 @@ +

15. 3Sum

Medium


Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

+ +

Notice that the solution set must not contain duplicate triplets.

+ +

 

+

Example 1:

+ +
Input: nums = [-1,0,1,2,-1,-4]
+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 = [0,1,1]
+Output: []
+Explanation: The only possible triplet does not sum up to 0.
+
+ +

Example 3:

+ +
Input: nums = [0,0,0]
+Output: [[0,0,0]]
+Explanation: The only possible triplet sums up to 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= nums.length <= 3000
  • +
  • -105 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/final/0016-3sum-closest.html b/final/0016-3sum-closest.html new file mode 100644 index 000000000..d362ac2dc --- /dev/null +++ b/final/0016-3sum-closest.html @@ -0,0 +1,30 @@ +

16. 3Sum Closest

Medium


Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.

+ +

Return the sum of the three integers.

+ +

You may assume that each input would have exactly one solution.

+ +

 

+

Example 1:

+ +
Input: nums = [-1,2,1,-4], target = 1
+Output: 2
+Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
+
+ +

Example 2:

+ +
Input: nums = [0,0,0], target = 1
+Output: 0
+Explanation: The sum that is closest to the target is 0. (0 + 0 + 0 = 0).
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= nums.length <= 500
  • +
  • -1000 <= nums[i] <= 1000
  • +
  • -104 <= target <= 104
  • +
+
\ No newline at end of file diff --git a/final/0017-letter-combinations-of-a-phone-number.html b/final/0017-letter-combinations-of-a-phone-number.html new file mode 100644 index 000000000..81e0b1fbb --- /dev/null +++ b/final/0017-letter-combinations-of-a-phone-number.html @@ -0,0 +1,31 @@ +

17. Letter Combinations of a Phone Number

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 digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

+ +

 

+

Example 1:

+ +
Input: digits = "23"
+Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
+
+ +

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 diff --git a/final/0018-4sum.html b/final/0018-4sum.html new file mode 100644 index 000000000..31fd5edda --- /dev/null +++ b/final/0018-4sum.html @@ -0,0 +1,32 @@ +

18. 4Sum

Medium


Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:

+ +
    +
  • 0 <= a, b, c, d < n
  • +
  • a, b, c, and d are distinct.
  • +
  • nums[a] + nums[b] + nums[c] + nums[d] == target
  • +
+ +

You may return the answer in any order.

+ +

 

+

Example 1:

+ +
Input: nums = [1,0,-1,0,-2,2], target = 0
+Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
+
+ +

Example 2:

+ +
Input: nums = [2,2,2,2,2], target = 8
+Output: [[2,2,2,2]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 200
  • +
  • -109 <= nums[i] <= 109
  • +
  • -109 <= target <= 109
  • +
+
\ No newline at end of file diff --git a/final/0019-remove-nth-node-from-end-of-list.html b/final/0019-remove-nth-node-from-end-of-list.html new file mode 100644 index 000000000..b1ecfb615 --- /dev/null +++ b/final/0019-remove-nth-node-from-end-of-list.html @@ -0,0 +1,34 @@ +

19. Remove Nth Node From End of List

Medium


Given the head of a linked list, remove the nth node from the end of the list and return its head.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5], n = 2
+Output: [1,2,3,5]
+
+ +

Example 2:

+ +
Input: head = [1], n = 1
+Output: []
+
+ +

Example 3:

+ +
Input: head = [1,2], n = 1
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is sz.
  • +
  • 1 <= sz <= 30
  • +
  • 0 <= Node.val <= 100
  • +
  • 1 <= n <= sz
  • +
+ +

 

+

Follow up: Could you do this in one pass?

+
\ No newline at end of file diff --git a/0020-valid-parentheses/README.md b/final/0020-valid-parentheses.html similarity index 100% rename from 0020-valid-parentheses/README.md rename to final/0020-valid-parentheses.html diff --git a/0021-merge-two-sorted-lists/README.md b/final/0021-merge-two-sorted-lists.html similarity index 100% rename from 0021-merge-two-sorted-lists/README.md rename to final/0021-merge-two-sorted-lists.html diff --git a/final/0022-generate-parentheses.html b/final/0022-generate-parentheses.html new file mode 100644 index 000000000..154f576c0 --- /dev/null +++ b/final/0022-generate-parentheses.html @@ -0,0 +1,17 @@ +

22. Generate Parentheses

Medium


Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

+ +

 

+

Example 1:

+
Input: n = 3
+Output: ["((()))","(()())","(())()","()(())","()()()"]
+

Example 2:

+
Input: n = 1
+Output: ["()"]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= n <= 8
  • +
+
\ No newline at end of file diff --git a/0023-merge-k-sorted-lists/README.md b/final/0023-merge-k-sorted-lists.html similarity index 100% rename from 0023-merge-k-sorted-lists/README.md rename to final/0023-merge-k-sorted-lists.html diff --git a/final/0024-swap-nodes-in-pairs.html b/final/0024-swap-nodes-in-pairs.html new file mode 100644 index 000000000..f410f5b08 --- /dev/null +++ b/final/0024-swap-nodes-in-pairs.html @@ -0,0 +1,29 @@ +

24. Swap Nodes in Pairs

Medium


Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4]
+Output: [2,1,4,3]
+
+ +

Example 2:

+ +
Input: head = []
+Output: []
+
+ +

Example 3:

+ +
Input: head = [1]
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 100].
  • +
  • 0 <= Node.val <= 100
  • +
+
\ No newline at end of file diff --git a/0025-reverse-nodes-in-k-group/README.md b/final/0025-reverse-nodes-in-k-group.html similarity index 100% rename from 0025-reverse-nodes-in-k-group/README.md rename to final/0025-reverse-nodes-in-k-group.html diff --git a/0026-remove-duplicates-from-sorted-array/README.md b/final/0026-remove-duplicates-from-sorted-array.html similarity index 100% rename from 0026-remove-duplicates-from-sorted-array/README.md rename to final/0026-remove-duplicates-from-sorted-array.html diff --git a/0027-remove-element/README.md b/final/0027-remove-element.html similarity index 100% rename from 0027-remove-element/README.md rename to final/0027-remove-element.html diff --git a/0028-find-the-index-of-the-first-occurrence-in-a-string/README.md b/final/0028-find-the-index-of-the-first-occurrence-in-a-string.html similarity index 100% rename from 0028-find-the-index-of-the-first-occurrence-in-a-string/README.md rename to final/0028-find-the-index-of-the-first-occurrence-in-a-string.html diff --git a/final/0029-divide-two-integers.html b/final/0029-divide-two-integers.html new file mode 100644 index 000000000..9f694a561 --- /dev/null +++ b/final/0029-divide-two-integers.html @@ -0,0 +1,31 @@ +

29. Divide Two Integers

Medium


Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.

+ +

The integer division should truncate toward zero, which means losing its fractional part. For example, 8.345 would be truncated to 8, and -2.7335 would be truncated to -2.

+ +

Return the quotient after dividing dividend by divisor.

+ +

Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For this problem, if the quotient is strictly greater than 231 - 1, then return 231 - 1, and if the quotient is strictly less than -231, then return -231.

+ +

 

+

Example 1:

+ +
Input: dividend = 10, divisor = 3
+Output: 3
+Explanation: 10/3 = 3.33333.. which is truncated to 3.
+
+ +

Example 2:

+ +
Input: dividend = 7, divisor = -3
+Output: -2
+Explanation: 7/-3 = -2.33333.. which is truncated to -2.
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= dividend, divisor <= 231 - 1
  • +
  • divisor != 0
  • +
+
\ No newline at end of file diff --git a/final/0031-next-permutation.html b/final/0031-next-permutation.html new file mode 100644 index 000000000..5d4986530 --- /dev/null +++ b/final/0031-next-permutation.html @@ -0,0 +1,45 @@ +

31. Next Permutation

Medium


A permutation of an array of integers is an arrangement of its members into a sequence or linear 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 and use only constant extra memory.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3]
+Output: [1,3,2]
+
+ +

Example 2:

+ +
Input: nums = [3,2,1]
+Output: [1,2,3]
+
+ +

Example 3:

+ +
Input: nums = [1,1,5]
+Output: [1,5,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 100
  • +
+
\ No newline at end of file diff --git a/final/0033-search-in-rotated-sorted-array.html b/final/0033-search-in-rotated-sorted-array.html new file mode 100644 index 000000000..0e622ad12 --- /dev/null +++ b/final/0033-search-in-rotated-sorted-array.html @@ -0,0 +1,30 @@ +

33. Search in Rotated Sorted Array

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].

+ +

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.

+ +

You must write an algorithm with O(log n) runtime complexity.

+ +

 

+

Example 1:

+
Input: nums = [4,5,6,7,0,1,2], target = 0
+Output: 4
+

Example 2:

+
Input: nums = [4,5,6,7,0,1,2], target = 3
+Output: -1
+

Example 3:

+
Input: nums = [1], target = 0
+Output: -1
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5000
  • +
  • -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 diff --git a/final/0034-find-first-and-last-position-of-element-in-sorted-array.html b/final/0034-find-first-and-last-position-of-element-in-sorted-array.html new file mode 100644 index 000000000..3ba57ee9b --- /dev/null +++ b/final/0034-find-first-and-last-position-of-element-in-sorted-array.html @@ -0,0 +1,27 @@ +

34. Find First and Last Position of Element in Sorted Array

Medium


Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.

+ +

If target is not found in the array, return [-1, -1].

+ +

You must write an algorithm with O(log n) runtime complexity.

+ +

 

+

Example 1:

+
Input: nums = [5,7,7,8,8,10], target = 8
+Output: [3,4]
+

Example 2:

+
Input: nums = [5,7,7,8,8,10], target = 6
+Output: [-1,-1]
+

Example 3:

+
Input: nums = [], target = 0
+Output: [-1,-1]
+
+

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
  • nums is a non-decreasing array.
  • +
  • -109 <= target <= 109
  • +
+
\ No newline at end of file diff --git a/0035-search-insert-position/README.md b/final/0035-search-insert-position.html similarity index 100% rename from 0035-search-insert-position/README.md rename to final/0035-search-insert-position.html diff --git a/final/0036-valid-sudoku.html b/final/0036-valid-sudoku.html new file mode 100644 index 000000000..b8a273938 --- /dev/null +++ b/final/0036-valid-sudoku.html @@ -0,0 +1,56 @@ +

36. Valid Sudoku

Medium


Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

+ +
    +
  1. Each row must contain the digits 1-9 without repetition.
  2. +
  3. Each column must contain the digits 1-9 without repetition.
  4. +
  5. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
  6. +
+ +

Note:

+ +
    +
  • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
  • +
  • Only the filled cells need to be validated according to the mentioned rules.
  • +
+ +

 

+

Example 1:

+ +
Input: board = 
+[["5","3",".",".","7",".",".",".","."]
+,["6",".",".","1","9","5",".",".","."]
+,[".","9","8",".",".",".",".","6","."]
+,["8",".",".",".","6",".",".",".","3"]
+,["4",".",".","8",".","3",".",".","1"]
+,["7",".",".",".","2",".",".",".","6"]
+,[".","6",".",".",".",".","2","8","."]
+,[".",".",".","4","1","9",".",".","5"]
+,[".",".",".",".","8",".",".","7","9"]]
+Output: true
+
+ +

Example 2:

+ +
Input: board = 
+[["8","3",".",".","7",".",".",".","."]
+,["6",".",".","1","9","5",".",".","."]
+,[".","9","8",".",".",".",".","6","."]
+,["8",".",".",".","6",".",".",".","3"]
+,["4",".",".","8",".","3",".",".","1"]
+,["7",".",".",".","2",".",".",".","6"]
+,[".","6",".",".",".",".","2","8","."]
+,[".",".",".","4","1","9",".",".","5"]
+,[".",".",".",".","8",".",".","7","9"]]
+Output: false
+Explanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.
+
+ +

 

+

Constraints:

+ +
    +
  • board.length == 9
  • +
  • board[i].length == 9
  • +
  • board[i][j] is a digit 1-9 or '.'.
  • +
+
\ No newline at end of file diff --git a/final/0039-combination-sum.html b/final/0039-combination-sum.html new file mode 100644 index 000000000..5b4816e03 --- /dev/null +++ b/final/0039-combination-sum.html @@ -0,0 +1,39 @@ +

39. Combination Sum

Medium


Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.

+ +

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.

+ +

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:

+ +
Input: candidates = [2,3,6,7], target = 7
+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.
+
+ +

Example 2:

+ +
Input: candidates = [2,3,5], target = 8
+Output: [[2,2,2,2],[2,3,3],[3,5]]
+
+ +

Example 3:

+ +
Input: candidates = [2], target = 1
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= candidates.length <= 30
  • +
  • 2 <= candidates[i] <= 40
  • +
  • All elements of candidates are distinct.
  • +
  • 1 <= target <= 40
  • +
+
\ No newline at end of file diff --git a/final/0040-combination-sum-ii.html b/final/0040-combination-sum-ii.html new file mode 100644 index 000000000..41ac5070f --- /dev/null +++ b/final/0040-combination-sum-ii.html @@ -0,0 +1,38 @@ +

40. Combination Sum II

Medium


Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.

+ +

Each number in candidates may only be used once in the combination.

+ +

Note: The solution set must not contain duplicate combinations.

+ +

 

+

Example 1:

+ +
Input: candidates = [10,1,2,7,6,1,5], target = 8
+Output: 
+[
+[1,1,6],
+[1,2,5],
+[1,7],
+[2,6]
+]
+
+ +

Example 2:

+ +
Input: candidates = [2,5,2,1,2], target = 5
+Output: 
+[
+[1,2,2],
+[5]
+]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= candidates.length <= 100
  • +
  • 1 <= candidates[i] <= 50
  • +
  • 1 <= target <= 30
  • +
+
\ No newline at end of file diff --git a/0041-first-missing-positive/README.md b/final/0041-first-missing-positive.html similarity index 100% rename from 0041-first-missing-positive/README.md rename to final/0041-first-missing-positive.html diff --git a/0042-trapping-rain-water/README.md b/final/0042-trapping-rain-water.html similarity index 100% rename from 0042-trapping-rain-water/README.md rename to final/0042-trapping-rain-water.html diff --git a/final/0045-jump-game-ii.html b/final/0045-jump-game-ii.html new file mode 100644 index 000000000..57bef2ed9 --- /dev/null +++ b/final/0045-jump-game-ii.html @@ -0,0 +1,34 @@ +

45. Jump Game II

Medium


You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0].

+ +

Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where:

+ +
    +
  • 0 <= j <= nums[i] and
  • +
  • i + j < n
  • +
+ +

Return the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1].

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,1,1,4]
+Output: 2
+Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
+
+ +

Example 2:

+ +
Input: nums = [2,3,0,1,4]
+Output: 2
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 104
  • +
  • 0 <= nums[i] <= 1000
  • +
  • It's guaranteed that you can reach nums[n - 1].
  • +
+
\ No newline at end of file diff --git a/final/0046-permutations.html b/final/0046-permutations.html new file mode 100644 index 000000000..25218c6e2 --- /dev/null +++ b/final/0046-permutations.html @@ -0,0 +1,22 @@ +

46. Permutations

Medium


Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

+ +

 

+

Example 1:

+
Input: nums = [1,2,3]
+Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
+

Example 2:

+
Input: nums = [0,1]
+Output: [[0,1],[1,0]]
+

Example 3:

+
Input: nums = [1]
+Output: [[1]]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 6
  • +
  • -10 <= nums[i] <= 10
  • +
  • All the integers of nums are unique.
  • +
+
\ No newline at end of file diff --git a/final/0048-rotate-image.html b/final/0048-rotate-image.html new file mode 100644 index 000000000..c415d5c42 --- /dev/null +++ b/final/0048-rotate-image.html @@ -0,0 +1,26 @@ +

48. Rotate Image

Medium


You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

+ +

You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

+ +

 

+

Example 1:

+ +
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
+Output: [[7,4,1],[8,5,2],[9,6,3]]
+
+ +

Example 2:

+ +
Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
+Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
+
+ +

 

+

Constraints:

+ +
    +
  • n == matrix.length == matrix[i].length
  • +
  • 1 <= n <= 20
  • +
  • -1000 <= matrix[i][j] <= 1000
  • +
+
\ No newline at end of file diff --git a/final/0049-group-anagrams.html b/final/0049-group-anagrams.html new file mode 100644 index 000000000..3da623eb5 --- /dev/null +++ b/final/0049-group-anagrams.html @@ -0,0 +1,24 @@ +

49. Group Anagrams

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.

+ +

 

+

Example 1:

+
Input: strs = ["eat","tea","tan","ate","nat","bat"]
+Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
+

Example 2:

+
Input: strs = [""]
+Output: [[""]]
+

Example 3:

+
Input: strs = ["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 diff --git a/final/0050-powx-n.html b/final/0050-powx-n.html new file mode 100644 index 000000000..b4380f4bf --- /dev/null +++ b/final/0050-powx-n.html @@ -0,0 +1,33 @@ +

50. Pow(x, n)

Medium


Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

+ +

 

+

Example 1:

+ +
Input: x = 2.00000, n = 10
+Output: 1024.00000
+
+ +

Example 2:

+ +
Input: x = 2.10000, n = 3
+Output: 9.26100
+
+ +

Example 3:

+ +
Input: x = 2.00000, n = -2
+Output: 0.25000
+Explanation: 2-2 = 1/22 = 1/4 = 0.25
+
+ +

 

+

Constraints:

+ +
    +
  • -100.0 < x < 100.0
  • +
  • -231 <= n <= 231-1
  • +
  • n is an integer.
  • +
  • Either x is not zero or n > 0.
  • +
  • -104 <= xn <= 104
  • +
+
\ No newline at end of file diff --git a/final/0053-maximum-subarray.html b/final/0053-maximum-subarray.html new file mode 100644 index 000000000..8c856c7c3 --- /dev/null +++ b/final/0053-maximum-subarray.html @@ -0,0 +1,35 @@ +

53. Maximum Subarray

Medium


Given an integer array nums, find the subarray with the largest sum, and return its sum.

+ +

 

+

Example 1:

+ +
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
+Output: 6
+Explanation: The subarray [4,-1,2,1] has the largest sum 6.
+
+ +

Example 2:

+ +
Input: nums = [1]
+Output: 1
+Explanation: The subarray [1] has the largest sum 1.
+
+ +

Example 3:

+ +
Input: nums = [5,4,-1,7,8]
+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 diff --git a/final/0054-spiral-matrix.html b/final/0054-spiral-matrix.html new file mode 100644 index 000000000..afec7a07d --- /dev/null +++ b/final/0054-spiral-matrix.html @@ -0,0 +1,25 @@ +

54. Spiral Matrix

Medium


Given an m x n matrix, return all elements of the matrix in spiral order.

+ +

 

+

Example 1:

+ +
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
+Output: [1,2,3,6,9,8,7,4,5]
+
+ +

Example 2:

+ +
Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
+Output: [1,2,3,4,8,12,11,10,9,5,6,7]
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m, n <= 10
  • +
  • -100 <= matrix[i][j] <= 100
  • +
+
\ No newline at end of file diff --git a/final/0055-jump-game.html b/final/0055-jump-game.html new file mode 100644 index 000000000..e69de29bb diff --git a/final/0056-merge-intervals.html b/final/0056-merge-intervals.html new file mode 100644 index 000000000..78870292f --- /dev/null +++ b/final/0056-merge-intervals.html @@ -0,0 +1,26 @@ +

56. Merge Intervals

Medium


Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

+ +

 

+

Example 1:

+ +
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
+Output: [[1,6],[8,10],[15,18]]
+Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6].
+
+ +

Example 2:

+ +
Input: intervals = [[1,4],[4,5]]
+Output: [[1,5]]
+Explanation: Intervals [1,4] and [4,5] are considered overlapping.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= intervals.length <= 104
  • +
  • intervals[i].length == 2
  • +
  • 0 <= starti <= endi <= 104
  • +
+
\ No newline at end of file diff --git a/final/0057-insert-interval.html b/final/0057-insert-interval.html new file mode 100644 index 000000000..3805102b5 --- /dev/null +++ b/final/0057-insert-interval.html @@ -0,0 +1,32 @@ +

57. Insert Interval

Medium


You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval.

+ +

Insert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping intervals (merge overlapping intervals if necessary).

+ +

Return intervals after the insertion.

+ +

 

+

Example 1:

+ +
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
+Output: [[1,5],[6,9]]
+
+ +

Example 2:

+ +
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
+Output: [[1,2],[3,10],[12,16]]
+Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= intervals.length <= 104
  • +
  • intervals[i].length == 2
  • +
  • 0 <= starti <= endi <= 105
  • +
  • intervals is sorted by starti in ascending order.
  • +
  • newInterval.length == 2
  • +
  • 0 <= start <= end <= 105
  • +
+
\ No newline at end of file diff --git a/0058-length-of-last-word/README.md b/final/0058-length-of-last-word.html similarity index 100% rename from 0058-length-of-last-word/README.md rename to final/0058-length-of-last-word.html diff --git a/0059-spiral-matrix-ii/README.md b/final/0059-spiral-matrix-ii.html similarity index 100% rename from 0059-spiral-matrix-ii/README.md rename to final/0059-spiral-matrix-ii.html diff --git a/final/0061-rotate-list.html b/final/0061-rotate-list.html new file mode 100644 index 000000000..390023b42 --- /dev/null +++ b/final/0061-rotate-list.html @@ -0,0 +1,24 @@ +

61. Rotate List

Medium


Given the head of a linked list, rotate the list to the right by k places.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5], k = 2
+Output: [4,5,1,2,3]
+
+ +

Example 2:

+ +
Input: head = [0,1,2], k = 4
+Output: [2,0,1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 500].
  • +
  • -100 <= Node.val <= 100
  • +
  • 0 <= k <= 2 * 109
  • +
+
\ No newline at end of file diff --git a/final/0062-unique-paths.html b/final/0062-unique-paths.html new file mode 100644 index 000000000..ec1dd06ab --- /dev/null +++ b/final/0062-unique-paths.html @@ -0,0 +1,30 @@ +

62. Unique Paths

Medium


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.

+ +

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.

+ +

The test cases are generated so that the answer will be less than or equal to 2 * 109.

+ +

 

+

Example 1:

+ +
Input: m = 3, n = 7
+Output: 28
+
+ +

Example 2:

+ +
Input: m = 3, n = 2
+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
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= m, n <= 100
  • +
+
\ No newline at end of file diff --git a/0063-unique-paths-ii/README.md b/final/0063-unique-paths-ii.html similarity index 100% rename from 0063-unique-paths-ii/README.md rename to final/0063-unique-paths-ii.html diff --git a/final/0064-minimum-path-sum.html b/final/0064-minimum-path-sum.html new file mode 100644 index 000000000..8da7737ce --- /dev/null +++ b/final/0064-minimum-path-sum.html @@ -0,0 +1,28 @@ +

64. Minimum Path Sum

Medium


Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.

+ +

Note: You can only move either down or right at any point in time.

+ +

 

+

Example 1:

+ +
Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
+Output: 7
+Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.
+
+ +

Example 2:

+ +
Input: grid = [[1,2,3],[4,5,6]]
+Output: 12
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 200
  • +
  • 0 <= grid[i][j] <= 200
  • +
+
\ No newline at end of file diff --git a/0066-plus-one/README.md b/final/0066-plus-one.html similarity index 100% rename from 0066-plus-one/README.md rename to final/0066-plus-one.html diff --git a/0067-add-binary/README.md b/final/0067-add-binary.html similarity index 100% rename from 0067-add-binary/README.md rename to final/0067-add-binary.html diff --git a/0068-text-justification/README.md b/final/0068-text-justification.html similarity index 100% rename from 0068-text-justification/README.md rename to final/0068-text-justification.html diff --git a/0069-sqrtx/README.md b/final/0069-sqrtx.html similarity index 100% rename from 0069-sqrtx/README.md rename to final/0069-sqrtx.html diff --git a/0070-climbing-stairs/README.md b/final/0070-climbing-stairs.html similarity index 100% rename from 0070-climbing-stairs/README.md rename to final/0070-climbing-stairs.html diff --git a/final/0073-set-matrix-zeroes.html b/final/0073-set-matrix-zeroes.html new file mode 100644 index 000000000..574d6249a --- /dev/null +++ b/final/0073-set-matrix-zeroes.html @@ -0,0 +1,36 @@ +

73. Set Matrix Zeroes

Medium


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.

+ +

 

+

Example 1:

+ +
Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
+Output: [[1,0,1],[0,0,0],[1,0,1]]
+
+ +

Example 2:

+ +
Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
+Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[0].length
  • +
  • 1 <= m, n <= 200
  • +
  • -231 <= matrix[i][j] <= 231 - 1
  • +
+ +

 

+

Follow up:

+ +
    +
  • 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 diff --git a/final/0074-search-a-2d-matrix.html b/final/0074-search-a-2d-matrix.html new file mode 100644 index 000000000..176870938 --- /dev/null +++ b/final/0074-search-a-2d-matrix.html @@ -0,0 +1,34 @@ +

74. Search a 2D Matrix

Medium


You are given an m x n integer matrix matrix with the following two properties:

+ +
    +
  • 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:

+ +
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
+Output: true
+
+ +

Example 2:

+ +
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • -104 <= matrix[i][j], target <= 104
  • +
+
\ No newline at end of file diff --git a/final/0075-sort-colors.html b/final/0075-sort-colors.html new file mode 100644 index 000000000..7ea19a67c --- /dev/null +++ b/final/0075-sort-colors.html @@ -0,0 +1,31 @@ +

75. Sort Colors

Medium


Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

+ +

We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

+ +

You must solve this problem without using the library's sort function.

+ +

 

+

Example 1:

+ +
Input: nums = [2,0,2,1,1,0]
+Output: [0,0,1,1,2,2]
+
+ +

Example 2:

+ +
Input: nums = [2,0,1]
+Output: [0,1,2]
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 300
  • +
  • nums[i] is either 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 diff --git a/0076-minimum-window-substring/README.md b/final/0076-minimum-window-substring.html similarity index 100% rename from 0076-minimum-window-substring/README.md rename to final/0076-minimum-window-substring.html diff --git a/final/0077-combinations.html b/final/0077-combinations.html new file mode 100644 index 000000000..cc6d44a0c --- /dev/null +++ b/final/0077-combinations.html @@ -0,0 +1,28 @@ +

77. Combinations

Medium


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.

+ +

 

+

Example 1:

+ +
Input: n = 4, k = 2
+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]]
+Explanation: There is 1 choose 1 = 1 total combination.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 20
  • +
  • 1 <= k <= n
  • +
+
\ No newline at end of file diff --git a/final/0078-subsets.html b/final/0078-subsets.html new file mode 100644 index 000000000..226b26bbf --- /dev/null +++ b/final/0078-subsets.html @@ -0,0 +1,26 @@ +

78. Subsets

Medium


Given an integer array nums of unique elements, return all possible subsets (the power set).

+ +

The solution set must not contain duplicate subsets. Return the solution in any order.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3]
+Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
+
+ +

Example 2:

+ +
Input: nums = [0]
+Output: [[],[0]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 10
  • +
  • -10 <= nums[i] <= 10
  • +
  • All the numbers of nums are unique.
  • +
+
\ No newline at end of file diff --git a/final/0079-word-search.html b/final/0079-word-search.html new file mode 100644 index 000000000..1480ac27c --- /dev/null +++ b/final/0079-word-search.html @@ -0,0 +1,37 @@ +

79. Word Search

Medium


Given an m x n grid of characters board and a string word, return true if word exists in the grid.

+ +

The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.

+ +

 

+

Example 1:

+ +
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
+Output: true
+
+ +

Example 2:

+ +
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
+Output: true
+
+ +

Example 3:

+ +
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • m == board.length
  • +
  • n = board[i].length
  • +
  • 1 <= m, n <= 6
  • +
  • 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 diff --git a/final/0081-search-in-rotated-sorted-array-ii.html b/final/0081-search-in-rotated-sorted-array-ii.html new file mode 100644 index 000000000..f0a17f29c --- /dev/null +++ b/final/0081-search-in-rotated-sorted-array-ii.html @@ -0,0 +1,29 @@ +

81. Search in Rotated Sorted Array II

Medium


There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).

+ +

Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= 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,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].

+ +

Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.

+ +

You must decrease the overall operation steps as much as possible.

+ +

 

+

Example 1:

+
Input: nums = [2,5,6,0,0,1,2], target = 0
+Output: true
+

Example 2:

+
Input: nums = [2,5,6,0,0,1,2], target = 3
+Output: false
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5000
  • +
  • -104 <= nums[i] <= 104
  • +
  • nums is guaranteed to be rotated at some pivot.
  • +
  • -104 <= target <= 104
  • +
+ +

 

+

Follow up: This problem is similar to Search in Rotated Sorted Array, but nums may contain duplicates. Would this affect the runtime complexity? How and why?

+
\ No newline at end of file diff --git a/0083-remove-duplicates-from-sorted-list/README.md b/final/0083-remove-duplicates-from-sorted-list.html similarity index 100% rename from 0083-remove-duplicates-from-sorted-list/README.md rename to final/0083-remove-duplicates-from-sorted-list.html diff --git a/0084-largest-rectangle-in-histogram/README.md b/final/0084-largest-rectangle-in-histogram.html similarity index 100% rename from 0084-largest-rectangle-in-histogram/README.md rename to final/0084-largest-rectangle-in-histogram.html diff --git a/0085-maximal-rectangle/README.md b/final/0085-maximal-rectangle.html similarity index 100% rename from 0085-maximal-rectangle/README.md rename to final/0085-maximal-rectangle.html diff --git a/final/0086-partition-list.html b/final/0086-partition-list.html new file mode 100644 index 000000000..372a542c5 --- /dev/null +++ b/final/0086-partition-list.html @@ -0,0 +1,26 @@ +

86. Partition List

Medium


Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

+ +

You should preserve the original relative order of the nodes in each of the two partitions.

+ +

 

+

Example 1:

+ +
Input: head = [1,4,3,2,5,2], x = 3
+Output: [1,2,2,4,3,5]
+
+ +

Example 2:

+ +
Input: head = [2,1], x = 2
+Output: [1,2]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 200].
  • +
  • -100 <= Node.val <= 100
  • +
  • -200 <= x <= 200
  • +
+
\ No newline at end of file diff --git a/0088-merge-sorted-array/README.md b/final/0088-merge-sorted-array.html similarity index 100% rename from 0088-merge-sorted-array/README.md rename to final/0088-merge-sorted-array.html diff --git a/final/0090-subsets-ii.html b/final/0090-subsets-ii.html new file mode 100644 index 000000000..49bedbe04 --- /dev/null +++ b/final/0090-subsets-ii.html @@ -0,0 +1,20 @@ +

90. Subsets II

Medium


Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

+ +

The solution set must not contain duplicate subsets. Return the solution in any order.

+ +

 

+

Example 1:

+
Input: nums = [1,2,2]
+Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
+

Example 2:

+
Input: nums = [0]
+Output: [[],[0]]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 10
  • +
  • -10 <= nums[i] <= 10
  • +
+
\ No newline at end of file diff --git a/final/0091-decode-ways.html b/final/0091-decode-ways.html new file mode 100644 index 000000000..84e177d9d --- /dev/null +++ b/final/0091-decode-ways.html @@ -0,0 +1,51 @@ +

91. Decode Ways

Medium


A message containing letters from A-Z can be encoded into numbers using the following mapping:

+ +
'A' -> "1"
+'B' -> "2"
+...
+'Z' -> "26"
+
+ +

To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:

+ +
    +
  • "AAJF" with the grouping (1 1 10 6)
  • +
  • "KJF" with the grouping (11 10 6)
  • +
+ +

Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".

+ +

Given a string s containing only digits, return the number of ways to decode it.

+ +

The test cases are generated so that the answer fits in a 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: s = "12"
+Output: 2
+Explanation: "12" could be decoded as "AB" (1 2) or "L" (12).
+
+ +

Example 2:

+ +
Input: s = "226"
+Output: 3
+Explanation: "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
+
+ +

Example 3:

+ +
Input: s = "06"
+Output: 0
+Explanation: "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s contains only digits and may contain leading zero(s).
  • +
+
\ No newline at end of file diff --git a/final/0092-reverse-linked-list-ii.html b/final/0092-reverse-linked-list-ii.html new file mode 100644 index 000000000..8c76add52 --- /dev/null +++ b/final/0092-reverse-linked-list-ii.html @@ -0,0 +1,27 @@ +

92. Reverse Linked List II

Medium


Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5], left = 2, right = 4
+Output: [1,4,3,2,5]
+
+ +

Example 2:

+ +
Input: head = [5], left = 1, right = 1
+Output: [5]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is n.
  • +
  • 1 <= n <= 500
  • +
  • -500 <= Node.val <= 500
  • +
  • 1 <= left <= right <= n
  • +
+ +

 

+Follow up: Could you do it in one pass?
\ No newline at end of file diff --git a/0094-binary-tree-inorder-traversal/README.md b/final/0094-binary-tree-inorder-traversal.html similarity index 100% rename from 0094-binary-tree-inorder-traversal/README.md rename to final/0094-binary-tree-inorder-traversal.html diff --git a/0095-unique-binary-search-trees-ii/README.md b/final/0095-unique-binary-search-trees-ii.html similarity index 100% rename from 0095-unique-binary-search-trees-ii/README.md rename to final/0095-unique-binary-search-trees-ii.html diff --git a/0097-interleaving-string/README.md b/final/0097-interleaving-string.html similarity index 100% rename from 0097-interleaving-string/README.md rename to final/0097-interleaving-string.html diff --git a/final/0098-validate-binary-search-tree.html b/final/0098-validate-binary-search-tree.html new file mode 100644 index 000000000..a5ec6043b --- /dev/null +++ b/final/0098-validate-binary-search-tree.html @@ -0,0 +1,32 @@ +

98. Validate Binary Search Tree

Medium


Given the root of a binary tree, determine if it is a valid binary search tree (BST).

+ +

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.
  • +
  • Both the left and right subtrees must also be binary search trees.
  • +
+ +

 

+

Example 1:

+ +
Input: root = [2,1,3]
+Output: true
+
+ +

Example 2:

+ +
Input: root = [5,1,4,null,null,3,6]
+Output: false
+Explanation: The root node's value is 5 but its right child's value is 4.
+
+ +

 

+

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 diff --git a/0100-same-tree/README.md b/final/0100-same-tree.html similarity index 100% rename from 0100-same-tree/README.md rename to final/0100-same-tree.html diff --git a/0101-symmetric-tree/README.md b/final/0101-symmetric-tree.html similarity index 100% rename from 0101-symmetric-tree/README.md rename to final/0101-symmetric-tree.html diff --git a/final/0102-binary-tree-level-order-traversal.html b/final/0102-binary-tree-level-order-traversal.html new file mode 100644 index 000000000..dc78860fc --- /dev/null +++ b/final/0102-binary-tree-level-order-traversal.html @@ -0,0 +1,29 @@ +

102. Binary Tree Level Order Traversal

Medium


Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: [[3],[9,20],[15,7]]
+
+ +

Example 2:

+ +
Input: root = [1]
+Output: [[1]]
+
+ +

Example 3:

+ +
Input: root = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 2000].
  • +
  • -1000 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0104-maximum-depth-of-binary-tree/README.md b/final/0104-maximum-depth-of-binary-tree.html similarity index 100% rename from 0104-maximum-depth-of-binary-tree/README.md rename to final/0104-maximum-depth-of-binary-tree.html diff --git a/final/0105-construct-binary-tree-from-preorder-and-inorder-traversal.html b/final/0105-construct-binary-tree-from-preorder-and-inorder-traversal.html new file mode 100644 index 000000000..ad7d1dc29 --- /dev/null +++ b/final/0105-construct-binary-tree-from-preorder-and-inorder-traversal.html @@ -0,0 +1,28 @@ +

105. Construct Binary Tree from Preorder and Inorder Traversal

Medium


Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.

+ +

 

+

Example 1:

+ +
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
+Output: [3,9,20,null,null,15,7]
+
+ +

Example 2:

+ +
Input: preorder = [-1], inorder = [-1]
+Output: [-1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= preorder.length <= 3000
  • +
  • inorder.length == preorder.length
  • +
  • -3000 <= preorder[i], inorder[i] <= 3000
  • +
  • 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 diff --git a/0110-balanced-binary-tree/README.md b/final/0110-balanced-binary-tree.html similarity index 100% rename from 0110-balanced-binary-tree/README.md rename to final/0110-balanced-binary-tree.html diff --git a/0112-path-sum/README.md b/final/0112-path-sum.html similarity index 100% rename from 0112-path-sum/README.md rename to final/0112-path-sum.html diff --git a/0116-populating-next-right-pointers-in-each-node/README.md b/final/0116-populating-next-right-pointers-in-each-node.html similarity index 100% rename from 0116-populating-next-right-pointers-in-each-node/README.md rename to final/0116-populating-next-right-pointers-in-each-node.html diff --git a/0118-pascals-triangle/README.md b/final/0118-pascals-triangle.html similarity index 100% rename from 0118-pascals-triangle/README.md rename to final/0118-pascals-triangle.html diff --git a/0119-pascals-triangle-ii/README.md b/final/0119-pascals-triangle-ii.html similarity index 100% rename from 0119-pascals-triangle-ii/README.md rename to final/0119-pascals-triangle-ii.html diff --git a/final/0120-triangle.html b/final/0120-triangle.html new file mode 100644 index 000000000..e35f27bc6 --- /dev/null +++ b/final/0120-triangle.html @@ -0,0 +1,35 @@ +

120. Triangle

Medium


Given a triangle array, return the minimum path sum from top to bottom.

+ +

For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.

+ +

 

+

Example 1:

+ +
Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
+Output: 11
+Explanation: The triangle looks like:
+   2
+  3 4
+ 6 5 7
+4 1 8 3
+The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
+
+ +

Example 2:

+ +
Input: triangle = [[-10]]
+Output: -10
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= triangle.length <= 200
  • +
  • triangle[0].length == 1
  • +
  • triangle[i].length == triangle[i - 1].length + 1
  • +
  • -104 <= triangle[i][j] <= 104
  • +
+ +

 

+Follow up: Could you do this using only O(n) extra space, where n is the total number of rows in the triangle?
\ No newline at end of file diff --git a/0121-best-time-to-buy-and-sell-stock/README.md b/final/0121-best-time-to-buy-and-sell-stock.html similarity index 100% rename from 0121-best-time-to-buy-and-sell-stock/README.md rename to final/0121-best-time-to-buy-and-sell-stock.html diff --git a/0125-valid-palindrome/README.md b/final/0125-valid-palindrome.html similarity index 100% rename from 0125-valid-palindrome/README.md rename to final/0125-valid-palindrome.html diff --git a/0127-word-ladder/README.md b/final/0127-word-ladder.html similarity index 100% rename from 0127-word-ladder/README.md rename to final/0127-word-ladder.html diff --git a/final/0128-longest-consecutive-sequence.html b/final/0128-longest-consecutive-sequence.html new file mode 100644 index 000000000..2938c99d7 --- /dev/null +++ b/final/0128-longest-consecutive-sequence.html @@ -0,0 +1,26 @@ +

128. Longest Consecutive Sequence

Medium


Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

+ +

You must write an algorithm that runs in O(n) time.

+ +

 

+

Example 1:

+ +
Input: nums = [100,4,200,1,3,2]
+Output: 4
+Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
+
+ +

Example 2:

+ +
Input: nums = [0,3,7,2,5,8,4,6,0,1]
+Output: 9
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/final/0129-sum-root-to-leaf-numbers.html b/final/0129-sum-root-to-leaf-numbers.html new file mode 100644 index 000000000..abefe7fbe --- /dev/null +++ b/final/0129-sum-root-to-leaf-numbers.html @@ -0,0 +1,43 @@ +

129. Sum Root to Leaf Numbers

Medium


You are given the root of a binary tree containing digits from 0 to 9 only.

+ +

Each root-to-leaf path in the tree represents a number.

+ +
    +
  • For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.
  • +
+ +

Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer.

+ +

A leaf node is a node with no children.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3]
+Output: 25
+Explanation:
+The root-to-leaf path 1->2 represents the number 12.
+The root-to-leaf path 1->3 represents the number 13.
+Therefore, sum = 12 + 13 = 25.
+
+ +

Example 2:

+ +
Input: root = [4,9,0,5,1]
+Output: 1026
+Explanation:
+The root-to-leaf path 4->9->5 represents the number 495.
+The root-to-leaf path 4->9->1 represents the number 491.
+The root-to-leaf path 4->0 represents the number 40.
+Therefore, sum = 495 + 491 + 40 = 1026.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 1000].
  • +
  • 0 <= Node.val <= 9
  • +
  • The depth of the tree will not exceed 10.
  • +
+
\ No newline at end of file diff --git a/final/0131-palindrome-partitioning.html b/final/0131-palindrome-partitioning.html new file mode 100644 index 000000000..934742248 --- /dev/null +++ b/final/0131-palindrome-partitioning.html @@ -0,0 +1,18 @@ +

131. Palindrome Partitioning

Medium


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:

+
Input: s = "aab"
+Output: [["a","a","b"],["aa","b"]]
+

Example 2:

+
Input: s = "a"
+Output: [["a"]]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 16
  • +
  • s contains only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/final/0133-clone-graph.html b/final/0133-clone-graph.html new file mode 100644 index 000000000..8bfc46895 --- /dev/null +++ b/final/0133-clone-graph.html @@ -0,0 +1,59 @@ +

133. Clone Graph

Medium


Given a reference of a node in a connected undirected graph.

+ +

Return a deep copy (clone) of the graph.

+ +

Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors.

+ +
class Node {
+    public int val;
+    public List<Node> neighbors;
+}
+
+ +

 

+ +

Test case format:

+ +

For simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with val == 1, the second node with val == 2, and so on. The graph is represented in the test case using an adjacency list.

+ +

An adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.

+ +

The given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.

+ +

 

+

Example 1:

+ +
Input: adjList = [[2,4],[1,3],[2,4],[1,3]]
+Output: [[2,4],[1,3],[2,4],[1,3]]
+Explanation: There are 4 nodes in the graph.
+1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).
+2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).
+3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).
+4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).
+
+ +

Example 2:

+ +
Input: adjList = [[]]
+Output: [[]]
+Explanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors.
+
+ +

Example 3:

+ +
Input: adjList = []
+Output: []
+Explanation: This an empty graph, it does not have any nodes.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the graph is in the range [0, 100].
  • +
  • 1 <= Node.val <= 100
  • +
  • Node.val is unique for each node.
  • +
  • There are no repeated edges and no self-loops in the graph.
  • +
  • The Graph is connected and all nodes can be visited starting from the given node.
  • +
+
\ No newline at end of file diff --git a/0135-candy/README.md b/final/0135-candy.html similarity index 100% rename from 0135-candy/README.md rename to final/0135-candy.html diff --git a/0136-single-number/README.md b/final/0136-single-number.html similarity index 100% rename from 0136-single-number/README.md rename to final/0136-single-number.html diff --git a/final/0137-single-number-ii.html b/final/0137-single-number-ii.html new file mode 100644 index 000000000..72a3e4fe5 --- /dev/null +++ b/final/0137-single-number-ii.html @@ -0,0 +1,21 @@ +

137. Single Number II

Medium


Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.

+ +

You must implement a solution with a linear runtime complexity and use only constant extra space.

+ +

 

+

Example 1:

+
Input: nums = [2,2,3,2]
+Output: 3
+

Example 2:

+
Input: nums = [0,1,0,1,0,1,99]
+Output: 99
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • Each element in nums appears exactly three times except for one element which appears once.
  • +
+
\ No newline at end of file diff --git a/final/0138-copy-list-with-random-pointer.html b/final/0138-copy-list-with-random-pointer.html new file mode 100644 index 000000000..687b9dabd --- /dev/null +++ b/final/0138-copy-list-with-random-pointer.html @@ -0,0 +1,47 @@ +

138. Copy List with Random Pointer

Medium


A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null.

+ +

Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. None of the pointers in the new list should point to nodes in the original list.

+ +

For example, if there are two nodes X and Y in the original list, where X.random --> Y, then for the corresponding two nodes x and y in the copied list, x.random --> y.

+ +

Return the head of the copied linked list.

+ +

The linked list is represented in the input/output as a list of n nodes. Each node is represented as a pair of [val, random_index] where:

+ +
    +
  • val: an integer representing Node.val
  • +
  • random_index: the index of the node (range from 0 to n-1) that the random pointer points to, or null if it does not point to any node.
  • +
+ +

Your code will only be given the head of the original linked list.

+ +

 

+

Example 1:

+ +
Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
+Output: [[7,null],[13,0],[11,4],[10,2],[1,0]]
+
+ +

Example 2:

+ +
Input: head = [[1,1],[2,1]]
+Output: [[1,1],[2,1]]
+
+ +

Example 3:

+ +

+ +
Input: head = [[3,null],[3,0],[3,null]]
+Output: [[3,null],[3,0],[3,null]]
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= n <= 1000
  • +
  • -104 <= Node.val <= 104
  • +
  • Node.random is null or is pointing to some node in the linked list.
  • +
+
\ No newline at end of file diff --git a/final/0139-word-break.html b/final/0139-word-break.html new file mode 100644 index 000000000..14dbb3f6e --- /dev/null +++ b/final/0139-word-break.html @@ -0,0 +1,37 @@ +

139. Word Break

Medium


Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

+ +

Note that the same word in the dictionary may be reused multiple times in the segmentation.

+ +

 

+

Example 1:

+ +
Input: s = "leetcode", wordDict = ["leet","code"]
+Output: true
+Explanation: Return true because "leetcode" can be segmented as "leet code".
+
+ +

Example 2:

+ +
Input: s = "applepenapple", wordDict = ["apple","pen"]
+Output: true
+Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
+Note that you are allowed to reuse a dictionary word.
+
+ +

Example 3:

+ +
Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 300
  • +
  • 1 <= wordDict.length <= 1000
  • +
  • 1 <= wordDict[i].length <= 20
  • +
  • s and wordDict[i] consist of only lowercase English letters.
  • +
  • All the strings of wordDict are unique.
  • +
+
\ No newline at end of file diff --git a/0140-word-break-ii/README.md b/final/0140-word-break-ii.html similarity index 100% rename from 0140-word-break-ii/README.md rename to final/0140-word-break-ii.html diff --git a/0141-linked-list-cycle/README.md b/final/0141-linked-list-cycle.html similarity index 100% rename from 0141-linked-list-cycle/README.md rename to final/0141-linked-list-cycle.html diff --git a/final/0143-reorder-list.html b/final/0143-reorder-list.html new file mode 100644 index 000000000..fa1bf802a --- /dev/null +++ b/final/0143-reorder-list.html @@ -0,0 +1,33 @@ +

143. Reorder List

Medium


You are given the head of a singly linked-list. The list can be represented as:

+ +
L0 → L1 → … → Ln - 1 → Ln
+
+ +

Reorder the list to be on the following form:

+ +
L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …
+
+ +

You may not modify the values in the list's nodes. Only nodes themselves may be changed.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4]
+Output: [1,4,2,3]
+
+ +

Example 2:

+ +
Input: head = [1,2,3,4,5]
+Output: [1,5,2,4,3]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 5 * 104].
  • +
  • 1 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0144-binary-tree-preorder-traversal/README.md b/final/0144-binary-tree-preorder-traversal.html similarity index 100% rename from 0144-binary-tree-preorder-traversal/README.md rename to final/0144-binary-tree-preorder-traversal.html diff --git a/0145-binary-tree-postorder-traversal/README.md b/final/0145-binary-tree-postorder-traversal.html similarity index 100% rename from 0145-binary-tree-postorder-traversal/README.md rename to final/0145-binary-tree-postorder-traversal.html diff --git a/final/0146-lru-cache.html b/final/0146-lru-cache.html new file mode 100644 index 000000000..ae892bc08 --- /dev/null +++ b/final/0146-lru-cache.html @@ -0,0 +1,44 @@ +

146. LRU Cache

Medium


Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

+ +

Implement the LRUCache class:

+ +
    +
  • LRUCache(int capacity) Initialize the LRU cache with positive size capacity.
  • +
  • int get(int key) Return the value of the key if the key exists, otherwise return -1.
  • +
  • void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.
  • +
+ +

The functions get and put must each run in O(1) average time complexity.

+ +

 

+

Example 1:

+ +
Input
+["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
+Output
+[null, null, null, 1, null, -1, null, -1, 3, 4]
+
+Explanation
+LRUCache lRUCache = new LRUCache(2);
+lRUCache.put(1, 1); // cache is {1=1}
+lRUCache.put(2, 2); // cache is {1=1, 2=2}
+lRUCache.get(1);    // return 1
+lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}
+lRUCache.get(2);    // returns -1 (not found)
+lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}
+lRUCache.get(1);    // return -1 (not found)
+lRUCache.get(3);    // return 3
+lRUCache.get(4);    // return 4
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= capacity <= 3000
  • +
  • 0 <= key <= 104
  • +
  • 0 <= value <= 105
  • +
  • At most 2 * 105 calls will be made to get and put.
  • +
+
\ No newline at end of file diff --git a/final/0148-sort-list.html b/final/0148-sort-list.html new file mode 100644 index 000000000..e56bc9c9f --- /dev/null +++ b/final/0148-sort-list.html @@ -0,0 +1,32 @@ +

148. Sort List

Medium


Given the head of a linked list, return the list after sorting it in ascending order.

+ +

 

+

Example 1:

+ +
Input: head = [4,2,1,3]
+Output: [1,2,3,4]
+
+ +

Example 2:

+ +
Input: head = [-1,5,3,4,0]
+Output: [-1,0,3,4,5]
+
+ +

Example 3:

+ +
Input: head = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 5 * 104].
  • +
  • -105 <= Node.val <= 105
  • +
+ +

 

+

Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?

+
\ No newline at end of file diff --git a/final/0150-evaluate-reverse-polish-notation.html b/final/0150-evaluate-reverse-polish-notation.html new file mode 100644 index 000000000..4a26fcc43 --- /dev/null +++ b/final/0150-evaluate-reverse-polish-notation.html @@ -0,0 +1,51 @@ +

150. Evaluate Reverse Polish Notation

Medium


You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.

+ +

Evaluate the expression. Return an integer that represents the value of the expression.

+ +

Note that:

+ +
    +
  • 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:

+ +
Input: tokens = ["2","1","+","3","*"]
+Output: 9
+Explanation: ((2 + 1) * 3) = 9
+
+ +

Example 2:

+ +
Input: tokens = ["4","13","5","/","+"]
+Output: 6
+Explanation: (4 + (13 / 5)) = 6
+
+ +

Example 3:

+ +
Input: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
+Output: 22
+Explanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
+= ((10 * (6 / (12 * -11))) + 17) + 5
+= ((10 * (6 / -132)) + 17) + 5
+= ((10 * 0) + 17) + 5
+= (0 + 17) + 5
+= 17 + 5
+= 22
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= tokens.length <= 104
  • +
  • tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].
  • +
+
\ No newline at end of file diff --git a/final/0153-find-minimum-in-rotated-sorted-array.html b/final/0153-find-minimum-in-rotated-sorted-array.html new file mode 100644 index 000000000..ddea742eb --- /dev/null +++ b/final/0153-find-minimum-in-rotated-sorted-array.html @@ -0,0 +1,46 @@ +

153. Find Minimum in Rotated Sorted Array

Medium


Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:

+ +
    +
  • [4,5,6,7,0,1,2] if it was rotated 4 times.
  • +
  • [0,1,2,4,5,6,7] if it was rotated 7 times.
  • +
+ +

Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

+ +

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.

+ +

 

+

Example 1:

+ +
Input: nums = [3,4,5,1,2]
+Output: 1
+Explanation: The original array was [1,2,3,4,5] rotated 3 times.
+
+ +

Example 2:

+ +
Input: nums = [4,5,6,7,0,1,2]
+Output: 0
+Explanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.
+
+ +

Example 3:

+ +
Input: nums = [11,13,15,17]
+Output: 11
+Explanation: The original array was [11,13,15,17] and it was rotated 4 times. 
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 5000
  • +
  • -5000 <= nums[i] <= 5000
  • +
  • All the integers of nums are unique.
  • +
  • nums is sorted and rotated between 1 and n times.
  • +
+
\ No newline at end of file diff --git a/final/0155-min-stack.html b/final/0155-min-stack.html new file mode 100644 index 000000000..61b1b9a32 --- /dev/null +++ b/final/0155-min-stack.html @@ -0,0 +1,44 @@ +

155. Min Stack

Medium


Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

+ +

Implement the MinStack class:

+ +
    +
  • MinStack() initializes the stack object.
  • +
  • void push(int val) pushes the element val onto the stack.
  • +
  • void pop() removes the element on the top of the stack.
  • +
  • int top() gets the top element of the stack.
  • +
  • int getMin() retrieves the minimum element in the stack.
  • +
+ +

You must implement a solution with O(1) time complexity for each function.

+ +

 

+

Example 1:

+ +
Input
+["MinStack","push","push","push","getMin","pop","top","getMin"]
+[[],[-2],[0],[-3],[],[],[],[]]
+
+Output
+[null,null,null,null,-3,null,0,-2]
+
+Explanation
+MinStack minStack = new MinStack();
+minStack.push(-2);
+minStack.push(0);
+minStack.push(-3);
+minStack.getMin(); // return -3
+minStack.pop();
+minStack.top();    // return 0
+minStack.getMin(); // return -2
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= val <= 231 - 1
  • +
  • Methods pop, top and getMin operations will always be called on non-empty stacks.
  • +
  • At most 3 * 104 calls will be made to push, pop, top, and getMin.
  • +
+
\ No newline at end of file diff --git a/0159-longest-substring-with-at-most-two-distinct-characters/README.md b/final/0159-longest-substring-with-at-most-two-distinct-characters.html similarity index 100% rename from 0159-longest-substring-with-at-most-two-distinct-characters/README.md rename to final/0159-longest-substring-with-at-most-two-distinct-characters.html diff --git a/final/0162-find-peak-element.html b/final/0162-find-peak-element.html new file mode 100644 index 000000000..96c32bd28 --- /dev/null +++ b/final/0162-find-peak-element.html @@ -0,0 +1,30 @@ +

162. Find Peak Element

Medium


A peak element is an element that is strictly greater than its neighbors.

+ +

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] = -∞. 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.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1]
+Output: 2
+Explanation: 3 is a peak element and your function should return the index number 2.
+ +

Example 2:

+ +
Input: nums = [1,2,1,3,5,6,4]
+Output: 5
+Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • nums[i] != nums[i + 1] for all valid i.
  • +
+
\ No newline at end of file diff --git a/final/0165-compare-version-numbers.html b/final/0165-compare-version-numbers.html new file mode 100644 index 000000000..e69de29bb diff --git a/final/0167-two-sum-ii-input-array-is-sorted.html b/final/0167-two-sum-ii-input-array-is-sorted.html new file mode 100644 index 000000000..53383a197 --- /dev/null +++ b/final/0167-two-sum-ii-input-array-is-sorted.html @@ -0,0 +1,41 @@ +

167. Two Sum II - Input Array Is Sorted

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.

+ +

Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2.

+ +

The tests are generated such that there is exactly one solution. You may not use the same element twice.

+ +

Your solution must use only constant extra space.

+ +

 

+

Example 1:

+ +
Input: numbers = [2,7,11,15], target = 9
+Output: [1,2]
+Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].
+
+ +

Example 2:

+ +
Input: numbers = [2,3,4], target = 6
+Output: [1,3]
+Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3].
+
+ +

Example 3:

+ +
Input: numbers = [-1,0], target = -1
+Output: [1,2]
+Explanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2].
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= numbers.length <= 3 * 104
  • +
  • -1000 <= numbers[i] <= 1000
  • +
  • numbers is sorted in non-decreasing order.
  • +
  • -1000 <= target <= 1000
  • +
  • The tests are generated such that there is exactly one solution.
  • +
+
\ No newline at end of file diff --git a/0168-excel-sheet-column-title/README.md b/final/0168-excel-sheet-column-title.html similarity index 100% rename from 0168-excel-sheet-column-title/README.md rename to final/0168-excel-sheet-column-title.html diff --git a/0169-majority-element/README.md b/final/0169-majority-element.html similarity index 100% rename from 0169-majority-element/README.md rename to final/0169-majority-element.html diff --git a/final/0189-rotate-array.html b/final/0189-rotate-array.html new file mode 100644 index 000000000..0f1538df6 --- /dev/null +++ b/final/0189-rotate-array.html @@ -0,0 +1,39 @@ +

189. Rotate Array

Medium


Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4,5,6,7], k = 3
+Output: [5,6,7,1,2,3,4]
+Explanation:
+rotate 1 steps to the right: [7,1,2,3,4,5,6]
+rotate 2 steps to the right: [6,7,1,2,3,4,5]
+rotate 3 steps to the right: [5,6,7,1,2,3,4]
+
+ +

Example 2:

+ +
Input: nums = [-1,-100,3,99], k = 2
+Output: [3,99,-1,-100]
+Explanation: 
+rotate 1 steps to the right: [99,-1,-100,3]
+rotate 2 steps to the right: [3,99,-1,-100]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • 0 <= k <= 105
  • +
+ +

 

+

Follow up:

+ +
    +
  • Try to come up with as many solutions as you can. There are at least three different ways to solve this problem.
  • +
  • Could you do it in-place with O(1) extra space?
  • +
+
\ No newline at end of file diff --git a/0190-reverse-bits/README.md b/final/0190-reverse-bits.html similarity index 100% rename from 0190-reverse-bits/README.md rename to final/0190-reverse-bits.html diff --git a/0191-number-of-1-bits/README.md b/final/0191-number-of-1-bits.html similarity index 100% rename from 0191-number-of-1-bits/README.md rename to final/0191-number-of-1-bits.html diff --git a/0197-rising-temperature/README.md b/final/0197-rising-temperature.html similarity index 100% rename from 0197-rising-temperature/README.md rename to final/0197-rising-temperature.html diff --git a/final/0198-house-robber.html b/final/0198-house-robber.html new file mode 100644 index 000000000..4784d722b --- /dev/null +++ b/final/0198-house-robber.html @@ -0,0 +1,29 @@ +

198. House Robber

Medium


You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

+ +

Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1]
+Output: 4
+Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
+Total amount you can rob = 1 + 3 = 4.
+
+ +

Example 2:

+ +
Input: nums = [2,7,9,3,1]
+Output: 12
+Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
+Total amount you can rob = 2 + 9 + 1 = 12.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 400
  • +
+
\ No newline at end of file diff --git a/final/0199-binary-tree-right-side-view.html b/final/0199-binary-tree-right-side-view.html new file mode 100644 index 000000000..e69de29bb diff --git a/final/0200-number-of-islands.html b/final/0200-number-of-islands.html new file mode 100644 index 000000000..f0398d0fc --- /dev/null +++ b/final/0200-number-of-islands.html @@ -0,0 +1,37 @@ +

200. Number of Islands

Medium


Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

+ +

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

+ +

 

+

Example 1:

+ +
Input: grid = [
+  ["1","1","1","1","0"],
+  ["1","1","0","1","0"],
+  ["1","1","0","0","0"],
+  ["0","0","0","0","0"]
+]
+Output: 1
+
+ +

Example 2:

+ +
Input: grid = [
+  ["1","1","0","0","0"],
+  ["1","1","0","0","0"],
+  ["0","0","1","0","0"],
+  ["0","0","0","1","1"]
+]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 300
  • +
  • grid[i][j] is '0' or '1'.
  • +
+
\ No newline at end of file diff --git a/0201-bitwise-and-of-numbers-range/README.md b/final/0201-bitwise-and-of-numbers-range.html similarity index 100% rename from 0201-bitwise-and-of-numbers-range/README.md rename to final/0201-bitwise-and-of-numbers-range.html diff --git a/0202-happy-number/README.md b/final/0202-happy-number.html similarity index 100% rename from 0202-happy-number/README.md rename to final/0202-happy-number.html diff --git a/0203-remove-linked-list-elements/README.md b/final/0203-remove-linked-list-elements.html similarity index 100% rename from 0203-remove-linked-list-elements/README.md rename to final/0203-remove-linked-list-elements.html diff --git a/0205-isomorphic-strings/README.md b/final/0205-isomorphic-strings.html similarity index 100% rename from 0205-isomorphic-strings/README.md rename to final/0205-isomorphic-strings.html diff --git a/0206-reverse-linked-list/README.md b/final/0206-reverse-linked-list.html similarity index 100% rename from 0206-reverse-linked-list/README.md rename to final/0206-reverse-linked-list.html diff --git a/final/0207-course-schedule.html b/final/0207-course-schedule.html new file mode 100644 index 000000000..c9f7b97e2 --- /dev/null +++ b/final/0207-course-schedule.html @@ -0,0 +1,36 @@ +

207. Course Schedule

Medium


There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

+ +
    +
  • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
  • +
+ +

Return true if you can finish all courses. Otherwise, return false.

+ +

 

+

Example 1:

+ +
Input: numCourses = 2, prerequisites = [[1,0]]
+Output: true
+Explanation: There are a total of 2 courses to take. 
+To take course 1 you should have finished course 0. So it is possible.
+
+ +

Example 2:

+ +
Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
+Output: false
+Explanation: There are a total of 2 courses to take. 
+To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= numCourses <= 2000
  • +
  • 0 <= prerequisites.length <= 5000
  • +
  • prerequisites[i].length == 2
  • +
  • 0 <= ai, bi < numCourses
  • +
  • All the pairs prerequisites[i] are unique.
  • +
+
\ No newline at end of file diff --git a/final/0208-implement-trie-prefix-tree.html b/final/0208-implement-trie-prefix-tree.html new file mode 100644 index 000000000..4e589427c --- /dev/null +++ b/final/0208-implement-trie-prefix-tree.html @@ -0,0 +1,39 @@ +

208. Implement Trie (Prefix Tree)

Medium


A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

+ +

Implement the Trie class:

+ +
    +
  • Trie() Initializes the trie object.
  • +
  • void insert(String word) Inserts the string word into the trie.
  • +
  • boolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.
  • +
  • boolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.
  • +
+ +

 

+

Example 1:

+ +
Input
+["Trie", "insert", "search", "search", "startsWith", "insert", "search"]
+[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]
+Output
+[null, null, true, false, true, null, true]
+
+Explanation
+Trie trie = new Trie();
+trie.insert("apple");
+trie.search("apple");   // return True
+trie.search("app");     // return False
+trie.startsWith("app"); // return True
+trie.insert("app");
+trie.search("app");     // return True
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word.length, prefix.length <= 2000
  • +
  • word and prefix consist only of lowercase English letters.
  • +
  • At most 3 * 104 calls in total will be made to insert, search, and startsWith.
  • +
+
\ No newline at end of file diff --git a/0213-house-robber-ii/README.md b/final/0213-house-robber-ii.html similarity index 100% rename from 0213-house-robber-ii/README.md rename to final/0213-house-robber-ii.html diff --git a/final/0215-kth-largest-element-in-an-array.html b/final/0215-kth-largest-element-in-an-array.html new file mode 100644 index 000000000..1735cc58c --- /dev/null +++ b/final/0215-kth-largest-element-in-an-array.html @@ -0,0 +1,22 @@ +

215. Kth Largest Element in an Array

Medium


Given an integer array nums and an integer k, return the kth largest element in the array.

+ +

Note that it is the kth largest element in the sorted order, not the kth distinct element.

+ +

Can you solve it without sorting?

+ +

 

+

Example 1:

+
Input: nums = [3,2,1,5,6,4], k = 2
+Output: 5
+

Example 2:

+
Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
+Output: 4
+
+

 

+

Constraints:

+ +
    +
  • 1 <= k <= nums.length <= 105
  • +
  • -104 <= nums[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0217-contains-duplicate/README.md b/final/0217-contains-duplicate.html similarity index 100% rename from 0217-contains-duplicate/README.md rename to final/0217-contains-duplicate.html diff --git a/0219-contains-duplicate-ii/README.md b/final/0219-contains-duplicate-ii.html similarity index 100% rename from 0219-contains-duplicate-ii/README.md rename to final/0219-contains-duplicate-ii.html diff --git a/0224-basic-calculator/README.md b/final/0224-basic-calculator.html similarity index 100% rename from 0224-basic-calculator/README.md rename to final/0224-basic-calculator.html diff --git a/0225-implement-stack-using-queues/README.md b/final/0225-implement-stack-using-queues.html similarity index 100% rename from 0225-implement-stack-using-queues/README.md rename to final/0225-implement-stack-using-queues.html diff --git a/0226-invert-binary-tree/README.md b/final/0226-invert-binary-tree.html similarity index 100% rename from 0226-invert-binary-tree/README.md rename to final/0226-invert-binary-tree.html diff --git a/final/0229-majority-element-ii.html b/final/0229-majority-element-ii.html new file mode 100644 index 000000000..a3fbb6f98 --- /dev/null +++ b/final/0229-majority-element-ii.html @@ -0,0 +1,32 @@ +

229. Majority Element II

Medium


Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

+ +

 

+

Example 1:

+ +
Input: nums = [3,2,3]
+Output: [3]
+
+ +

Example 2:

+ +
Input: nums = [1]
+Output: [1]
+
+ +

Example 3:

+ +
Input: nums = [1,2]
+Output: [1,2]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • -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/final/0230-kth-smallest-element-in-a-bst.html b/final/0230-kth-smallest-element-in-a-bst.html new file mode 100644 index 000000000..ab773284c --- /dev/null +++ b/final/0230-kth-smallest-element-in-a-bst.html @@ -0,0 +1,27 @@ +

230. Kth Smallest Element in a BST

Medium


Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.

+ +

 

+

Example 1:

+ +
Input: root = [3,1,4,null,2], k = 1
+Output: 1
+
+ +

Example 2:

+ +
Input: root = [5,3,6,2,4,null,null,1], k = 3
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is n.
  • +
  • 1 <= k <= n <= 104
  • +
  • 0 <= Node.val <= 104
  • +
+ +

 

+

Follow up: If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?

+
\ No newline at end of file diff --git a/0231-power-of-two/README.md b/final/0231-power-of-two.html similarity index 100% rename from 0231-power-of-two/README.md rename to final/0231-power-of-two.html diff --git a/0232-implement-queue-using-stacks/README.md b/final/0232-implement-queue-using-stacks.html similarity index 100% rename from 0232-implement-queue-using-stacks/README.md rename to final/0232-implement-queue-using-stacks.html diff --git a/0234-palindrome-linked-list/README.md b/final/0234-palindrome-linked-list.html similarity index 100% rename from 0234-palindrome-linked-list/README.md rename to final/0234-palindrome-linked-list.html diff --git a/final/0235-lowest-common-ancestor-of-a-binary-search-tree.html b/final/0235-lowest-common-ancestor-of-a-binary-search-tree.html new file mode 100644 index 000000000..0640fe056 --- /dev/null +++ b/final/0235-lowest-common-ancestor-of-a-binary-search-tree.html @@ -0,0 +1,36 @@ +

235. Lowest Common Ancestor of a Binary Search Tree

Medium


Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.

+ +

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

+ +

 

+

Example 1:

+ +
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
+Output: 6
+Explanation: The LCA of nodes 2 and 8 is 6.
+
+ +

Example 2:

+ +
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
+Output: 2
+Explanation: The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.
+
+ +

Example 3:

+ +
Input: root = [2,1], p = 2, q = 1
+Output: 2
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [2, 105].
  • +
  • -109 <= Node.val <= 109
  • +
  • All Node.val are unique.
  • +
  • p != q
  • +
  • p and q will exist in the BST.
  • +
+
\ No newline at end of file diff --git a/final/0236-lowest-common-ancestor-of-a-binary-tree.html b/final/0236-lowest-common-ancestor-of-a-binary-tree.html new file mode 100644 index 000000000..33fa84b0f --- /dev/null +++ b/final/0236-lowest-common-ancestor-of-a-binary-tree.html @@ -0,0 +1,36 @@ +

236. Lowest Common Ancestor of a Binary Tree

Medium


Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

+ +

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

+ +

 

+

Example 1:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
+Output: 3
+Explanation: The LCA of nodes 5 and 1 is 3.
+
+ +

Example 2:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
+Output: 5
+Explanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.
+
+ +

Example 3:

+ +
Input: root = [1,2], p = 1, q = 2
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [2, 105].
  • +
  • -109 <= Node.val <= 109
  • +
  • All Node.val are unique.
  • +
  • p != q
  • +
  • p and q will exist in the tree.
  • +
+
\ No newline at end of file diff --git a/final/0237-delete-node-in-a-linked-list.html b/final/0237-delete-node-in-a-linked-list.html new file mode 100644 index 000000000..3fc46f111 --- /dev/null +++ b/final/0237-delete-node-in-a-linked-list.html @@ -0,0 +1,48 @@ +

237. Delete Node in a Linked List

Medium


There is a singly-linked list head and we want to delete a node node in it.

+ +

You are given the node to be deleted node. You will not be given access to the first node of head.

+ +

All the values of the linked list are unique, and it is guaranteed that the given node node is not the last node in the linked list.

+ +

Delete the given node. Note that by deleting the node, we do not mean removing it from memory. We mean:

+ +
    +
  • The value of the given node should not exist in the linked list.
  • +
  • The number of nodes in the linked list should decrease by one.
  • +
  • All the values before node should be in the same order.
  • +
  • All the values after node should be in the same order.
  • +
+ +

Custom testing:

+ +
    +
  • For the input, you should provide the entire linked list head and the node to be given node. node should not be the last node of the list and should be an actual node in the list.
  • +
  • We will build the linked list and pass the node to your function.
  • +
  • The output will be the entire list after calling your function.
  • +
+ +

 

+

Example 1:

+ +
Input: head = [4,5,1,9], node = 5
+Output: [4,1,9]
+Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
+
+ +

Example 2:

+ +
Input: head = [4,5,1,9], node = 1
+Output: [4,5,9]
+Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of the nodes in the given list is in the range [2, 1000].
  • +
  • -1000 <= Node.val <= 1000
  • +
  • The value of each node in the list is unique.
  • +
  • The node to be deleted is in the list and is not a tail node.
  • +
+
\ No newline at end of file diff --git a/final/0238-product-of-array-except-self.html b/final/0238-product-of-array-except-self.html new file mode 100644 index 000000000..8251a0f72 --- /dev/null +++ b/final/0238-product-of-array-except-self.html @@ -0,0 +1,26 @@ +

238. Product of Array Except Self

Medium


Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

+ +

The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

+ +

You must write an algorithm that runs in O(n) time and without using the division operation.

+ +

 

+

Example 1:

+
Input: nums = [1,2,3,4]
+Output: [24,12,8,6]
+

Example 2:

+
Input: nums = [-1,1,0,-3,3]
+Output: [0,0,9,0,0]
+
+

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 105
  • +
  • -30 <= nums[i] <= 30
  • +
  • The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
  • +
+ +

 

+

Follow up: Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)

+
\ No newline at end of file diff --git a/0239-sliding-window-maximum/README.md b/final/0239-sliding-window-maximum.html similarity index 100% rename from 0239-sliding-window-maximum/README.md rename to final/0239-sliding-window-maximum.html diff --git a/0242-valid-anagram/README.md b/final/0242-valid-anagram.html similarity index 100% rename from 0242-valid-anagram/README.md rename to final/0242-valid-anagram.html diff --git a/final/0253-meeting-rooms-ii.html b/final/0253-meeting-rooms-ii.html new file mode 100644 index 000000000..2e04a9171 --- /dev/null +++ b/final/0253-meeting-rooms-ii.html @@ -0,0 +1,18 @@ +

253. Meeting Rooms II

Medium


Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

+ +

 

+

Example 1:

+
Input: intervals = [[0,30],[5,10],[15,20]]
+Output: 2
+

Example 2:

+
Input: intervals = [[7,10],[2,4]]
+Output: 1
+
+

 

+

Constraints:

+ +
    +
  • 1 <= intervals.length <= 104
  • +
  • 0 <= starti < endi <= 106
  • +
+
\ No newline at end of file diff --git a/0255-verify-preorder-sequence-in-binary-search-tree/README.md b/final/0255-verify-preorder-sequence-in-binary-search-tree.html similarity index 100% rename from 0255-verify-preorder-sequence-in-binary-search-tree/README.md rename to final/0255-verify-preorder-sequence-in-binary-search-tree.html diff --git a/0256-paint-house/README.md b/final/0256-paint-house.html similarity index 100% rename from 0256-paint-house/README.md rename to final/0256-paint-house.html diff --git a/final/0260-single-number-iii.html b/final/0260-single-number-iii.html new file mode 100644 index 000000000..203cd5d78 --- /dev/null +++ b/final/0260-single-number-iii.html @@ -0,0 +1,33 @@ +

260. Single Number III

Medium


Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.

+ +

You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,1,3,2,5]
+Output: [3,5]
+Explanation:  [5, 3] is also a valid answer.
+
+ +

Example 2:

+ +
Input: nums = [-1,0]
+Output: [-1,0]
+
+ +

Example 3:

+ +
Input: nums = [0,1]
+Output: [1,0]
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 3 * 104
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • Each integer in nums will appear twice, only two integers will appear once.
  • +
+
\ No newline at end of file diff --git a/0263-ugly-number/README.md b/final/0263-ugly-number.html similarity index 100% rename from 0263-ugly-number/README.md rename to final/0263-ugly-number.html diff --git a/final/0264-ugly-number-ii.html b/final/0264-ugly-number-ii.html new file mode 100644 index 000000000..296532e1b --- /dev/null +++ b/final/0264-ugly-number-ii.html @@ -0,0 +1,26 @@ +

264. Ugly Number II

Medium


An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

+ +

Given an integer n, return the nth ugly number.

+ +

 

+

Example 1:

+ +
Input: n = 10
+Output: 12
+Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.
+
+ +

Example 2:

+ +
Input: n = 1
+Output: 1
+Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1690
  • +
+
\ No newline at end of file diff --git a/0268-missing-number/README.md b/final/0268-missing-number.html similarity index 100% rename from 0268-missing-number/README.md rename to final/0268-missing-number.html diff --git a/0271-encode-and-decode-strings/README.md b/final/0271-encode-and-decode-strings.html similarity index 100% rename from 0271-encode-and-decode-strings/README.md rename to final/0271-encode-and-decode-strings.html diff --git a/0273-integer-to-english-words/README.md b/final/0273-integer-to-english-words.html similarity index 100% rename from 0273-integer-to-english-words/README.md rename to final/0273-integer-to-english-words.html diff --git a/0276-paint-fence/README.md b/final/0276-paint-fence.html similarity index 100% rename from 0276-paint-fence/README.md rename to final/0276-paint-fence.html diff --git a/0278-first-bad-version/README.md b/final/0278-first-bad-version.html similarity index 100% rename from 0278-first-bad-version/README.md rename to final/0278-first-bad-version.html diff --git a/final/0279-perfect-squares.html b/final/0279-perfect-squares.html new file mode 100644 index 000000000..cfd0d4337 --- /dev/null +++ b/final/0279-perfect-squares.html @@ -0,0 +1,26 @@ +

279. Perfect Squares

Medium


Given an integer n, return the least number of perfect square numbers that sum to n.

+ +

A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.

+ +

 

+

Example 1:

+ +
Input: n = 12
+Output: 3
+Explanation: 12 = 4 + 4 + 4.
+
+ +

Example 2:

+ +
Input: n = 13
+Output: 2
+Explanation: 13 = 4 + 9.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 104
  • +
+
\ No newline at end of file diff --git a/0283-move-zeroes/README.md b/final/0283-move-zeroes.html similarity index 100% rename from 0283-move-zeroes/README.md rename to final/0283-move-zeroes.html diff --git a/final/0287-find-the-duplicate-number.html b/final/0287-find-the-duplicate-number.html new file mode 100644 index 000000000..63bff0a6a --- /dev/null +++ b/final/0287-find-the-duplicate-number.html @@ -0,0 +1,37 @@ +

287. Find the Duplicate Number

Medium


Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

+ +

There is only one repeated number in nums, return this repeated number.

+ +

You must solve the problem without modifying the array nums and uses only constant extra space.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3,4,2,2]
+Output: 2
+
+ +

Example 2:

+ +
Input: nums = [3,1,3,4,2]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 105
  • +
  • nums.length == n + 1
  • +
  • 1 <= nums[i] <= n
  • +
  • All the integers in nums appear only once except for precisely one integer which appears two or more times.
  • +
+ +

 

+

Follow up:

+ +
    +
  • How can we prove that at least one duplicate number must exist in nums?
  • +
  • Can you solve the problem in linear runtime complexity?
  • +
+
\ No newline at end of file diff --git a/0290-word-pattern/README.md b/final/0290-word-pattern.html similarity index 100% rename from 0290-word-pattern/README.md rename to final/0290-word-pattern.html diff --git a/0291-word-pattern-ii/README.md b/final/0291-word-pattern-ii.html similarity index 100% rename from 0291-word-pattern-ii/README.md rename to final/0291-word-pattern-ii.html diff --git a/0293-flip-game/README.md b/final/0293-flip-game.html similarity index 100% rename from 0293-flip-game/README.md rename to final/0293-flip-game.html diff --git a/0295-find-median-from-data-stream/README.md b/final/0295-find-median-from-data-stream.html similarity index 100% rename from 0295-find-median-from-data-stream/README.md rename to final/0295-find-median-from-data-stream.html diff --git a/0296-best-meeting-point/README.md b/final/0296-best-meeting-point.html similarity index 100% rename from 0296-best-meeting-point/README.md rename to final/0296-best-meeting-point.html diff --git a/0297-serialize-and-deserialize-binary-tree/README.md b/final/0297-serialize-and-deserialize-binary-tree.html similarity index 100% rename from 0297-serialize-and-deserialize-binary-tree/README.md rename to final/0297-serialize-and-deserialize-binary-tree.html diff --git a/final/0300-longest-increasing-subsequence.html b/final/0300-longest-increasing-subsequence.html new file mode 100644 index 000000000..74241c8e8 --- /dev/null +++ b/final/0300-longest-increasing-subsequence.html @@ -0,0 +1,33 @@ +

300. Longest Increasing Subsequence

Medium


Given an integer array nums, return the length of the longest strictly increasing subsequence.

+ +

 

+

Example 1:

+ +
Input: nums = [10,9,2,5,3,7,101,18]
+Output: 4
+Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
+
+ +

Example 2:

+ +
Input: nums = [0,1,0,3,2,3]
+Output: 4
+
+ +

Example 3:

+ +
Input: nums = [7,7,7,7,7,7,7]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 2500
  • +
  • -104 <= nums[i] <= 104
  • +
+ +

 

+

Follow up: Can you come up with an algorithm that runs in O(n log(n)) time complexity?

+
\ No newline at end of file diff --git a/0305-number-of-islands-ii/README.md b/final/0305-number-of-islands-ii.html similarity index 100% rename from 0305-number-of-islands-ii/README.md rename to final/0305-number-of-islands-ii.html diff --git a/final/0310-minimum-height-trees.html b/final/0310-minimum-height-trees.html new file mode 100644 index 000000000..de5a228ad --- /dev/null +++ b/final/0310-minimum-height-trees.html @@ -0,0 +1,34 @@ +

310. Minimum Height Trees

Medium


A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.

+ +

Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree as the root. When you select a node x as the root, the result tree has height h. Among all possible rooted trees, those with minimum height (i.e. min(h))  are called minimum height trees (MHTs).

+ +

Return a list of all MHTs' root labels. You can return the answer in any order.

+ +

The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf.

+ +

 

+

Example 1:

+ +
Input: n = 4, edges = [[1,0],[1,2],[1,3]]
+Output: [1]
+Explanation: As shown, the height of the tree is 1 when the root is the node with label 1 which is the only MHT.
+
+ +

Example 2:

+ +
Input: n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]
+Output: [3,4]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 2 * 104
  • +
  • edges.length == n - 1
  • +
  • 0 <= ai, bi < n
  • +
  • ai != bi
  • +
  • All the pairs (ai, bi) are distinct.
  • +
  • The given input is guaranteed to be a tree and there will be no repeated edges.
  • +
+
\ No newline at end of file diff --git a/final/0316-remove-duplicate-letters.html b/final/0316-remove-duplicate-letters.html new file mode 100644 index 000000000..22848ad23 --- /dev/null +++ b/final/0316-remove-duplicate-letters.html @@ -0,0 +1,26 @@ +

316. Remove Duplicate Letters

Medium


Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.

+ +

 

+

Example 1:

+ +
Input: s = "bcabc"
+Output: "abc"
+
+ +

Example 2:

+ +
Input: s = "cbacdcbc"
+Output: "acdb"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 104
  • +
  • s consists of lowercase English letters.
  • +
+ +

 

+

Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/

+
\ No newline at end of file diff --git a/0320-generalized-abbreviation/README.md b/final/0320-generalized-abbreviation.html similarity index 100% rename from 0320-generalized-abbreviation/README.md rename to final/0320-generalized-abbreviation.html diff --git a/final/0322-coin-change.html b/final/0322-coin-change.html new file mode 100644 index 000000000..6aa78759e --- /dev/null +++ b/final/0322-coin-change.html @@ -0,0 +1,35 @@ +

322. Coin Change

Medium


You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

+ +

Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

+ +

You may assume that you have an infinite number of each kind of coin.

+ +

 

+

Example 1:

+ +
Input: coins = [1,2,5], amount = 11
+Output: 3
+Explanation: 11 = 5 + 5 + 1
+
+ +

Example 2:

+ +
Input: coins = [2], amount = 3
+Output: -1
+
+ +

Example 3:

+ +
Input: coins = [1], amount = 0
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= coins.length <= 12
  • +
  • 1 <= coins[i] <= 231 - 1
  • +
  • 0 <= amount <= 104
  • +
+
\ No newline at end of file diff --git a/0330-patching-array/README.md b/final/0330-patching-array.html similarity index 100% rename from 0330-patching-array/README.md rename to final/0330-patching-array.html diff --git a/0332-reconstruct-itinerary/README.md b/final/0332-reconstruct-itinerary.html similarity index 100% rename from 0332-reconstruct-itinerary/README.md rename to final/0332-reconstruct-itinerary.html diff --git a/0338-counting-bits/README.md b/final/0338-counting-bits.html similarity index 100% rename from 0338-counting-bits/README.md rename to final/0338-counting-bits.html diff --git a/final/0340-longest-substring-with-at-most-k-distinct-characters.html b/final/0340-longest-substring-with-at-most-k-distinct-characters.html new file mode 100644 index 000000000..3d59f9315 --- /dev/null +++ b/final/0340-longest-substring-with-at-most-k-distinct-characters.html @@ -0,0 +1,24 @@ +

340. Longest Substring with At Most K Distinct Characters

Medium


Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.

+ +

 

+

Example 1:

+ +
Input: s = "eceba", k = 2
+Output: 3
+Explanation: The substring is "ece" with length 3.
+ +

Example 2:

+ +
Input: s = "aa", k = 1
+Output: 2
+Explanation: The substring is "aa" with length 2.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 5 * 104
  • +
  • 0 <= k <= 50
  • +
+
\ No newline at end of file diff --git a/0341-flatten-nested-list-iterator/README.md b/final/0341-flatten-nested-list-iterator.html similarity index 100% rename from 0341-flatten-nested-list-iterator/README.md rename to final/0341-flatten-nested-list-iterator.html diff --git a/0342-power-of-four/README.md b/final/0342-power-of-four.html similarity index 100% rename from 0342-power-of-four/README.md rename to final/0342-power-of-four.html diff --git a/0343-integer-break/README.md b/final/0343-integer-break.html similarity index 100% rename from 0343-integer-break/README.md rename to final/0343-integer-break.html diff --git a/0344-reverse-string/README.md b/final/0344-reverse-string.html similarity index 100% rename from 0344-reverse-string/README.md rename to final/0344-reverse-string.html diff --git a/0346-moving-average-from-data-stream/README.md b/final/0346-moving-average-from-data-stream.html similarity index 100% rename from 0346-moving-average-from-data-stream/README.md rename to final/0346-moving-average-from-data-stream.html diff --git a/final/0347-top-k-frequent-elements.html b/final/0347-top-k-frequent-elements.html new file mode 100644 index 000000000..708d6ca4b --- /dev/null +++ b/final/0347-top-k-frequent-elements.html @@ -0,0 +1,23 @@ +

347. Top K Frequent Elements

Medium


Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

+ +

 

+

Example 1:

+
Input: nums = [1,1,1,2,2,3], k = 2
+Output: [1,2]
+

Example 2:

+
Input: nums = [1], k = 1
+Output: [1]
+
+

 

+

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.
  • +
+ +

 

+

Follow up: Your algorithm's time complexity must be better than O(n log n), where n is the array's size.

+
\ No newline at end of file diff --git a/0349-intersection-of-two-arrays/README.md b/final/0349-intersection-of-two-arrays.html similarity index 100% rename from 0349-intersection-of-two-arrays/README.md rename to final/0349-intersection-of-two-arrays.html diff --git a/0350-intersection-of-two-arrays-ii/README.md b/final/0350-intersection-of-two-arrays-ii.html similarity index 100% rename from 0350-intersection-of-two-arrays-ii/README.md rename to final/0350-intersection-of-two-arrays-ii.html diff --git a/0351-android-unlock-patterns/README.md b/final/0351-android-unlock-patterns.html similarity index 100% rename from 0351-android-unlock-patterns/README.md rename to final/0351-android-unlock-patterns.html diff --git a/0358-rearrange-string-k-distance-apart/README.md b/final/0358-rearrange-string-k-distance-apart.html similarity index 100% rename from 0358-rearrange-string-k-distance-apart/README.md rename to final/0358-rearrange-string-k-distance-apart.html diff --git a/final/0368-largest-divisible-subset.html b/final/0368-largest-divisible-subset.html new file mode 100644 index 000000000..ae432a88b --- /dev/null +++ b/final/0368-largest-divisible-subset.html @@ -0,0 +1,32 @@ +

368. Largest Divisible Subset

Medium


Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:

+ +
    +
  • answer[i] % answer[j] == 0, or
  • +
  • answer[j] % answer[i] == 0
  • +
+ +

If there are multiple solutions, return any of them.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3]
+Output: [1,2]
+Explanation: [1,3] is also accepted.
+
+ +

Example 2:

+ +
Input: nums = [1,2,4,8]
+Output: [1,2,4,8]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • 1 <= nums[i] <= 2 * 109
  • +
  • All the integers in nums are unique.
  • +
+
\ No newline at end of file diff --git a/0377-combination-sum-iv/README.md b/final/0377-combination-sum-iv.html similarity index 100% rename from 0377-combination-sum-iv/README.md rename to final/0377-combination-sum-iv.html diff --git a/final/0380-insert-delete-getrandom-o1.html b/final/0380-insert-delete-getrandom-o1.html new file mode 100644 index 000000000..fc1cda7ba --- /dev/null +++ b/final/0380-insert-delete-getrandom-o1.html @@ -0,0 +1,40 @@ +

380. Insert Delete GetRandom O(1)

Medium


Implement the RandomizedSet class:

+ +
    +
  • RandomizedSet() Initializes the RandomizedSet object.
  • +
  • bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.
  • +
  • bool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false otherwise.
  • +
  • int getRandom() Returns a random element from the current set of elements (it's guaranteed that at least one element exists when this method is called). Each element must have the same probability of being returned.
  • +
+ +

You must implement the functions of the class such that each function works in average O(1) time complexity.

+ +

 

+

Example 1:

+ +
Input
+["RandomizedSet", "insert", "remove", "insert", "getRandom", "remove", "insert", "getRandom"]
+[[], [1], [2], [2], [], [1], [2], []]
+Output
+[null, true, false, true, 2, true, false, 2]
+
+Explanation
+RandomizedSet randomizedSet = new RandomizedSet();
+randomizedSet.insert(1); // Inserts 1 to the set. Returns true as 1 was inserted successfully.
+randomizedSet.remove(2); // Returns false as 2 does not exist in the set.
+randomizedSet.insert(2); // Inserts 2 to the set, returns true. Set now contains [1,2].
+randomizedSet.getRandom(); // getRandom() should return either 1 or 2 randomly.
+randomizedSet.remove(1); // Removes 1 from the set, returns true. Set now contains [2].
+randomizedSet.insert(2); // 2 was already in the set, so return false.
+randomizedSet.getRandom(); // Since 2 is the only number in the set, getRandom() will always return 2.
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= val <= 231 - 1
  • +
  • At most 2 * 105 calls will be made to insert, remove, and getRandom.
  • +
  • There will be at least one element in the data structure when getRandom is called.
  • +
+
\ No newline at end of file diff --git a/0383-ransom-note/README.md b/final/0383-ransom-note.html similarity index 100% rename from 0383-ransom-note/README.md rename to final/0383-ransom-note.html diff --git a/0387-first-unique-character-in-a-string/README.md b/final/0387-first-unique-character-in-a-string.html similarity index 100% rename from 0387-first-unique-character-in-a-string/README.md rename to final/0387-first-unique-character-in-a-string.html diff --git a/0389-find-the-difference/README.md b/final/0389-find-the-difference.html similarity index 100% rename from 0389-find-the-difference/README.md rename to final/0389-find-the-difference.html diff --git a/0392-is-subsequence/README.md b/final/0392-is-subsequence.html similarity index 100% rename from 0392-is-subsequence/README.md rename to final/0392-is-subsequence.html diff --git a/final/0402-remove-k-digits.html b/final/0402-remove-k-digits.html new file mode 100644 index 000000000..4319e3f39 --- /dev/null +++ b/final/0402-remove-k-digits.html @@ -0,0 +1,33 @@ +

402. Remove K Digits

Medium


Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.

+ +

 

+

Example 1:

+ +
Input: num = "1432219", k = 3
+Output: "1219"
+Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
+
+ +

Example 2:

+ +
Input: num = "10200", k = 1
+Output: "200"
+Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
+
+ +

Example 3:

+ +
Input: num = "10", k = 2
+Output: "0"
+Explanation: Remove all the digits from the number and it is left with nothing which is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= num.length <= 105
  • +
  • num consists of only digits.
  • +
  • num does not have any leading zeros except for the zero itself.
  • +
+
\ No newline at end of file diff --git a/0403-frog-jump/README.md b/final/0403-frog-jump.html similarity index 100% rename from 0403-frog-jump/README.md rename to final/0403-frog-jump.html diff --git a/0404-sum-of-left-leaves/README.md b/final/0404-sum-of-left-leaves.html similarity index 100% rename from 0404-sum-of-left-leaves/README.md rename to final/0404-sum-of-left-leaves.html diff --git a/0409-longest-palindrome/README.md b/final/0409-longest-palindrome.html similarity index 100% rename from 0409-longest-palindrome/README.md rename to final/0409-longest-palindrome.html diff --git a/final/0416-partition-equal-subset-sum.html b/final/0416-partition-equal-subset-sum.html new file mode 100644 index 000000000..91d0d0709 --- /dev/null +++ b/final/0416-partition-equal-subset-sum.html @@ -0,0 +1,25 @@ +

416. Partition Equal Subset Sum

Medium


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:

+ +
Input: nums = [1,5,11,5]
+Output: true
+Explanation: The array can be partitioned as [1, 5, 5] and [11].
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,5]
+Output: false
+Explanation: The array cannot be partitioned into equal sum subsets.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 200
  • +
  • 1 <= nums[i] <= 100
  • +
+
\ No newline at end of file diff --git a/final/0438-find-all-anagrams-in-a-string.html b/final/0438-find-all-anagrams-in-a-string.html new file mode 100644 index 000000000..0a32c05eb --- /dev/null +++ b/final/0438-find-all-anagrams-in-a-string.html @@ -0,0 +1,32 @@ +

438. Find All Anagrams in a String

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.

+ +

 

+

Example 1:

+ +
Input: s = "cbaebabacd", p = "abc"
+Output: [0,6]
+Explanation:
+The substring with start index = 0 is "cba", which is an anagram of "abc".
+The substring with start index = 6 is "bac", which is an anagram of "abc".
+
+ +

Example 2:

+ +
Input: s = "abab", p = "ab"
+Output: [0,1,2]
+Explanation:
+The substring with start index = 0 is "ab", which is an anagram of "ab".
+The substring with start index = 1 is "ba", which is an anagram of "ab".
+The substring with start index = 2 is "ab", which is an anagram of "ab".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length, p.length <= 3 * 104
  • +
  • s and p consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0439-ternary-expression-parser/README.md b/final/0439-ternary-expression-parser.html similarity index 100% rename from 0439-ternary-expression-parser/README.md rename to final/0439-ternary-expression-parser.html diff --git a/final/0442-find-all-duplicates-in-an-array.html b/final/0442-find-all-duplicates-in-an-array.html new file mode 100644 index 000000000..1aaf2301b --- /dev/null +++ b/final/0442-find-all-duplicates-in-an-array.html @@ -0,0 +1,25 @@ +

442. Find All Duplicates in an Array

Medium


Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.

+ +

You must write an algorithm that runs in O(n) time and uses only constant extra space.

+ +

 

+

Example 1:

+
Input: nums = [4,3,2,7,8,2,3,1]
+Output: [2,3]
+

Example 2:

+
Input: nums = [1,1,2]
+Output: [1]
+

Example 3:

+
Input: nums = [1]
+Output: []
+
+

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= nums[i] <= n
  • +
  • Each element in nums appears once or twice.
  • +
+
\ No newline at end of file diff --git a/0446-arithmetic-slices-ii-subsequence/README.md b/final/0446-arithmetic-slices-ii-subsequence.html similarity index 100% rename from 0446-arithmetic-slices-ii-subsequence/README.md rename to final/0446-arithmetic-slices-ii-subsequence.html diff --git a/final/0451-sort-characters-by-frequency.html b/final/0451-sort-characters-by-frequency.html new file mode 100644 index 000000000..6eceb8b12 --- /dev/null +++ b/final/0451-sort-characters-by-frequency.html @@ -0,0 +1,37 @@ +

451. Sort Characters By Frequency

Medium


Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.

+ +

Return the sorted string. If there are multiple answers, return any of them.

+ +

 

+

Example 1:

+ +
Input: s = "tree"
+Output: "eert"
+Explanation: 'e' appears twice while 'r' and 't' both appear once.
+So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.
+
+ +

Example 2:

+ +
Input: s = "cccaaa"
+Output: "aaaccc"
+Explanation: Both 'c' and 'a' appear three times, so both "cccaaa" and "aaaccc" are valid answers.
+Note that "cacaca" is incorrect, as the same characters must be together.
+
+ +

Example 3:

+ +
Input: s = "Aabb"
+Output: "bbAa"
+Explanation: "bbaA" is also a valid answer, but "Aabb" is incorrect.
+Note that 'A' and 'a' are treated as two different characters.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 5 * 105
  • +
  • s consists of uppercase and lowercase English letters and digits.
  • +
+
\ No newline at end of file diff --git a/0452-minimum-number-of-arrows-to-burst-balloons/README.md b/final/0452-minimum-number-of-arrows-to-burst-balloons.html similarity index 100% rename from 0452-minimum-number-of-arrows-to-burst-balloons/README.md rename to final/0452-minimum-number-of-arrows-to-burst-balloons.html diff --git a/0455-assign-cookies/README.md b/final/0455-assign-cookies.html similarity index 100% rename from 0455-assign-cookies/README.md rename to final/0455-assign-cookies.html diff --git a/final/0456-132-pattern.html b/final/0456-132-pattern.html new file mode 100644 index 000000000..049ce47c1 --- /dev/null +++ b/final/0456-132-pattern.html @@ -0,0 +1,35 @@ +

456. 132 Pattern

Medium


Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].

+ +

Return true if there is a 132 pattern in nums, otherwise, return false.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4]
+Output: false
+Explanation: There is no 132 pattern in the sequence.
+
+ +

Example 2:

+ +
Input: nums = [3,1,4,2]
+Output: true
+Explanation: There is a 132 pattern in the sequence: [1, 4, 2].
+
+ +

Example 3:

+ +
Input: nums = [-1,3,2,0]
+Output: true
+Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 2 * 105
  • +
  • -109 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/0458-poor-pigs/README.md b/final/0458-poor-pigs.html similarity index 100% rename from 0458-poor-pigs/README.md rename to final/0458-poor-pigs.html diff --git a/0459-repeated-substring-pattern/README.md b/final/0459-repeated-substring-pattern.html similarity index 100% rename from 0459-repeated-substring-pattern/README.md rename to final/0459-repeated-substring-pattern.html diff --git a/0463-island-perimeter/README.md b/final/0463-island-perimeter.html similarity index 100% rename from 0463-island-perimeter/README.md rename to final/0463-island-perimeter.html diff --git a/0476-number-complement/README.md b/final/0476-number-complement.html similarity index 100% rename from 0476-number-complement/README.md rename to final/0476-number-complement.html diff --git a/final/0486-predict-the-winner.html b/final/0486-predict-the-winner.html new file mode 100644 index 000000000..e69de29bb diff --git a/0487-max-consecutive-ones-ii/README.md b/final/0487-max-consecutive-ones-ii.html similarity index 100% rename from 0487-max-consecutive-ones-ii/README.md rename to final/0487-max-consecutive-ones-ii.html diff --git a/0490-the-maze/README.md b/final/0490-the-maze.html similarity index 100% rename from 0490-the-maze/README.md rename to final/0490-the-maze.html diff --git a/0501-find-mode-in-binary-search-tree/README.md b/final/0501-find-mode-in-binary-search-tree.html similarity index 100% rename from 0501-find-mode-in-binary-search-tree/README.md rename to final/0501-find-mode-in-binary-search-tree.html diff --git a/0502-ipo/README.md b/final/0502-ipo.html similarity index 100% rename from 0502-ipo/README.md rename to final/0502-ipo.html diff --git a/0505-the-maze-ii/README.md b/final/0505-the-maze-ii.html similarity index 100% rename from 0505-the-maze-ii/README.md rename to final/0505-the-maze-ii.html diff --git a/0506-relative-ranks/README.md b/final/0506-relative-ranks.html similarity index 100% rename from 0506-relative-ranks/README.md rename to final/0506-relative-ranks.html diff --git a/0509-fibonacci-number/README.md b/final/0509-fibonacci-number.html similarity index 100% rename from 0509-fibonacci-number/README.md rename to final/0509-fibonacci-number.html diff --git a/0513-find-bottom-left-tree-value/README.md b/final/0513-find-bottom-left-tree-value.html similarity index 100% rename from 0513-find-bottom-left-tree-value/README.md rename to final/0513-find-bottom-left-tree-value.html diff --git a/0514-freedom-trail/README.md b/final/0514-freedom-trail.html similarity index 100% rename from 0514-freedom-trail/README.md rename to final/0514-freedom-trail.html diff --git a/0515-find-largest-value-in-each-tree-row/README.md b/final/0515-find-largest-value-in-each-tree-row.html similarity index 100% rename from 0515-find-largest-value-in-each-tree-row/README.md rename to final/0515-find-largest-value-in-each-tree-row.html diff --git a/final/0518-coin-change-ii.html b/final/0518-coin-change-ii.html new file mode 100644 index 000000000..d7f159727 --- /dev/null +++ b/final/0518-coin-change-ii.html @@ -0,0 +1,43 @@ +

518. Coin Change II

Medium


You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

+ +

Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.

+ +

You may assume that you have an infinite number of each kind of coin.

+ +

The answer is guaranteed to fit into a signed 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: amount = 5, coins = [1,2,5]
+Output: 4
+Explanation: there are four ways to make up the amount:
+5=5
+5=2+2+1
+5=2+1+1+1
+5=1+1+1+1+1
+
+ +

Example 2:

+ +
Input: amount = 3, coins = [2]
+Output: 0
+Explanation: the amount of 3 cannot be made up just with coins of 2.
+
+ +

Example 3:

+ +
Input: amount = 10, coins = [10]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= coins.length <= 300
  • +
  • 1 <= coins[i] <= 5000
  • +
  • All the values of coins are unique.
  • +
  • 0 <= amount <= 5000
  • +
+
\ No newline at end of file diff --git a/final/0523-continuous-subarray-sum.html b/final/0523-continuous-subarray-sum.html new file mode 100644 index 000000000..0bf5d8e1d --- /dev/null +++ b/final/0523-continuous-subarray-sum.html @@ -0,0 +1,48 @@ +

523. Continuous Subarray Sum

Medium


Given an integer array nums and an integer k, return true if nums has a good subarray or false otherwise.

+ +

A good subarray is a subarray where:

+ +
    +
  • its length is at least two, and
  • +
  • the sum of the elements of the subarray is a multiple of k.
  • +
+ +

Note that:

+ +
    +
  • A subarray is a contiguous part of the array.
  • +
  • An integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k.
  • +
+ +

 

+

Example 1:

+ +
Input: nums = [23,2,4,6,7], k = 6
+Output: true
+Explanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6.
+
+ +

Example 2:

+ +
Input: nums = [23,2,6,4,7], k = 6
+Output: true
+Explanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42.
+42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer.
+
+ +

Example 3:

+ +
Input: nums = [23,2,6,4,7], k = 13
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 109
  • +
  • 0 <= sum(nums[i]) <= 231 - 1
  • +
  • 1 <= k <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/final/0525-contiguous-array.html b/final/0525-contiguous-array.html new file mode 100644 index 000000000..20b1a72d9 --- /dev/null +++ b/final/0525-contiguous-array.html @@ -0,0 +1,25 @@ +

525. Contiguous Array

Medium


Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.

+ +

 

+

Example 1:

+ +
Input: nums = [0,1]
+Output: 2
+Explanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.
+
+ +

Example 2:

+ +
Input: nums = [0,1,0]
+Output: 2
+Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • nums[i] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/final/0532-k-diff-pairs-in-an-array.html b/final/0532-k-diff-pairs-in-an-array.html new file mode 100644 index 000000000..fd44bfa14 --- /dev/null +++ b/final/0532-k-diff-pairs-in-an-array.html @@ -0,0 +1,44 @@ +

532. K-diff Pairs in an Array

Medium


Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.

+ +

A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:

+ +
    +
  • 0 <= i, j < nums.length
  • +
  • i != j
  • +
  • |nums[i] - nums[j]| == k
  • +
+ +

Notice that |val| denotes the absolute value of val.

+ +

 

+

Example 1:

+ +
Input: nums = [3,1,4,1,5], k = 2
+Output: 2
+Explanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5).
+Although we have two 1s in the input, we should only return the number of unique pairs.
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,4,5], k = 1
+Output: 4
+Explanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5).
+
+ +

Example 3:

+ +
Input: nums = [1,3,1,5,4], k = 0
+Output: 1
+Explanation: There is one 0-diff pair in the array, (1, 1).
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 104
  • +
  • -107 <= nums[i] <= 107
  • +
  • 0 <= k <= 107
  • +
+
\ No newline at end of file diff --git a/final/0540-single-element-in-a-sorted-array.html b/final/0540-single-element-in-a-sorted-array.html new file mode 100644 index 000000000..41726f966 --- /dev/null +++ b/final/0540-single-element-in-a-sorted-array.html @@ -0,0 +1,22 @@ +

540. Single Element in a Sorted Array

Medium


You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.

+ +

Return the single element that appears only once.

+ +

Your solution must run in O(log n) time and O(1) space.

+ +

 

+

Example 1:

+
Input: nums = [1,1,2,3,3,4,4,8,8]
+Output: 2
+

Example 2:

+
Input: nums = [3,3,7,7,10,11,11]
+Output: 10
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/final/0542-01-matrix.html b/final/0542-01-matrix.html new file mode 100644 index 000000000..931bf9a29 --- /dev/null +++ b/final/0542-01-matrix.html @@ -0,0 +1,29 @@ +

542. 01 Matrix

Medium


Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.

+ +

The distance between two adjacent cells is 1.

+ +

 

+

Example 1:

+ +
Input: mat = [[0,0,0],[0,1,0],[0,0,0]]
+Output: [[0,0,0],[0,1,0],[0,0,0]]
+
+ +

Example 2:

+ +
Input: mat = [[0,0,0],[0,1,0],[1,1,1]]
+Output: [[0,0,0],[0,1,0],[1,2,1]]
+
+ +

 

+

Constraints:

+ +
    +
  • m == mat.length
  • +
  • n == mat[i].length
  • +
  • 1 <= m, n <= 104
  • +
  • 1 <= m * n <= 104
  • +
  • mat[i][j] is either 0 or 1.
  • +
  • There is at least one 0 in mat.
  • +
+
\ No newline at end of file diff --git a/0543-diameter-of-binary-tree/README.md b/final/0543-diameter-of-binary-tree.html similarity index 100% rename from 0543-diameter-of-binary-tree/README.md rename to final/0543-diameter-of-binary-tree.html diff --git a/0552-student-attendance-record-ii/README.md b/final/0552-student-attendance-record-ii.html similarity index 100% rename from 0552-student-attendance-record-ii/README.md rename to final/0552-student-attendance-record-ii.html diff --git a/0557-reverse-words-in-a-string-iii/README.md b/final/0557-reverse-words-in-a-string-iii.html similarity index 100% rename from 0557-reverse-words-in-a-string-iii/README.md rename to final/0557-reverse-words-in-a-string-iii.html diff --git a/0561-array-partition/README.md b/final/0561-array-partition.html similarity index 100% rename from 0561-array-partition/README.md rename to final/0561-array-partition.html diff --git a/0564-find-the-closest-palindrome/README.md b/final/0564-find-the-closest-palindrome.html similarity index 100% rename from 0564-find-the-closest-palindrome/README.md rename to final/0564-find-the-closest-palindrome.html diff --git a/0566-reshape-the-matrix/README.md b/final/0566-reshape-the-matrix.html similarity index 100% rename from 0566-reshape-the-matrix/README.md rename to final/0566-reshape-the-matrix.html diff --git a/final/0567-permutation-in-string.html b/final/0567-permutation-in-string.html new file mode 100644 index 000000000..095f65265 --- /dev/null +++ b/final/0567-permutation-in-string.html @@ -0,0 +1,26 @@ +

567. Permutation in String

Medium


Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

+ +

In other words, return true if one of s1's permutations is the substring of s2.

+ +

 

+

Example 1:

+ +
Input: s1 = "ab", s2 = "eidbaooo"
+Output: true
+Explanation: s2 contains one permutation of s1 ("ba").
+
+ +

Example 2:

+ +
Input: s1 = "ab", s2 = "eidboaoo"
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s1.length, s2.length <= 104
  • +
  • s1 and s2 consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0572-subtree-of-another-tree/README.md b/final/0572-subtree-of-another-tree.html similarity index 100% rename from 0572-subtree-of-another-tree/README.md rename to final/0572-subtree-of-another-tree.html diff --git a/0573-squirrel-simulation/README.md b/final/0573-squirrel-simulation.html similarity index 100% rename from 0573-squirrel-simulation/README.md rename to final/0573-squirrel-simulation.html diff --git a/0576-out-of-boundary-paths/README.md b/final/0576-out-of-boundary-paths.html similarity index 100% rename from 0576-out-of-boundary-paths/README.md rename to final/0576-out-of-boundary-paths.html diff --git a/0584-find-customer-referee/README.md b/final/0584-find-customer-referee.html similarity index 100% rename from 0584-find-customer-referee/README.md rename to final/0584-find-customer-referee.html diff --git a/0590-n-ary-tree-postorder-traversal/README.md b/final/0590-n-ary-tree-postorder-traversal.html similarity index 100% rename from 0590-n-ary-tree-postorder-traversal/README.md rename to final/0590-n-ary-tree-postorder-traversal.html diff --git a/final/0592-fraction-addition-and-subtraction.html b/final/0592-fraction-addition-and-subtraction.html new file mode 100644 index 000000000..5d1558c52 --- /dev/null +++ b/final/0592-fraction-addition-and-subtraction.html @@ -0,0 +1,34 @@ +

592. Fraction Addition and Subtraction

Medium


Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.

+ +

The final result should be an irreducible fraction. If your final result is an integer, change it to the format of a fraction that has a denominator 1. So in this case, 2 should be converted to 2/1.

+ +

 

+

Example 1:

+ +
Input: expression = "-1/2+1/2"
+Output: "0/1"
+
+ +

Example 2:

+ +
Input: expression = "-1/2+1/2+1/3"
+Output: "1/3"
+
+ +

Example 3:

+ +
Input: expression = "1/3-1/2"
+Output: "-1/6"
+
+ +

 

+

Constraints:

+ +
    +
  • The input string only contains '0' to '9', '/', '+' and '-'. So does the output.
  • +
  • Each fraction (input and output) has the format ±numerator/denominator. If the first input fraction or the output is positive, then '+' will be omitted.
  • +
  • The input only contains valid irreducible fractions, where the numerator and denominator of each fraction will always be in the range [1, 10]. If the denominator is 1, it means this fraction is actually an integer in a fraction format defined above.
  • +
  • The number of given fractions will be in the range [1, 10].
  • +
  • The numerator and denominator of the final result are guaranteed to be valid and in the range of 32-bit int.
  • +
+
\ No newline at end of file diff --git a/0595-big-countries/README.md b/final/0595-big-countries.html similarity index 100% rename from 0595-big-countries/README.md rename to final/0595-big-countries.html diff --git a/final/0606-construct-string-from-binary-tree.html b/final/0606-construct-string-from-binary-tree.html new file mode 100644 index 000000000..d304033ff --- /dev/null +++ b/final/0606-construct-string-from-binary-tree.html @@ -0,0 +1,27 @@ +

606. Construct String from Binary Tree

Easy


Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it.

+ +

Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,4]
+Output: "1(2(4))(3)"
+Explanation: Originally, it needs to be "1(2(4)())(3()())", but you need to omit all the unnecessary empty parenthesis pairs. And it will be "1(2(4))(3)"
+
+ +

Example 2:

+ +
Input: root = [1,2,3,null,4]
+Output: "1(2()(4))(3)"
+Explanation: Almost the same as the first example, except we cannot omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • -1000 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0617-merge-two-binary-trees/README.md b/final/0617-merge-two-binary-trees.html similarity index 100% rename from 0617-merge-two-binary-trees/README.md rename to final/0617-merge-two-binary-trees.html diff --git a/final/0621-task-scheduler.html b/final/0621-task-scheduler.html new file mode 100644 index 000000000..a449ed32f --- /dev/null +++ b/final/0621-task-scheduler.html @@ -0,0 +1,95 @@ +

621. Task Scheduler

Medium


You are given an array of CPU tasks, each represented by letters A to Z, and a cooling time, n. Each cycle or interval allows the completion of one task. Tasks can be completed in any order, but there's a constraint: identical tasks must be separated by at least n intervals due to cooling time.

+ +

​Return the minimum number of intervals required to complete all tasks.

+ +

 

+

Example 1:

+ +
+

Input: tasks = ["A","A","A","B","B","B"], n = 2

+ +

Output: 8

+ +

Explanation: A possible sequence is: A -> B -> idle -> A -> B -> idle -> A -> B.

+ +

After completing task A, you must wait two cycles before doing A again. The same applies to task B. In the 3rd interval, neither A nor B can be done, so you idle. By the 4th cycle, you can do A again as 2 intervals have passed.

+
+ +

Example 2:

+ +
+

Input: tasks = ["A","C","A","B","D","B"], n = 1

+ +

Output: 6

+ +

Explanation: A possible sequence is: A -> B -> C -> D -> A -> B.

+ +

With a cooling interval of 1, you can repeat a task after just one other task.

+
+ +

Example 3:

+ +
+

Input: tasks = ["A","A","A", "B","B","B"], n = 3

+ +

Output: 10

+ +

Explanation: A possible sequence is: A -> B -> idle -> idle -> A -> B -> idle -> idle -> A -> B.

+ +

There are only two types of tasks, A and B, which need to be separated by 3 intervals. This leads to idling twice between repetitions of these tasks.

+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= tasks.length <= 104
  • +
  • tasks[i] is an uppercase English letter.
  • +
  • 0 <= n <= 100
  • +
+
\ No newline at end of file diff --git a/0623-add-one-row-to-tree/README.md b/final/0623-add-one-row-to-tree.html similarity index 100% rename from 0623-add-one-row-to-tree/README.md rename to final/0623-add-one-row-to-tree.html diff --git a/final/0624-maximum-distance-in-arrays.html b/final/0624-maximum-distance-in-arrays.html new file mode 100644 index 000000000..77b7a756f --- /dev/null +++ b/final/0624-maximum-distance-in-arrays.html @@ -0,0 +1,32 @@ +

624. Maximum Distance in Arrays

Medium


You are given m arrays, where each array is sorted in ascending order.

+ +

You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|.

+ +

Return the maximum distance.

+ +

 

+

Example 1:

+ +
Input: arrays = [[1,2,3],[4,5],[1,2,3]]
+Output: 4
+Explanation: One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.
+
+ +

Example 2:

+ +
Input: arrays = [[1],[1]]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • m == arrays.length
  • +
  • 2 <= m <= 105
  • +
  • 1 <= arrays[i].length <= 500
  • +
  • -104 <= arrays[i][j] <= 104
  • +
  • arrays[i] is sorted in ascending order.
  • +
  • There will be at most 105 integers in all the arrays.
  • +
+
\ No newline at end of file diff --git a/0629-k-inverse-pairs-array/README.md b/final/0629-k-inverse-pairs-array.html similarity index 100% rename from 0629-k-inverse-pairs-array/README.md rename to final/0629-k-inverse-pairs-array.html diff --git a/final/0633-sum-of-square-numbers.html b/final/0633-sum-of-square-numbers.html new file mode 100644 index 000000000..efeadaa1f --- /dev/null +++ b/final/0633-sum-of-square-numbers.html @@ -0,0 +1,23 @@ +

633. Sum of Square Numbers

Medium


Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.

+ +

 

+

Example 1:

+ +
Input: c = 5
+Output: true
+Explanation: 1 * 1 + 2 * 2 = 5
+
+ +

Example 2:

+ +
Input: c = 3
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= c <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0645-set-mismatch/README.md b/final/0645-set-mismatch.html similarity index 100% rename from 0645-set-mismatch/README.md rename to final/0645-set-mismatch.html diff --git a/final/0646-maximum-length-of-pair-chain.html b/final/0646-maximum-length-of-pair-chain.html new file mode 100644 index 000000000..0537ff055 --- /dev/null +++ b/final/0646-maximum-length-of-pair-chain.html @@ -0,0 +1,32 @@ +

646. Maximum Length of Pair Chain

Medium


You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.

+ +

A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.

+ +

Return the length longest chain which can be formed.

+ +

You do not need to use up all the given intervals. You can select pairs in any order.

+ +

 

+

Example 1:

+ +
Input: pairs = [[1,2],[2,3],[3,4]]
+Output: 2
+Explanation: The longest chain is [1,2] -> [3,4].
+
+ +

Example 2:

+ +
Input: pairs = [[1,2],[7,8],[4,5]]
+Output: 3
+Explanation: The longest chain is [1,2] -> [4,5] -> [7,8].
+
+ +

 

+

Constraints:

+ +
    +
  • n == pairs.length
  • +
  • 1 <= n <= 1000
  • +
  • -1000 <= lefti < righti <= 1000
  • +
+
\ No newline at end of file diff --git a/final/0647-palindromic-substrings.html b/final/0647-palindromic-substrings.html new file mode 100644 index 000000000..f833b17ee --- /dev/null +++ b/final/0647-palindromic-substrings.html @@ -0,0 +1,29 @@ +

647. Palindromic Substrings

Medium


Given a string s, return the number of palindromic substrings in it.

+ +

A string is a palindrome when it reads the same backward as forward.

+ +

A substring is a contiguous sequence of characters within the string.

+ +

 

+

Example 1:

+ +
Input: s = "abc"
+Output: 3
+Explanation: Three palindromic strings: "a", "b", "c".
+
+ +

Example 2:

+ +
Input: s = "aaa"
+Output: 6
+Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/final/0648-replace-words.html b/final/0648-replace-words.html new file mode 100644 index 000000000..aed11e374 --- /dev/null +++ b/final/0648-replace-words.html @@ -0,0 +1,34 @@ +

648. Replace Words

Medium


In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative. For example, when the root "help" is followed by the word "ful", we can form a derivative "helpful".

+ +

Given a dictionary consisting of many roots and a sentence consisting of words separated by spaces, replace all the derivatives in the sentence with the root forming it. If a derivative can be replaced by more than one root, replace it with the root that has the shortest length.

+ +

Return the sentence after the replacement.

+ +

 

+

Example 1:

+ +
Input: dictionary = ["cat","bat","rat"], sentence = "the cattle was rattled by the battery"
+Output: "the cat was rat by the bat"
+
+ +

Example 2:

+ +
Input: dictionary = ["a","b","c"], sentence = "aadsfasf absbs bbab cadsfafs"
+Output: "a a b c"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= dictionary.length <= 1000
  • +
  • 1 <= dictionary[i].length <= 100
  • +
  • dictionary[i] consists of only lower-case letters.
  • +
  • 1 <= sentence.length <= 106
  • +
  • sentence consists of only lower-case letters and spaces.
  • +
  • The number of words in sentence is in the range [1, 1000]
  • +
  • The length of each word in sentence is in the range [1, 1000]
  • +
  • Every two consecutive words in sentence will be separated by exactly one space.
  • +
  • sentence does not have leading or trailing spaces.
  • +
+
\ No newline at end of file diff --git a/final/0650-2-keys-keyboard.html b/final/0650-2-keys-keyboard.html new file mode 100644 index 000000000..4d7785490 --- /dev/null +++ b/final/0650-2-keys-keyboard.html @@ -0,0 +1,33 @@ +

650. 2 Keys Keyboard

Medium


There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:

+ +
    +
  • Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).
  • +
  • Paste: You can paste the characters which are copied last time.
  • +
+ +

Given an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen.

+ +

 

+

Example 1:

+ +
Input: n = 3
+Output: 3
+Explanation: Initially, we have one character 'A'.
+In step 1, we use Copy All operation.
+In step 2, we use Paste operation to get 'AA'.
+In step 3, we use Paste operation to get 'AAA'.
+
+ +

Example 2:

+ +
Input: n = 1
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1000
  • +
+
\ No newline at end of file diff --git a/0653-two-sum-iv-input-is-a-bst/README.md b/final/0653-two-sum-iv-input-is-a-bst.html similarity index 100% rename from 0653-two-sum-iv-input-is-a-bst/README.md rename to final/0653-two-sum-iv-input-is-a-bst.html diff --git a/final/0658-find-k-closest-elements.html b/final/0658-find-k-closest-elements.html new file mode 100644 index 000000000..e69de29bb diff --git a/0661-image-smoother/README.md b/final/0661-image-smoother.html similarity index 100% rename from 0661-image-smoother/README.md rename to final/0661-image-smoother.html diff --git a/0664-strange-printer/README.md b/final/0664-strange-printer.html similarity index 100% rename from 0664-strange-printer/README.md rename to final/0664-strange-printer.html diff --git a/final/0678-valid-parenthesis-string.html b/final/0678-valid-parenthesis-string.html new file mode 100644 index 000000000..26a61d266 --- /dev/null +++ b/final/0678-valid-parenthesis-string.html @@ -0,0 +1,30 @@ +

678. Valid Parenthesis String

Medium


Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.

+ +

The following rules define a valid string:

+ +
    +
  • Any left parenthesis '(' must have a corresponding right parenthesis ')'.
  • +
  • Any right parenthesis ')' must have a corresponding left parenthesis '('.
  • +
  • Left parenthesis '(' must go before the corresponding right parenthesis ')'.
  • +
  • '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string "".
  • +
+ +

 

+

Example 1:

+
Input: s = "()"
+Output: true
+

Example 2:

+
Input: s = "(*)"
+Output: true
+

Example 3:

+
Input: s = "(*))"
+Output: true
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s[i] is '(', ')' or '*'.
  • +
+
\ No newline at end of file diff --git a/final/0695-max-area-of-island.html b/final/0695-max-area-of-island.html new file mode 100644 index 000000000..c31891e0a --- /dev/null +++ b/final/0695-max-area-of-island.html @@ -0,0 +1,30 @@ +

695. Max Area of Island

Medium


You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

+ +

The area of an island is the number of cells with a value 1 in the island.

+ +

Return the maximum area of an island in grid. If there is no island, return 0.

+ +

 

+

Example 1:

+ +
Input: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]
+Output: 6
+Explanation: The answer is not 11, because the island must be connected 4-directionally.
+
+ +

Example 2:

+ +
Input: grid = [[0,0,0,0,0,0,0,0]]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 50
  • +
  • grid[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/0700-search-in-a-binary-search-tree/README.md b/final/0700-search-in-a-binary-search-tree.html similarity index 100% rename from 0700-search-in-a-binary-search-tree/README.md rename to final/0700-search-in-a-binary-search-tree.html diff --git a/final/0701-insert-into-a-binary-search-tree.html b/final/0701-insert-into-a-binary-search-tree.html new file mode 100644 index 000000000..e065dfec4 --- /dev/null +++ b/final/0701-insert-into-a-binary-search-tree.html @@ -0,0 +1,36 @@ +

701. Insert into a Binary Search Tree

Medium


You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.

+ +

Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.

+ +

 

+

Example 1:

+ +
Input: root = [4,2,7,1,3], val = 5
+Output: [4,2,7,1,3,5]
+Explanation: Another accepted tree is:
+
+
+ +

Example 2:

+ +
Input: root = [40,20,60,10,30,50,70], val = 25
+Output: [40,20,60,10,30,50,70,null,null,25]
+
+ +

Example 3:

+ +
Input: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5
+Output: [4,2,7,1,3,5]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree will be in the range [0, 104].
  • +
  • -108 <= Node.val <= 108
  • +
  • All the values Node.val are unique.
  • +
  • -108 <= val <= 108
  • +
  • It's guaranteed that val does not exist in the original BST.
  • +
+
\ No newline at end of file diff --git a/0703-kth-largest-element-in-a-stream/README.md b/final/0703-kth-largest-element-in-a-stream.html similarity index 100% rename from 0703-kth-largest-element-in-a-stream/README.md rename to final/0703-kth-largest-element-in-a-stream.html diff --git a/0704-binary-search/README.md b/final/0704-binary-search.html similarity index 100% rename from 0704-binary-search/README.md rename to final/0704-binary-search.html diff --git a/0706-design-hashmap/README.md b/final/0706-design-hashmap.html similarity index 100% rename from 0706-design-hashmap/README.md rename to final/0706-design-hashmap.html diff --git a/0712-minimum-ascii-delete-sum-for-two-strings/README.md b/final/0712-minimum-ascii-delete-sum-for-two-strings.html similarity index 100% rename from 0712-minimum-ascii-delete-sum-for-two-strings/README.md rename to final/0712-minimum-ascii-delete-sum-for-two-strings.html diff --git a/0713-subarray-product-less-than-k/README.md b/final/0713-subarray-product-less-than-k.html similarity index 100% rename from 0713-subarray-product-less-than-k/README.md rename to final/0713-subarray-product-less-than-k.html diff --git a/final/0719-find-k-th-smallest-pair-distance.html b/final/0719-find-k-th-smallest-pair-distance.html new file mode 100644 index 000000000..e69de29bb diff --git a/final/0721-accounts-merge.html b/final/0721-accounts-merge.html new file mode 100644 index 000000000..3304916c6 --- /dev/null +++ b/final/0721-accounts-merge.html @@ -0,0 +1,35 @@ +

721. Accounts Merge

Medium


Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.

+ +

Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.

+ +

After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.

+ +

 

+

Example 1:

+ +
Input: accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
+Output: [["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
+Explanation:
+The first and second John's are the same person as they have the common email "johnsmith@mail.com".
+The third John and Mary are different people as none of their email addresses are used by other accounts.
+We could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'], 
+['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.
+
+ +

Example 2:

+ +
Input: accounts = [["Gabe","Gabe0@m.co","Gabe3@m.co","Gabe1@m.co"],["Kevin","Kevin3@m.co","Kevin5@m.co","Kevin0@m.co"],["Ethan","Ethan5@m.co","Ethan4@m.co","Ethan0@m.co"],["Hanzo","Hanzo3@m.co","Hanzo1@m.co","Hanzo0@m.co"],["Fern","Fern5@m.co","Fern1@m.co","Fern0@m.co"]]
+Output: [["Ethan","Ethan0@m.co","Ethan4@m.co","Ethan5@m.co"],["Gabe","Gabe0@m.co","Gabe1@m.co","Gabe3@m.co"],["Hanzo","Hanzo0@m.co","Hanzo1@m.co","Hanzo3@m.co"],["Kevin","Kevin0@m.co","Kevin3@m.co","Kevin5@m.co"],["Fern","Fern0@m.co","Fern1@m.co","Fern5@m.co"]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= accounts.length <= 1000
  • +
  • 2 <= accounts[i].length <= 10
  • +
  • 1 <= accounts[i][j].length <= 30
  • +
  • accounts[i][0] consists of English letters.
  • +
  • accounts[i][j] (for j > 0) is a valid email.
  • +
+
\ No newline at end of file diff --git a/0723-candy-crush/README.md b/final/0723-candy-crush.html similarity index 100% rename from 0723-candy-crush/README.md rename to final/0723-candy-crush.html diff --git a/final/0725-split-linked-list-in-parts.html b/final/0725-split-linked-list-in-parts.html new file mode 100644 index 000000000..45b552072 --- /dev/null +++ b/final/0725-split-linked-list-in-parts.html @@ -0,0 +1,35 @@ +

725. Split Linked List in Parts

Medium


Given the head of a singly linked list and an integer k, split the linked list into k consecutive linked list parts.

+ +

The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null.

+ +

The parts should be in the order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal to parts occurring later.

+ +

Return an array of the k parts.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3], k = 5
+Output: [[1],[2],[3],[],[]]
+Explanation:
+The first element output[0] has output[0].val = 1, output[0].next = null.
+The last element output[4] is null, but its string representation as a ListNode is [].
+
+ +

Example 2:

+ +
Input: head = [1,2,3,4,5,6,7,8,9,10], k = 3
+Output: [[1,2,3,4],[5,6,7],[8,9,10]]
+Explanation:
+The input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 1000].
  • +
  • 0 <= Node.val <= 1000
  • +
  • 1 <= k <= 50
  • +
+
\ No newline at end of file diff --git a/0726-number-of-atoms/README.md b/final/0726-number-of-atoms.html similarity index 100% rename from 0726-number-of-atoms/README.md rename to final/0726-number-of-atoms.html diff --git a/0733-flood-fill/README.md b/final/0733-flood-fill.html similarity index 100% rename from 0733-flood-fill/README.md rename to final/0733-flood-fill.html diff --git a/final/0739-daily-temperatures.html b/final/0739-daily-temperatures.html new file mode 100644 index 000000000..cb144a23b --- /dev/null +++ b/final/0739-daily-temperatures.html @@ -0,0 +1,21 @@ +

739. Daily Temperatures

Medium


Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

+ +

 

+

Example 1:

+
Input: temperatures = [73,74,75,71,69,72,76,73]
+Output: [1,1,4,2,1,1,0,0]
+

Example 2:

+
Input: temperatures = [30,40,50,60]
+Output: [1,1,1,0]
+

Example 3:

+
Input: temperatures = [30,60,90]
+Output: [1,1,0]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= temperatures.length <= 105
  • +
  • 30 <= temperatures[i] <= 100
  • +
+
\ No newline at end of file diff --git a/0741-cherry-pickup/README.md b/final/0741-cherry-pickup.html similarity index 100% rename from 0741-cherry-pickup/README.md rename to final/0741-cherry-pickup.html diff --git a/0746-min-cost-climbing-stairs/README.md b/final/0746-min-cost-climbing-stairs.html similarity index 100% rename from 0746-min-cost-climbing-stairs/README.md rename to final/0746-min-cost-climbing-stairs.html diff --git a/final/0752-open-the-lock.html b/final/0752-open-the-lock.html new file mode 100644 index 000000000..36cb276f0 --- /dev/null +++ b/final/0752-open-the-lock.html @@ -0,0 +1,44 @@ +

752. Open the Lock

Medium


You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot.

+ +

The lock initially starts at '0000', a string representing the state of the 4 wheels.

+ +

You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it.

+ +

Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.

+ +

 

+

Example 1:

+ +
Input: deadends = ["0201","0101","0102","1212","2002"], target = "0202"
+Output: 6
+Explanation: 
+A sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".
+Note that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,
+because the wheels of the lock become stuck after the display becomes the dead end "0102".
+
+ +

Example 2:

+ +
Input: deadends = ["8888"], target = "0009"
+Output: 1
+Explanation: We can turn the last wheel in reverse to move from "0000" -> "0009".
+
+ +

Example 3:

+ +
Input: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"
+Output: -1
+Explanation: We cannot reach the target without getting stuck.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= deadends.length <= 500
  • +
  • deadends[i].length == 4
  • +
  • target.length == 4
  • +
  • target will not be in the list deadends.
  • +
  • target and deadends[i] consist of digits only.
  • +
+
\ No newline at end of file diff --git a/final/0767-reorganize-string.html b/final/0767-reorganize-string.html new file mode 100644 index 000000000..5ae1df969 --- /dev/null +++ b/final/0767-reorganize-string.html @@ -0,0 +1,20 @@ +

767. Reorganize String

Medium


Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

+ +

Return any possible rearrangement of s or return "" if not possible.

+ +

 

+

Example 1:

+
Input: s = "aab"
+Output: "aba"
+

Example 2:

+
Input: s = "aaab"
+Output: ""
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 500
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/final/0776-split-bst.html b/final/0776-split-bst.html new file mode 100644 index 000000000..429efeeda --- /dev/null +++ b/final/0776-split-bst.html @@ -0,0 +1,27 @@ +

776. Split BST

Medium


Given the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where the first subtree has nodes that are all smaller or equal to the target value, while the second subtree has all nodes that are greater than the target value. It is not necessarily the case that the tree contains a node with the value target.

+ +

Additionally, most of the structure of the original tree should remain. Formally, for any child c with parent p in the original tree, if they are both in the same subtree after the split, then node c should still have the parent p.

+ +

Return an array of the two roots of the two subtrees in order.

+ +

 

+

Example 1:

+ +
Input: root = [4,2,6,1,3,5,7], target = 2
+Output: [[2,1],[4,3,6,null,null,5,7]]
+
+ +

Example 2:

+ +
Input: root = [1], target = 1
+Output: [[1],[]]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 50].
  • +
  • 0 <= Node.val, target <= 1000
  • +
+
\ No newline at end of file diff --git a/final/0779-k-th-symbol-in-grammar.html b/final/0779-k-th-symbol-in-grammar.html new file mode 100644 index 000000000..e3cac27c0 --- /dev/null +++ b/final/0779-k-th-symbol-in-grammar.html @@ -0,0 +1,42 @@ +

779. K-th Symbol in Grammar

Medium


We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.

+ +
    +
  • For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.
  • +
+ +

Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.

+ +

 

+

Example 1:

+ +
Input: n = 1, k = 1
+Output: 0
+Explanation: row 1: 0
+
+ +

Example 2:

+ +
Input: n = 2, k = 1
+Output: 0
+Explanation: 
+row 1: 0
+row 2: 01
+
+ +

Example 3:

+ +
Input: n = 2, k = 2
+Output: 1
+Explanation: 
+row 1: 0
+row 2: 01
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 30
  • +
  • 1 <= k <= 2n - 1
  • +
+
\ No newline at end of file diff --git a/0784-letter-case-permutation/README.md b/final/0784-letter-case-permutation.html similarity index 100% rename from 0784-letter-case-permutation/README.md rename to final/0784-letter-case-permutation.html diff --git a/final/0786-k-th-smallest-prime-fraction.html b/final/0786-k-th-smallest-prime-fraction.html new file mode 100644 index 000000000..819e01048 --- /dev/null +++ b/final/0786-k-th-smallest-prime-fraction.html @@ -0,0 +1,36 @@ +

786. K-th Smallest Prime Fraction

Medium


You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.

+ +

For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].

+ +

Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].

+ +

 

+

Example 1:

+ +
Input: arr = [1,2,3,5], k = 3
+Output: [2,5]
+Explanation: The fractions to be considered in sorted order are:
+1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.
+The third fraction is 2/5.
+
+ +

Example 2:

+ +
Input: arr = [1,7], k = 1
+Output: [1,7]
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= arr.length <= 1000
  • +
  • 1 <= arr[i] <= 3 * 104
  • +
  • arr[0] == 1
  • +
  • arr[i] is a prime number for i > 0.
  • +
  • All the numbers of arr are unique and sorted in strictly increasing order.
  • +
  • 1 <= k <= arr.length * (arr.length - 1) / 2
  • +
+ +

 

+Follow up: Can you solve the problem with better than O(n2) complexity?
\ No newline at end of file diff --git a/final/0787-cheapest-flights-within-k-stops.html b/final/0787-cheapest-flights-within-k-stops.html new file mode 100644 index 000000000..9bd2c6851 --- /dev/null +++ b/final/0787-cheapest-flights-within-k-stops.html @@ -0,0 +1,48 @@ +

787. Cheapest Flights Within K Stops

Medium


There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei.

+ +

You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.

+ +

 

+

Example 1:

+ +
Input: n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1
+Output: 700
+Explanation:
+The graph is shown above.
+The optimal path with at most 1 stop from city 0 to 3 is marked in red and has cost 100 + 600 = 700.
+Note that the path through cities [0,1,2,3] is cheaper but is invalid because it uses 2 stops.
+
+ +

Example 2:

+ +
Input: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1
+Output: 200
+Explanation:
+The graph is shown above.
+The optimal path with at most 1 stop from city 0 to 2 is marked in red and has cost 100 + 100 = 200.
+
+ +

Example 3:

+ +
Input: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0
+Output: 500
+Explanation:
+The graph is shown above.
+The optimal path with no stops from city 0 to 2 is marked in red and has cost 500.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 100
  • +
  • 0 <= flights.length <= (n * (n - 1) / 2)
  • +
  • flights[i].length == 3
  • +
  • 0 <= fromi, toi < n
  • +
  • fromi != toi
  • +
  • 1 <= pricei <= 104
  • +
  • There will not be any multiple flights between two cities.
  • +
  • 0 <= src, dst, k < n
  • +
  • src != dst
  • +
+
\ No newline at end of file diff --git a/final/0791-custom-sort-string.html b/final/0791-custom-sort-string.html new file mode 100644 index 000000000..df4199fed --- /dev/null +++ b/final/0791-custom-sort-string.html @@ -0,0 +1,41 @@ +

791. Custom Sort String

Medium


You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.

+ +

Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.

+ +

Return any permutation of s that satisfies this property.

+ +

 

+

Example 1:

+ +
+

Input: order = "cba", s = "abcd"

+ +

Output: "cbad"

+ +

Explanation: "a", "b", "c" appear in order, so the order of "a", "b", "c" should be "c", "b", and "a".

+ +

Since "d" does not appear in order, it can be at any position in the returned string. "dcba", "cdba", "cbda" are also valid outputs.

+
+ +

Example 2:

+ +
+

Input: order = "bcafg", s = "abcd"

+ +

Output: "bcad"

+ +

Explanation: The characters "b", "c", and "a" from order dictate the order for the characters in s. The character "d" in s does not appear in order, so its position is flexible.

+ +

Following the order of appearance in order, "b", "c", and "a" from s should be arranged as "b", "c", "a". "d" can be placed at any position since it's not in order. The output "bcad" correctly follows this rule. Other arrangements like "bacd" or "bcda" would also be valid, as long as "b", "c", "a" maintain their order.

+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= order.length <= 26
  • +
  • 1 <= s.length <= 200
  • +
  • order and s consist of lowercase English letters.
  • +
  • All the characters of order are unique.
  • +
+
\ No newline at end of file diff --git a/0799-champagne-tower/README.md b/final/0799-champagne-tower.html similarity index 100% rename from 0799-champagne-tower/README.md rename to final/0799-champagne-tower.html diff --git a/0808-soup-servings/README.md b/final/0808-soup-servings.html similarity index 100% rename from 0808-soup-servings/README.md rename to final/0808-soup-servings.html diff --git a/0815-bus-routes/README.md b/final/0815-bus-routes.html similarity index 100% rename from 0815-bus-routes/README.md rename to final/0815-bus-routes.html diff --git a/0823-binary-trees-with-factors/README.md b/final/0823-binary-trees-with-factors.html similarity index 100% rename from 0823-binary-trees-with-factors/README.md rename to final/0823-binary-trees-with-factors.html diff --git a/final/0826-most-profit-assigning-work.html b/final/0826-most-profit-assigning-work.html new file mode 100644 index 000000000..150af98dc --- /dev/null +++ b/final/0826-most-profit-assigning-work.html @@ -0,0 +1,40 @@ +

826. Most Profit Assigning Work

Medium


You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where:

+ +
    +
  • difficulty[i] and profit[i] are the difficulty and the profit of the ith job, and
  • +
  • worker[j] is the ability of jth worker (i.e., the jth worker can only complete a job with difficulty at most worker[j]).
  • +
+ +

Every worker can be assigned at most one job, but one job can be completed multiple times.

+ +
    +
  • For example, if three workers attempt the same job that pays $1, then the total profit will be $3. If a worker cannot complete any job, their profit is $0.
  • +
+ +

Return the maximum profit we can achieve after assigning the workers to the jobs.

+ +

 

+

Example 1:

+ +
Input: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]
+Output: 100
+Explanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get a profit of [20,20,30,30] separately.
+
+ +

Example 2:

+ +
Input: difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • n == difficulty.length
  • +
  • n == profit.length
  • +
  • m == worker.length
  • +
  • 1 <= n, m <= 104
  • +
  • 1 <= difficulty[i], profit[i], worker[i] <= 105
  • +
+
\ No newline at end of file diff --git a/0834-sum-of-distances-in-tree/README.md b/final/0834-sum-of-distances-in-tree.html similarity index 100% rename from 0834-sum-of-distances-in-tree/README.md rename to final/0834-sum-of-distances-in-tree.html diff --git a/final/0840-magic-squares-in-grid.html b/final/0840-magic-squares-in-grid.html new file mode 100644 index 000000000..06ddc8d22 --- /dev/null +++ b/final/0840-magic-squares-in-grid.html @@ -0,0 +1,35 @@ +

840. Magic Squares In Grid

Medium


A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.

+ +

Given a row x col grid of integers, how many 3 x 3 contiguous magic square subgrids are there?

+ +

Note: while a magic square can only contain numbers from 1 to 9, grid may contain numbers up to 15.

+ +

 

+

Example 1:

+ +
Input: grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]]
+Output: 1
+Explanation: 
+The following subgrid is a 3 x 3 magic square:
+
+while this one is not:
+
+In total, there is only one magic square inside the given grid.
+
+ +

Example 2:

+ +
Input: grid = [[8]]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • row == grid.length
  • +
  • col == grid[i].length
  • +
  • 1 <= row, col <= 10
  • +
  • 0 <= grid[i][j] <= 15
  • +
+
\ No newline at end of file diff --git a/0844-backspace-string-compare/README.md b/final/0844-backspace-string-compare.html similarity index 100% rename from 0844-backspace-string-compare/README.md rename to final/0844-backspace-string-compare.html diff --git a/0846-hand-of-straights/README.md b/final/0846-hand-of-straights.html similarity index 100% rename from 0846-hand-of-straights/README.md rename to final/0846-hand-of-straights.html diff --git a/0847-shortest-path-visiting-all-nodes/README.md b/final/0847-shortest-path-visiting-all-nodes.html similarity index 100% rename from 0847-shortest-path-visiting-all-nodes/README.md rename to final/0847-shortest-path-visiting-all-nodes.html diff --git a/final/0852-peak-index-in-a-mountain-array.html b/final/0852-peak-index-in-a-mountain-array.html new file mode 100644 index 000000000..e6e7ee11e --- /dev/null +++ b/final/0852-peak-index-in-a-mountain-array.html @@ -0,0 +1,44 @@ +

852. Peak Index in a Mountain Array

Medium


An array arr a mountain if the following properties hold:

+ +
    +
  • arr.length >= 3
  • +
  • There exists some i with 0 < i < arr.length - 1 such that: +
      +
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • +
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • +
    +
  • +
+ +

Given a mountain array arr, return the index i such that arr[0] < arr[1] < ... < arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

+ +

You must solve it in O(log(arr.length)) time complexity.

+ +

 

+

Example 1:

+ +
Input: arr = [0,1,0]
+Output: 1
+
+ +

Example 2:

+ +
Input: arr = [0,2,1,0]
+Output: 1
+
+ +

Example 3:

+ +
Input: arr = [0,10,5,2]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= arr.length <= 105
  • +
  • 0 <= arr[i] <= 106
  • +
  • arr is guaranteed to be a mountain array.
  • +
+
\ No newline at end of file diff --git a/0857-minimum-cost-to-hire-k-workers/README.md b/final/0857-minimum-cost-to-hire-k-workers.html similarity index 100% rename from 0857-minimum-cost-to-hire-k-workers/README.md rename to final/0857-minimum-cost-to-hire-k-workers.html diff --git a/0860-lemonade-change/README.md b/final/0860-lemonade-change.html similarity index 100% rename from 0860-lemonade-change/README.md rename to final/0860-lemonade-change.html diff --git a/0861-score-after-flipping-matrix/README.md b/final/0861-score-after-flipping-matrix.html similarity index 100% rename from 0861-score-after-flipping-matrix/README.md rename to final/0861-score-after-flipping-matrix.html diff --git a/0867-transpose-matrix/README.md b/final/0867-transpose-matrix.html similarity index 100% rename from 0867-transpose-matrix/README.md rename to final/0867-transpose-matrix.html diff --git a/0872-leaf-similar-trees/README.md b/final/0872-leaf-similar-trees.html similarity index 100% rename from 0872-leaf-similar-trees/README.md rename to final/0872-leaf-similar-trees.html diff --git a/final/0875-koko-eating-bananas.html b/final/0875-koko-eating-bananas.html new file mode 100644 index 000000000..c6eea5f5b --- /dev/null +++ b/final/0875-koko-eating-bananas.html @@ -0,0 +1,36 @@ +

875. Koko Eating Bananas

Medium


Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.

+ +

Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.

+ +

Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.

+ +

Return the minimum integer k such that she can eat all the bananas within h hours.

+ +

 

+

Example 1:

+ +
Input: piles = [3,6,7,11], h = 8
+Output: 4
+
+ +

Example 2:

+ +
Input: piles = [30,11,23,4,20], h = 5
+Output: 30
+
+ +

Example 3:

+ +
Input: piles = [30,11,23,4,20], h = 6
+Output: 23
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= piles.length <= 104
  • +
  • piles.length <= h <= 109
  • +
  • 1 <= piles[i] <= 109
  • +
+
\ No newline at end of file diff --git a/0876-middle-of-the-linked-list/README.md b/final/0876-middle-of-the-linked-list.html similarity index 100% rename from 0876-middle-of-the-linked-list/README.md rename to final/0876-middle-of-the-linked-list.html diff --git a/0880-decoded-string-at-index/README.md b/final/0880-decoded-string-at-index.html similarity index 100% rename from 0880-decoded-string-at-index/README.md rename to final/0880-decoded-string-at-index.html diff --git a/final/0881-boats-to-save-people.html b/final/0881-boats-to-save-people.html new file mode 100644 index 000000000..b45da2bea --- /dev/null +++ b/final/0881-boats-to-save-people.html @@ -0,0 +1,34 @@ +

881. Boats to Save People

Medium


You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.

+ +

Return the minimum number of boats to carry every given person.

+ +

 

+

Example 1:

+ +
Input: people = [1,2], limit = 3
+Output: 1
+Explanation: 1 boat (1, 2)
+
+ +

Example 2:

+ +
Input: people = [3,2,2,1], limit = 3
+Output: 3
+Explanation: 3 boats (1, 2), (2) and (3)
+
+ +

Example 3:

+ +
Input: people = [3,5,3,4], limit = 5
+Output: 4
+Explanation: 4 boats (3), (3), (4), (5)
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= people.length <= 5 * 104
  • +
  • 1 <= people[i] <= limit <= 3 * 104
  • +
+
\ No newline at end of file diff --git a/final/0885-spiral-matrix-iii.html b/final/0885-spiral-matrix-iii.html new file mode 100644 index 000000000..721d4ed3e --- /dev/null +++ b/final/0885-spiral-matrix-iii.html @@ -0,0 +1,28 @@ +

885. Spiral Matrix III

Medium


You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.

+ +

You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's boundary, we continue our walk outside the grid (but may return to the grid boundary later.). Eventually, we reach all rows * cols spaces of the grid.

+ +

Return an array of coordinates representing the positions of the grid in the order you visited them.

+ +

 

+

Example 1:

+ +
Input: rows = 1, cols = 4, rStart = 0, cStart = 0
+Output: [[0,0],[0,1],[0,2],[0,3]]
+
+ +

Example 2:

+ +
Input: rows = 5, cols = 6, rStart = 1, cStart = 4
+Output: [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= rows, cols <= 100
  • +
  • 0 <= rStart < rows
  • +
  • 0 <= cStart < cols
  • +
+
\ No newline at end of file diff --git a/0888-fair-candy-swap/README.md b/final/0888-fair-candy-swap.html similarity index 100% rename from 0888-fair-candy-swap/README.md rename to final/0888-fair-candy-swap.html diff --git a/final/0894-all-possible-full-binary-trees.html b/final/0894-all-possible-full-binary-trees.html new file mode 100644 index 000000000..6a00abbe6 --- /dev/null +++ b/final/0894-all-possible-full-binary-trees.html @@ -0,0 +1,26 @@ +

894. All Possible Full Binary Trees

Medium


Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0.

+ +

Each element of the answer is the root node of one possible tree. You may return the final list of trees in any order.

+ +

A full binary tree is a binary tree where each node has exactly 0 or 2 children.

+ +

 

+

Example 1:

+ +
Input: n = 7
+Output: [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]
+
+ +

Example 2:

+ +
Input: n = 3
+Output: [[0,0,0]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 20
  • +
+
\ No newline at end of file diff --git a/0896-monotonic-array/README.md b/final/0896-monotonic-array.html similarity index 100% rename from 0896-monotonic-array/README.md rename to final/0896-monotonic-array.html diff --git a/0905-sort-array-by-parity/README.md b/final/0905-sort-array-by-parity.html similarity index 100% rename from 0905-sort-array-by-parity/README.md rename to final/0905-sort-array-by-parity.html diff --git a/final/0907-sum-of-subarray-minimums.html b/final/0907-sum-of-subarray-minimums.html new file mode 100644 index 000000000..6cc631137 --- /dev/null +++ b/final/0907-sum-of-subarray-minimums.html @@ -0,0 +1,27 @@ +

907. Sum of Subarray Minimums

Medium


Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: arr = [3,1,2,4]
+Output: 17
+Explanation: 
+Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]. 
+Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.
+Sum is 17.
+
+ +

Example 2:

+ +
Input: arr = [11,81,94,43,3]
+Output: 444
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 3 * 104
  • +
  • 1 <= arr[i] <= 3 * 104
  • +
+
\ No newline at end of file diff --git a/final/0912-sort-an-array.html b/final/0912-sort-an-array.html new file mode 100644 index 000000000..9b50c6179 --- /dev/null +++ b/final/0912-sort-an-array.html @@ -0,0 +1,27 @@ +

912. Sort an Array

Medium


Given an array of integers nums, sort the array in ascending order and return it.

+ +

You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.

+ +

 

+

Example 1:

+ +
Input: nums = [5,2,3,1]
+Output: [1,2,3,5]
+Explanation: After sorting the array, the positions of some numbers are not changed (for example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).
+
+ +

Example 2:

+ +
Input: nums = [5,1,1,2,0,0]
+Output: [0,0,1,1,2,5]
+Explanation: Note that the values of nums are not necessairly unique.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • -5 * 104 <= nums[i] <= 5 * 104
  • +
+
\ No newline at end of file diff --git a/0920-number-of-music-playlists/README.md b/final/0920-number-of-music-playlists.html similarity index 100% rename from 0920-number-of-music-playlists/README.md rename to final/0920-number-of-music-playlists.html diff --git a/final/0930-binary-subarrays-with-sum.html b/final/0930-binary-subarrays-with-sum.html new file mode 100644 index 000000000..63710621b --- /dev/null +++ b/final/0930-binary-subarrays-with-sum.html @@ -0,0 +1,30 @@ +

930. Binary Subarrays With Sum

Medium


Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.

+ +

A subarray is a contiguous part of the array.

+ +

 

+

Example 1:

+ +
Input: nums = [1,0,1,0,1], goal = 2
+Output: 4
+Explanation: The 4 subarrays are bolded and underlined below:
+[1,0,1,0,1]
+[1,0,1,0,1]
+[1,0,1,0,1]
+[1,0,1,0,1]
+
+ +

Example 2:

+ +
Input: nums = [0,0,0,0,0], goal = 0
+Output: 15
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • nums[i] is either 0 or 1.
  • +
  • 0 <= goal <= nums.length
  • +
\ No newline at end of file diff --git a/0931-minimum-falling-path-sum/README.md b/final/0931-minimum-falling-path-sum.html similarity index 100% rename from 0931-minimum-falling-path-sum/README.md rename to final/0931-minimum-falling-path-sum.html diff --git a/0935-knight-dialer/README.md b/final/0935-knight-dialer.html similarity index 100% rename from 0935-knight-dialer/README.md rename to final/0935-knight-dialer.html diff --git a/0938-range-sum-of-bst/README.md b/final/0938-range-sum-of-bst.html similarity index 100% rename from 0938-range-sum-of-bst/README.md rename to final/0938-range-sum-of-bst.html diff --git a/final/0945-minimum-increment-to-make-array-unique.html b/final/0945-minimum-increment-to-make-array-unique.html new file mode 100644 index 000000000..b81b99e4a --- /dev/null +++ b/final/0945-minimum-increment-to-make-array-unique.html @@ -0,0 +1,30 @@ +

945. Minimum Increment to Make Array Unique

Medium


You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.

+ +

Return the minimum number of moves to make every value in nums unique.

+ +

The test cases are generated so that the answer fits in a 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,2]
+Output: 1
+Explanation: After 1 move, the array could be [1, 2, 3].
+
+ +

Example 2:

+ +
Input: nums = [3,2,1,2,1,7]
+Output: 6
+Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
+It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/final/0948-bag-of-tokens.html b/final/0948-bag-of-tokens.html new file mode 100644 index 000000000..968d02c52 --- /dev/null +++ b/final/0948-bag-of-tokens.html @@ -0,0 +1,106 @@ +

948. Bag of Tokens

Medium


You start with an initial power of power, an initial score of 0, and a bag of tokens given as an integer array tokens, where each tokens[i] donates the value of tokeni.

+ +

Your goal is to maximize the total score by strategically playing these tokens. In one move, you can play an unplayed token in one of the two ways (but not both for the same token):

+ +
    +
  • Face-up: If your current power is at least tokens[i], you may play tokeni, losing tokens[i] power and gaining 1 score.
  • +
  • Face-down: If your current score is at least 1, you may play tokeni, gaining tokens[i] power and losing 1 score.
  • +
+ +

Return the maximum possible score you can achieve after playing any number of tokens.

+ +

 

+

Example 1:

+ +
+

Input: tokens = [100], power = 50

+ +

Output: 0

+ +

Explanation: Since your score is 0 initially, you cannot play the token face-down. You also cannot play it face-up since your power (50) is less than tokens[0] (100).

+
+ +

Example 2:

+ +
+

Input: tokens = [200,100], power = 150

+ +

Output: 1

+ +

Explanation: Play token1 (100) face-up, reducing your power to 50 and increasing your score to 1.

+ +

There is no need to play token0, since you cannot play it face-up to add to your score. The maximum score achievable is 1.

+
+ +

Example 3:

+ +
+

Input: tokens = [100,200,300,400], power = 200

+ +

Output: 2

+ +

Explanation: Play the tokens in this order to get a score of 2:

+ +
    +
  1. Play token0 (100) face-up, reducing power to 100 and increasing score to 1.
  2. +
  3. Play token3 (400) face-down, increasing power to 500 and reducing score to 0.
  4. +
  5. Play token1 (200) face-up, reducing power to 300 and increasing score to 1.
  6. +
  7. Play token2 (300) face-up, reducing power to 0 and increasing score to 2.
  8. +
+ +

The maximum score achievable is 2.

+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= tokens.length <= 1000
  • +
  • 0 <= tokens[i], power < 104
  • +
+
\ No newline at end of file diff --git a/final/0950-reveal-cards-in-increasing-order.html b/final/0950-reveal-cards-in-increasing-order.html new file mode 100644 index 000000000..8fd4c765e --- /dev/null +++ b/final/0950-reveal-cards-in-increasing-order.html @@ -0,0 +1,49 @@ +

950. Reveal Cards In Increasing Order

Medium


You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i].

+ +

You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck.

+ +

You will do the following steps repeatedly until all cards are revealed:

+ +
    +
  1. Take the top card of the deck, reveal it, and take it out of the deck.
  2. +
  3. If there are still cards in the deck then put the next top card of the deck at the bottom of the deck.
  4. +
  5. If there are still unrevealed cards, go back to step 1. Otherwise, stop.
  6. +
+ +

Return an ordering of the deck that would reveal the cards in increasing order.

+ +

Note that the first entry in the answer is considered to be the top of the deck.

+ +

 

+

Example 1:

+ +
Input: deck = [17,13,11,2,3,5,7]
+Output: [2,13,3,11,5,17,7]
+Explanation: 
+We get the deck in the order [17,13,11,2,3,5,7] (this order does not matter), and reorder it.
+After reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.
+We reveal 2, and move 13 to the bottom.  The deck is now [3,11,5,17,7,13].
+We reveal 3, and move 11 to the bottom.  The deck is now [5,17,7,13,11].
+We reveal 5, and move 17 to the bottom.  The deck is now [7,13,11,17].
+We reveal 7, and move 13 to the bottom.  The deck is now [11,17,13].
+We reveal 11, and move 17 to the bottom.  The deck is now [13,17].
+We reveal 13, and move 17 to the bottom.  The deck is now [17].
+We reveal 17.
+Since all the cards revealed are in increasing order, the answer is correct.
+
+ +

Example 2:

+ +
Input: deck = [1,1000]
+Output: [1,1000]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= deck.length <= 1000
  • +
  • 1 <= deck[i] <= 106
  • +
  • All the values of deck are unique.
  • +
+
\ No newline at end of file diff --git a/final/0959-regions-cut-by-slashes.html b/final/0959-regions-cut-by-slashes.html new file mode 100644 index 000000000..fc2c5d3bc --- /dev/null +++ b/final/0959-regions-cut-by-slashes.html @@ -0,0 +1,35 @@ +

959. Regions Cut By Slashes

Medium


An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions.

+ +

Given the grid grid represented as a string array, return the number of regions.

+ +

Note that backslash characters are escaped, so a '\' is represented as '\\'.

+ +

 

+

Example 1:

+ +
Input: grid = [" /","/ "]
+Output: 2
+
+ +

Example 2:

+ +
Input: grid = [" /","  "]
+Output: 1
+
+ +

Example 3:

+ +
Input: grid = ["/\\","\\/"]
+Output: 5
+Explanation: Recall that because \ characters are escaped, "\\/" refers to \/, and "/\\" refers to /\.
+
+ +

 

+

Constraints:

+ +
    +
  • n == grid.length == grid[i].length
  • +
  • 1 <= n <= 30
  • +
  • grid[i][j] is either '/', '\', or ' '.
  • +
+
\ No newline at end of file diff --git a/final/0973-k-closest-points-to-origin.html b/final/0973-k-closest-points-to-origin.html new file mode 100644 index 000000000..0c45639c6 --- /dev/null +++ b/final/0973-k-closest-points-to-origin.html @@ -0,0 +1,33 @@ +

973. K Closest Points to Origin

Medium


Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).

+ +

The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2).

+ +

You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).

+ +

 

+

Example 1:

+ +
Input: points = [[1,3],[-2,2]], k = 1
+Output: [[-2,2]]
+Explanation:
+The distance between (1, 3) and the origin is sqrt(10).
+The distance between (-2, 2) and the origin is sqrt(8).
+Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
+We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].
+
+ +

Example 2:

+ +
Input: points = [[3,3],[5,-1],[-2,4]], k = 2
+Output: [[3,3],[-2,4]]
+Explanation: The answer [[-2,4],[3,3]] would also be accepted.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= points.length <= 104
  • +
  • -104 < xi, yi < 104
  • +
+
\ No newline at end of file diff --git a/final/0974-subarray-sums-divisible-by-k.html b/final/0974-subarray-sums-divisible-by-k.html new file mode 100644 index 000000000..af732be78 --- /dev/null +++ b/final/0974-subarray-sums-divisible-by-k.html @@ -0,0 +1,28 @@ +

974. Subarray Sums Divisible by K

Medium


Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.

+ +

A subarray is a contiguous part of an array.

+ +

 

+

Example 1:

+ +
Input: nums = [4,5,0,-2,-3,1], k = 5
+Output: 7
+Explanation: There are 7 subarrays with a sum divisible by k = 5:
+[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
+
+ +

Example 2:

+ +
Input: nums = [5], k = 9
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • -104 <= nums[i] <= 104
  • +
  • 2 <= k <= 104
  • +
+
\ No newline at end of file diff --git a/0977-squares-of-a-sorted-array/README.md b/final/0977-squares-of-a-sorted-array.html similarity index 100% rename from 0977-squares-of-a-sorted-array/README.md rename to final/0977-squares-of-a-sorted-array.html diff --git a/final/0979-distribute-coins-in-binary-tree.html b/final/0979-distribute-coins-in-binary-tree.html new file mode 100644 index 000000000..e7b0415a9 --- /dev/null +++ b/final/0979-distribute-coins-in-binary-tree.html @@ -0,0 +1,31 @@ +

979. Distribute Coins in Binary Tree

Medium


You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.

+ +

In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent.

+ +

Return the minimum number of moves required to make every node have exactly one coin.

+ +

 

+

Example 1:

+ +
Input: root = [3,0,0]
+Output: 2
+Explanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.
+
+ +

Example 2:

+ +
Input: root = [0,3,0]
+Output: 3
+Explanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is n.
  • +
  • 1 <= n <= 100
  • +
  • 0 <= Node.val <= n
  • +
  • The sum of all Node.val is n.
  • +
+
\ No newline at end of file diff --git a/final/0981-time-based-key-value-store.html b/final/0981-time-based-key-value-store.html new file mode 100644 index 000000000..2aa380da2 --- /dev/null +++ b/final/0981-time-based-key-value-store.html @@ -0,0 +1,40 @@ +

981. Time Based Key-Value Store

Medium


Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.

+ +

Implement the TimeMap class:

+ +
    +
  • TimeMap() Initializes the object of the data structure.
  • +
  • void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp.
  • +
  • String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp. If there are multiple such values, it returns the value associated with the largest timestamp_prev. If there are no values, it returns "".
  • +
+ +

 

+

Example 1:

+ +
Input
+["TimeMap", "set", "get", "get", "set", "get", "get"]
+[[], ["foo", "bar", 1], ["foo", 1], ["foo", 3], ["foo", "bar2", 4], ["foo", 4], ["foo", 5]]
+Output
+[null, null, "bar", "bar", null, "bar2", "bar2"]
+
+Explanation
+TimeMap timeMap = new TimeMap();
+timeMap.set("foo", "bar", 1);  // store the key "foo" and value "bar" along with timestamp = 1.
+timeMap.get("foo", 1);         // return "bar"
+timeMap.get("foo", 3);         // return "bar", since there is no value corresponding to foo at timestamp 3 and timestamp 2, then the only value is at timestamp 1 is "bar".
+timeMap.set("foo", "bar2", 4); // store the key "foo" and value "bar2" along with timestamp = 4.
+timeMap.get("foo", 4);         // return "bar2"
+timeMap.get("foo", 5);         // return "bar2"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= key.length, value.length <= 100
  • +
  • key and value consist of lowercase English letters and digits.
  • +
  • 1 <= timestamp <= 107
  • +
  • All the timestamps timestamp of set are strictly increasing.
  • +
  • At most 2 * 105 calls will be made to set and get.
  • +
+
\ No newline at end of file diff --git a/0988-smallest-string-starting-from-leaf/README.md b/final/0988-smallest-string-starting-from-leaf.html similarity index 100% rename from 0988-smallest-string-starting-from-leaf/README.md rename to final/0988-smallest-string-starting-from-leaf.html diff --git a/0992-subarrays-with-k-different-integers/README.md b/final/0992-subarrays-with-k-different-integers.html similarity index 100% rename from 0992-subarrays-with-k-different-integers/README.md rename to final/0992-subarrays-with-k-different-integers.html diff --git a/final/0994-rotting-oranges.html b/final/0994-rotting-oranges.html new file mode 100644 index 000000000..1eb3cfc3c --- /dev/null +++ b/final/0994-rotting-oranges.html @@ -0,0 +1,43 @@ +

994. Rotting Oranges

Medium


You are given an m x n grid where each cell can have one of three values:

+ +
    +
  • 0 representing an empty cell,
  • +
  • 1 representing a fresh orange, or
  • +
  • 2 representing a rotten orange.
  • +
+ +

Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.

+ +

Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1.

+ +

 

+

Example 1:

+ +
Input: grid = [[2,1,1],[1,1,0],[0,1,1]]
+Output: 4
+
+ +

Example 2:

+ +
Input: grid = [[2,1,1],[0,1,1],[1,0,1]]
+Output: -1
+Explanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.
+
+ +

Example 3:

+ +
Input: grid = [[0,2]]
+Output: 0
+Explanation: Since there are already no fresh oranges at minute 0, the answer is just 0.
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 10
  • +
  • grid[i][j] is 0, 1, or 2.
  • +
+
\ No newline at end of file diff --git a/0995-minimum-number-of-k-consecutive-bit-flips/README.md b/final/0995-minimum-number-of-k-consecutive-bit-flips.html similarity index 100% rename from 0995-minimum-number-of-k-consecutive-bit-flips/README.md rename to final/0995-minimum-number-of-k-consecutive-bit-flips.html diff --git a/0997-find-the-town-judge/README.md b/final/0997-find-the-town-judge.html similarity index 100% rename from 0997-find-the-town-judge/README.md rename to final/0997-find-the-town-judge.html diff --git a/1002-find-common-characters/README.md b/final/1002-find-common-characters.html similarity index 100% rename from 1002-find-common-characters/README.md rename to final/1002-find-common-characters.html diff --git a/final/1026-maximum-difference-between-node-and-ancestor.html b/final/1026-maximum-difference-between-node-and-ancestor.html new file mode 100644 index 000000000..67c353c51 --- /dev/null +++ b/final/1026-maximum-difference-between-node-and-ancestor.html @@ -0,0 +1,30 @@ +

1026. Maximum Difference Between Node and Ancestor

Medium


Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b.

+ +

A node a is an ancestor of b if either: any child of a is equal to b or any child of a is an ancestor of b.

+ +

 

+

Example 1:

+ +
Input: root = [8,3,10,1,6,null,14,null,null,4,7,13]
+Output: 7
+Explanation: We have various ancestor-node differences, some of which are given below :
+|8 - 3| = 5
+|3 - 7| = 4
+|8 - 1| = 7
+|10 - 13| = 3
+Among all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.
+ +

Example 2:

+ +
Input: root = [1,null,2,null,0,3]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [2, 5000].
  • +
  • 0 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/final/1038-binary-search-tree-to-greater-sum-tree.html b/final/1038-binary-search-tree-to-greater-sum-tree.html new file mode 100644 index 000000000..e69de29bb diff --git a/1043-partition-array-for-maximum-sum/README.md b/final/1043-partition-array-for-maximum-sum.html similarity index 100% rename from 1043-partition-array-for-maximum-sum/README.md rename to final/1043-partition-array-for-maximum-sum.html diff --git a/1046-last-stone-weight/README.md b/final/1046-last-stone-weight.html similarity index 100% rename from 1046-last-stone-weight/README.md rename to final/1046-last-stone-weight.html diff --git a/1048-longest-string-chain/README.md b/final/1048-longest-string-chain.html similarity index 100% rename from 1048-longest-string-chain/README.md rename to final/1048-longest-string-chain.html diff --git a/1051-height-checker/README.md b/final/1051-height-checker.html similarity index 100% rename from 1051-height-checker/README.md rename to final/1051-height-checker.html diff --git a/final/1052-grumpy-bookstore-owner.html b/final/1052-grumpy-bookstore-owner.html new file mode 100644 index 000000000..dce57e167 --- /dev/null +++ b/final/1052-grumpy-bookstore-owner.html @@ -0,0 +1,35 @@ +

1052. Grumpy Bookstore Owner

Medium


There is a bookstore owner that has a store open for n minutes. Every minute, some number of customers enter the store. You are given an integer array customers of length n where customers[i] is the number of the customer that enters the store at the start of the ith minute and all those customers leave after the end of that minute.

+ +

On some minutes, the bookstore owner is grumpy. You are given a binary array grumpy where grumpy[i] is 1 if the bookstore owner is grumpy during the ith minute, and is 0 otherwise.

+ +

When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise, they are satisfied.

+ +

The bookstore owner knows a secret technique to keep themselves not grumpy for minutes consecutive minutes, but can only use it once.

+ +

Return the maximum number of customers that can be satisfied throughout the day.

+ +

 

+

Example 1:

+ +
Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
+Output: 16
+Explanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. 
+The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
+
+ +

Example 2:

+ +
Input: customers = [1], grumpy = [0], minutes = 1
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • n == customers.length == grumpy.length
  • +
  • 1 <= minutes <= n <= 2 * 104
  • +
  • 0 <= customers[i] <= 1000
  • +
  • grumpy[i] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/1057-campus-bikes/README.md b/final/1057-campus-bikes.html similarity index 100% rename from 1057-campus-bikes/README.md rename to final/1057-campus-bikes.html diff --git a/final/1060-missing-element-in-sorted-array.html b/final/1060-missing-element-in-sorted-array.html new file mode 100644 index 000000000..c6258e4d0 --- /dev/null +++ b/final/1060-missing-element-in-sorted-array.html @@ -0,0 +1,36 @@ +

1060. Missing Element in Sorted Array

Medium


Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.

+ +

 

+

Example 1:

+ +
Input: nums = [4,7,9,10], k = 1
+Output: 5
+Explanation: The first missing number is 5.
+
+ +

Example 2:

+ +
Input: nums = [4,7,9,10], k = 3
+Output: 8
+Explanation: The missing numbers are [5,6,8,...], hence the third missing number is 8.
+
+ +

Example 3:

+ +
Input: nums = [1,2,4], k = 3
+Output: 6
+Explanation: The missing numbers are [3,5,6,7,...], hence the third missing number is 6.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • 1 <= nums[i] <= 107
  • +
  • nums is sorted in ascending order, and all the elements are unique.
  • +
  • 1 <= k <= 108
  • +
+ +

 

+Follow up: Can you find a logarithmic time complexity (i.e., O(log(n))) solution?
\ No newline at end of file diff --git a/final/1062-longest-repeating-substring.html b/final/1062-longest-repeating-substring.html new file mode 100644 index 000000000..93f6a590b --- /dev/null +++ b/final/1062-longest-repeating-substring.html @@ -0,0 +1,32 @@ +

1062. Longest Repeating Substring

Medium


Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.

+ +

 

+

Example 1:

+ +
Input: s = "abcd"
+Output: 0
+Explanation: There is no repeating substring.
+
+ +

Example 2:

+ +
Input: s = "abbaba"
+Output: 2
+Explanation: The longest repeating substrings are "ab" and "ba", each of which occurs twice.
+
+ +

Example 3:

+ +
Input: s = "aabcaabdaab"
+Output: 3
+Explanation: The longest repeating substring is "aab", which occurs 3 times.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 2000
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1063-number-of-valid-subarrays/README.md b/final/1063-number-of-valid-subarrays.html similarity index 100% rename from 1063-number-of-valid-subarrays/README.md rename to final/1063-number-of-valid-subarrays.html diff --git a/1066-campus-bikes-ii/README.md b/final/1066-campus-bikes-ii.html similarity index 100% rename from 1066-campus-bikes-ii/README.md rename to final/1066-campus-bikes-ii.html diff --git a/1071-greatest-common-divisor-of-strings/README.md b/final/1071-greatest-common-divisor-of-strings.html similarity index 100% rename from 1071-greatest-common-divisor-of-strings/README.md rename to final/1071-greatest-common-divisor-of-strings.html diff --git a/1074-number-of-submatrices-that-sum-to-target/README.md b/final/1074-number-of-submatrices-that-sum-to-target.html similarity index 100% rename from 1074-number-of-submatrices-that-sum-to-target/README.md rename to final/1074-number-of-submatrices-that-sum-to-target.html diff --git a/1095-find-in-mountain-array/README.md b/final/1095-find-in-mountain-array.html similarity index 100% rename from 1095-find-in-mountain-array/README.md rename to final/1095-find-in-mountain-array.html diff --git a/1099-two-sum-less-than-k/README.md b/final/1099-two-sum-less-than-k.html similarity index 100% rename from 1099-two-sum-less-than-k/README.md rename to final/1099-two-sum-less-than-k.html diff --git a/1101-the-earliest-moment-when-everyone-become-friends/README.md b/final/1101-the-earliest-moment-when-everyone-become-friends.html similarity index 100% rename from 1101-the-earliest-moment-when-everyone-become-friends/README.md rename to final/1101-the-earliest-moment-when-everyone-become-friends.html diff --git a/final/1105-filling-bookcase-shelves.html b/final/1105-filling-bookcase-shelves.html new file mode 100644 index 000000000..a85820e4e --- /dev/null +++ b/final/1105-filling-bookcase-shelves.html @@ -0,0 +1,39 @@ +

1105. Filling Bookcase Shelves

Medium


You are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the ith book. You are also given an integer shelfWidth.

+ +

We want to place these books in order onto bookcase shelves that have a total width shelfWidth.

+ +

We choose some of the books to place on this shelf such that the sum of their thickness is less than or equal to shelfWidth, then build another level of the shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down. We repeat this process until there are no more books to place.

+ +

Note that at each step of the above process, the order of the books we place is the same order as the given sequence of books.

+ +
    +
  • For example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.
  • +
+ +

Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.

+ +

 

+

Example 1:

+ +
Input: books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelfWidth = 4
+Output: 6
+Explanation:
+The sum of the heights of the 3 shelves is 1 + 3 + 2 = 6.
+Notice that book number 2 does not have to be on the first shelf.
+
+ +

Example 2:

+ +
Input: books = [[1,3],[2,4],[3,2]], shelfWidth = 6
+Output: 4
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= books.length <= 1000
  • +
  • 1 <= thicknessi <= shelfWidth <= 1000
  • +
  • 1 <= heighti <= 1000
  • +
+
\ No newline at end of file diff --git a/1110-delete-nodes-and-return-forest/README.md b/final/1110-delete-nodes-and-return-forest.html similarity index 100% rename from 1110-delete-nodes-and-return-forest/README.md rename to final/1110-delete-nodes-and-return-forest.html diff --git a/1119-remove-vowels-from-a-string/README.md b/final/1119-remove-vowels-from-a-string.html similarity index 100% rename from 1119-remove-vowels-from-a-string/README.md rename to final/1119-remove-vowels-from-a-string.html diff --git a/final/1120-maximum-average-subtree.html b/final/1120-maximum-average-subtree.html new file mode 100644 index 000000000..1b9575cff --- /dev/null +++ b/final/1120-maximum-average-subtree.html @@ -0,0 +1,32 @@ +

1120. Maximum Average Subtree

Medium


Given the root of a binary tree, return the maximum average value of a subtree of that tree. Answers within 10-5 of the actual answer will be accepted.

+ +

A subtree of a tree is any node of that tree plus all its descendants.

+ +

The average value of a tree is the sum of its values, divided by the number of nodes.

+ +

 

+

Example 1:

+ +
Input: root = [5,6,1]
+Output: 6.00000
+Explanation: 
+For the node with value = 5 we have an average of (5 + 6 + 1) / 3 = 4.
+For the node with value = 6 we have an average of 6 / 1 = 6.
+For the node with value = 1 we have an average of 1 / 1 = 1.
+So the answer is 6 which is the maximum.
+
+ +

Example 2:

+ +
Input: root = [0,null,1]
+Output: 1.00000
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • 0 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/1122-relative-sort-array/README.md b/final/1122-relative-sort-array.html similarity index 100% rename from 1122-relative-sort-array/README.md rename to final/1122-relative-sort-array.html diff --git a/1136-parallel-courses/README.md b/final/1136-parallel-courses.html similarity index 100% rename from 1136-parallel-courses/README.md rename to final/1136-parallel-courses.html diff --git a/1137-n-th-tribonacci-number/README.md b/final/1137-n-th-tribonacci-number.html similarity index 100% rename from 1137-n-th-tribonacci-number/README.md rename to final/1137-n-th-tribonacci-number.html diff --git a/final/1140-stone-game-ii.html b/final/1140-stone-game-ii.html new file mode 100644 index 000000000..7add6be15 --- /dev/null +++ b/final/1140-stone-game-ii.html @@ -0,0 +1,32 @@ +

1140. Stone Game II

Medium


Alice and Bob continue their games with piles of stones.  There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].  The objective of the game is to end with the most stones. 

+ +

Alice and Bob take turns, with Alice starting first.  Initially, M = 1.

+ +

On each player's turn, that player can take all the stones in the first X remaining piles, where 1 <= X <= 2M.  Then, we set M = max(M, X).

+ +

The game continues until all the stones have been taken.

+ +

Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.

+ +

 

+

Example 1:

+ +
Input: piles = [2,7,9,4,4]
+Output: 10
+Explanation:  If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 piles in total. If Alice takes two piles at the beginning, then Bob can take all three piles left. In this case, Alice get 2 + 7 = 9 piles in total. So we return 10 since it's larger. 
+
+ +

Example 2:

+ +
Input: piles = [1,2,3,4,5,100]
+Output: 104
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= piles.length <= 100
  • +
  • 1 <= piles[i] <= 104
  • +
+
\ No newline at end of file diff --git a/final/1143-longest-common-subsequence.html b/final/1143-longest-common-subsequence.html new file mode 100644 index 000000000..41371569a --- /dev/null +++ b/final/1143-longest-common-subsequence.html @@ -0,0 +1,40 @@ +

1143. Longest Common Subsequence

Medium


Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

+ +

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

+ +
    +
  • For example, "ace" is a subsequence of "abcde".
  • +
+ +

A common subsequence of two strings is a subsequence that is common to both strings.

+ +

 

+

Example 1:

+ +
Input: text1 = "abcde", text2 = "ace" 
+Output: 3  
+Explanation: The longest common subsequence is "ace" and its length is 3.
+
+ +

Example 2:

+ +
Input: text1 = "abc", text2 = "abc"
+Output: 3
+Explanation: The longest common subsequence is "abc" and its length is 3.
+
+ +

Example 3:

+ +
Input: text1 = "abc", text2 = "def"
+Output: 0
+Explanation: There is no such common subsequence, so the result is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= text1.length, text2.length <= 1000
  • +
  • text1 and text2 consist of only lowercase English characters.
  • +
+
\ No newline at end of file diff --git a/1148-article-views-i/README.md b/final/1148-article-views-i.html similarity index 100% rename from 1148-article-views-i/README.md rename to final/1148-article-views-i.html diff --git a/final/1155-number-of-dice-rolls-with-target-sum.html b/final/1155-number-of-dice-rolls-with-target-sum.html new file mode 100644 index 000000000..19dd039a7 --- /dev/null +++ b/final/1155-number-of-dice-rolls-with-target-sum.html @@ -0,0 +1,36 @@ +

1155. Number of Dice Rolls With Target Sum

Medium


You have n dice, and each die has k faces numbered from 1 to k.

+ +

Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 1, k = 6, target = 3
+Output: 1
+Explanation: You throw one die with 6 faces.
+There is only one way to get a sum of 3.
+
+ +

Example 2:

+ +
Input: n = 2, k = 6, target = 7
+Output: 6
+Explanation: You throw two dice, each with 6 faces.
+There are 6 ways to get a sum of 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1.
+
+ +

Example 3:

+ +
Input: n = 30, k = 30, target = 500
+Output: 222616187
+Explanation: The answer must be returned modulo 109 + 7.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n, k <= 30
  • +
  • 1 <= target <= 1000
  • +
+
\ No newline at end of file diff --git a/1160-find-words-that-can-be-formed-by-characters/README.md b/final/1160-find-words-that-can-be-formed-by-characters.html similarity index 100% rename from 1160-find-words-that-can-be-formed-by-characters/README.md rename to final/1160-find-words-that-can-be-formed-by-characters.html diff --git a/1165-single-row-keyboard/README.md b/final/1165-single-row-keyboard.html similarity index 100% rename from 1165-single-row-keyboard/README.md rename to final/1165-single-row-keyboard.html diff --git a/1167-minimum-cost-to-connect-sticks/README.md b/final/1167-minimum-cost-to-connect-sticks.html similarity index 100% rename from 1167-minimum-cost-to-connect-sticks/README.md rename to final/1167-minimum-cost-to-connect-sticks.html diff --git a/final/1171-remove-zero-sum-consecutive-nodes-from-linked-list.html b/final/1171-remove-zero-sum-consecutive-nodes-from-linked-list.html new file mode 100644 index 000000000..a851823fd --- /dev/null +++ b/final/1171-remove-zero-sum-consecutive-nodes-from-linked-list.html @@ -0,0 +1,34 @@ +

1171. Remove Zero Sum Consecutive Nodes from Linked List

Medium


Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences.

+ +

After doing so, return the head of the final linked list.  You may return any such answer.

+ +

 

+

(Note that in the examples below, all sequences are serializations of ListNode objects.)

+ +

Example 1:

+ +
Input: head = [1,2,-3,3,1]
+Output: [3,1]
+Note: The answer [1,2,1] would also be accepted.
+
+ +

Example 2:

+ +
Input: head = [1,2,3,-3,4]
+Output: [1,2,4]
+
+ +

Example 3:

+ +
Input: head = [1,2,3,-3,-2]
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • The given linked list will contain between 1 and 1000 nodes.
  • +
  • Each node in the linked list has -1000 <= node.val <= 1000.
  • +
+
\ No newline at end of file diff --git a/1183-maximum-number-of-ones/README.md b/final/1183-maximum-number-of-ones.html similarity index 100% rename from 1183-maximum-number-of-ones/README.md rename to final/1183-maximum-number-of-ones.html diff --git a/1190-reverse-substrings-between-each-pair-of-parentheses/README.md b/final/1190-reverse-substrings-between-each-pair-of-parentheses.html similarity index 100% rename from 1190-reverse-substrings-between-each-pair-of-parentheses/README.md rename to final/1190-reverse-substrings-between-each-pair-of-parentheses.html diff --git a/1197-minimum-knight-moves/README.md b/final/1197-minimum-knight-moves.html similarity index 100% rename from 1197-minimum-knight-moves/README.md rename to final/1197-minimum-knight-moves.html diff --git a/1199-minimum-time-to-build-blocks/README.md b/final/1199-minimum-time-to-build-blocks.html similarity index 100% rename from 1199-minimum-time-to-build-blocks/README.md rename to final/1199-minimum-time-to-build-blocks.html diff --git a/1203-sort-items-by-groups-respecting-dependencies/README.md b/final/1203-sort-items-by-groups-respecting-dependencies.html similarity index 100% rename from 1203-sort-items-by-groups-respecting-dependencies/README.md rename to final/1203-sort-items-by-groups-respecting-dependencies.html diff --git a/1207-unique-number-of-occurrences/README.md b/final/1207-unique-number-of-occurrences.html similarity index 100% rename from 1207-unique-number-of-occurrences/README.md rename to final/1207-unique-number-of-occurrences.html diff --git a/1208-get-equal-substrings-within-budget/README.md b/final/1208-get-equal-substrings-within-budget.html similarity index 100% rename from 1208-get-equal-substrings-within-budget/README.md rename to final/1208-get-equal-substrings-within-budget.html diff --git a/1216-valid-palindrome-iii/README.md b/final/1216-valid-palindrome-iii.html similarity index 100% rename from 1216-valid-palindrome-iii/README.md rename to final/1216-valid-palindrome-iii.html diff --git a/final/1219-path-with-maximum-gold.html b/final/1219-path-with-maximum-gold.html new file mode 100644 index 000000000..399cf0bda --- /dev/null +++ b/final/1219-path-with-maximum-gold.html @@ -0,0 +1,48 @@ +

1219. Path with Maximum Gold

Medium


In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.

+ +

Return the maximum amount of gold you can collect under the conditions:

+ +
    +
  • Every time you are located in a cell you will collect all the gold in that cell.
  • +
  • From your position, you can walk one step to the left, right, up, or down.
  • +
  • You can't visit the same cell more than once.
  • +
  • Never visit a cell with 0 gold.
  • +
  • You can start and stop collecting gold from any position in the grid that has some gold.
  • +
+ +

 

+

Example 1:

+ +
Input: grid = [[0,6,0],[5,8,7],[0,9,0]]
+Output: 24
+Explanation:
+[[0,6,0],
+ [5,8,7],
+ [0,9,0]]
+Path to get the maximum gold, 9 -> 8 -> 7.
+
+ +

Example 2:

+ +
Input: grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]
+Output: 28
+Explanation:
+[[1,0,7],
+ [2,0,6],
+ [3,4,5],
+ [0,3,0],
+ [9,0,20]]
+Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 15
  • +
  • 0 <= grid[i][j] <= 100
  • +
  • There are at most 25 cells containing gold.
  • +
+
\ No newline at end of file diff --git a/1220-count-vowels-permutation/README.md b/final/1220-count-vowels-permutation.html similarity index 100% rename from 1220-count-vowels-permutation/README.md rename to final/1220-count-vowels-permutation.html diff --git a/1230-toss-strange-coins/README.md b/final/1230-toss-strange-coins.html similarity index 100% rename from 1230-toss-strange-coins/README.md rename to final/1230-toss-strange-coins.html diff --git a/1235-maximum-profit-in-job-scheduling/README.md b/final/1235-maximum-profit-in-job-scheduling.html similarity index 100% rename from 1235-maximum-profit-in-job-scheduling/README.md rename to final/1235-maximum-profit-in-job-scheduling.html diff --git a/1239-maximum-length-of-a-concatenated-string-with-unique-characters/README.md b/final/1239-maximum-length-of-a-concatenated-string-with-unique-characters.html similarity index 100% rename from 1239-maximum-length-of-a-concatenated-string-with-unique-characters/README.md rename to final/1239-maximum-length-of-a-concatenated-string-with-unique-characters.html diff --git a/1245-tree-diameter/README.md b/final/1245-tree-diameter.html similarity index 100% rename from 1245-tree-diameter/README.md rename to final/1245-tree-diameter.html diff --git a/final/1248-count-number-of-nice-subarrays.html b/final/1248-count-number-of-nice-subarrays.html new file mode 100644 index 000000000..e5144d0dd --- /dev/null +++ b/final/1248-count-number-of-nice-subarrays.html @@ -0,0 +1,34 @@ +

1248. Count Number of Nice Subarrays

Medium


Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.

+ +

Return the number of nice sub-arrays.

+ +

 

+

Example 1:

+ +
Input: nums = [1,1,2,1,1], k = 3
+Output: 2
+Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
+
+ +

Example 2:

+ +
Input: nums = [2,4,6], k = 1
+Output: 0
+Explanation: There are no odd numbers in the array.
+
+ +

Example 3:

+ +
Input: nums = [2,2,2,1,2,2,1,2,2,2], k = 2
+Output: 16
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 50000
  • +
  • 1 <= nums[i] <= 10^5
  • +
  • 1 <= k <= nums.length
  • +
+
\ No newline at end of file diff --git a/final/1249-minimum-remove-to-make-valid-parentheses.html b/final/1249-minimum-remove-to-make-valid-parentheses.html new file mode 100644 index 000000000..d5ec3542c --- /dev/null +++ b/final/1249-minimum-remove-to-make-valid-parentheses.html @@ -0,0 +1,41 @@ +

1249. Minimum Remove to Make Valid Parentheses

Medium


Given a string s of '(' , ')' and lowercase English characters.

+ +

Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.

+ +

Formally, a parentheses string is valid if and only if:

+ +
    +
  • It is the empty string, contains only lowercase characters, or
  • +
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • +
  • It can be written as (A), where A is a valid string.
  • +
+ +

 

+

Example 1:

+ +
Input: s = "lee(t(c)o)de)"
+Output: "lee(t(c)o)de"
+Explanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.
+
+ +

Example 2:

+ +
Input: s = "a)b(c)d"
+Output: "ab(c)d"
+
+ +

Example 3:

+ +
Input: s = "))(("
+Output: ""
+Explanation: An empty string is also valid.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s[i] is either'(' , ')', or lowercase English letter.
  • +
+
\ No newline at end of file diff --git a/1255-maximum-score-words-formed-by-letters/README.md b/final/1255-maximum-score-words-formed-by-letters.html similarity index 100% rename from 1255-maximum-score-words-formed-by-letters/README.md rename to final/1255-maximum-score-words-formed-by-letters.html diff --git a/1265-print-immutable-linked-list-in-reverse/README.md b/final/1265-print-immutable-linked-list-in-reverse.html similarity index 100% rename from 1265-print-immutable-linked-list-in-reverse/README.md rename to final/1265-print-immutable-linked-list-in-reverse.html diff --git a/1266-minimum-time-visiting-all-points/README.md b/final/1266-minimum-time-visiting-all-points.html similarity index 100% rename from 1266-minimum-time-visiting-all-points/README.md rename to final/1266-minimum-time-visiting-all-points.html diff --git a/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/README.md b/final/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.html similarity index 100% rename from 1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/README.md rename to final/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.html diff --git a/1272-remove-interval/README.md b/final/1272-remove-interval.html similarity index 100% rename from 1272-remove-interval/README.md rename to final/1272-remove-interval.html diff --git a/final/1282-group-the-people-given-the-group-size-they-belong-to.html b/final/1282-group-the-people-given-the-group-size-they-belong-to.html new file mode 100644 index 000000000..5db21c7e5 --- /dev/null +++ b/final/1282-group-the-people-given-the-group-size-they-belong-to.html @@ -0,0 +1,35 @@ +

1282. Group the People Given the Group Size They Belong To

Medium


There are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1.

+ +

You are given an integer array groupSizes, where groupSizes[i] is the size of the group that person i is in. For example, if groupSizes[1] = 3, then person 1 must be in a group of size 3.

+ +

Return a list of groups such that each person i is in a group of size groupSizes[i].

+ +

Each person should appear in exactly one group, and every person must be in a group. If there are multiple answers, return any of them. It is guaranteed that there will be at least one valid solution for the given input.

+ +

 

+

Example 1:

+ +
Input: groupSizes = [3,3,3,3,3,1,3]
+Output: [[5],[0,1,2],[3,4,6]]
+Explanation: 
+The first group is [5]. The size is 1, and groupSizes[5] = 1.
+The second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.
+The third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.
+Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].
+
+ +

Example 2:

+ +
Input: groupSizes = [2,1,3,3,3,2]
+Output: [[1],[0,5],[2,3,4]]
+
+ +

 

+

Constraints:

+ +
    +
  • groupSizes.length == n
  • +
  • 1 <= n <= 500
  • +
  • 1 <= groupSizes[i] <= n
  • +
+
\ No newline at end of file diff --git a/1287-element-appearing-more-than-25-in-sorted-array/README.md b/final/1287-element-appearing-more-than-25-in-sorted-array.html similarity index 100% rename from 1287-element-appearing-more-than-25-in-sorted-array/README.md rename to final/1287-element-appearing-more-than-25-in-sorted-array.html diff --git a/1289-minimum-falling-path-sum-ii/README.md b/final/1289-minimum-falling-path-sum-ii.html similarity index 100% rename from 1289-minimum-falling-path-sum-ii/README.md rename to final/1289-minimum-falling-path-sum-ii.html diff --git a/1291-sequential-digits/README.md b/final/1291-sequential-digits.html similarity index 100% rename from 1291-sequential-digits/README.md rename to final/1291-sequential-digits.html diff --git a/final/1325-delete-leaves-with-a-given-value.html b/final/1325-delete-leaves-with-a-given-value.html new file mode 100644 index 000000000..23f321db6 --- /dev/null +++ b/final/1325-delete-leaves-with-a-given-value.html @@ -0,0 +1,40 @@ +

1325. Delete Leaves With a Given Value

Medium


Given a binary tree root and an integer target, delete all the leaf nodes with value target.

+ +

Note that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you cannot).

+ +

 

+

Example 1:

+ +

+ +
Input: root = [1,2,3,2,null,2,4], target = 2
+Output: [1,null,3,null,4]
+Explanation: Leaf nodes in green with value (target = 2) are removed (Picture in left). 
+After removing, new nodes become leaf nodes with value (target = 2) (Picture in center).
+
+ +

Example 2:

+ +

+ +
Input: root = [1,3,3,3,2], target = 3
+Output: [1,3,null,null,2]
+
+ +

Example 3:

+ +

+ +
Input: root = [1,2,null,2,null,2], target = 2
+Output: [1]
+Explanation: Leaf nodes in green with value (target = 2) are removed at each step.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 3000].
  • +
  • 1 <= Node.val, target <= 1000
  • +
+
\ No newline at end of file diff --git a/1326-minimum-number-of-taps-to-open-to-water-a-garden/README.md b/final/1326-minimum-number-of-taps-to-open-to-water-a-garden.html similarity index 100% rename from 1326-minimum-number-of-taps-to-open-to-water-a-garden/README.md rename to final/1326-minimum-number-of-taps-to-open-to-water-a-garden.html diff --git a/final/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.html b/final/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.html new file mode 100644 index 000000000..b1f25dcea --- /dev/null +++ b/final/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.html @@ -0,0 +1,46 @@ +

1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance

Medium


There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distanceThreshold.

+ +

Return the city with the smallest number of cities that are reachable through some path and whose distance is at most distanceThreshold, If there are multiple such cities, return the city with the greatest number.

+ +

Notice that the distance of a path connecting cities i and j is equal to the sum of the edges' weights along that path.

+ +

 

+

Example 1:

+ +
Input: n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4
+Output: 3
+Explanation: The figure above describes the graph. 
+The neighboring cities at a distanceThreshold = 4 for each city are:
+City 0 -> [City 1, City 2] 
+City 1 -> [City 0, City 2, City 3] 
+City 2 -> [City 0, City 1, City 3] 
+City 3 -> [City 1, City 2] 
+Cities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number.
+
+ +

Example 2:

+ +
Input: n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2
+Output: 0
+Explanation: The figure above describes the graph. 
+The neighboring cities at a distanceThreshold = 2 for each city are:
+City 0 -> [City 1] 
+City 1 -> [City 0, City 4] 
+City 2 -> [City 3, City 4] 
+City 3 -> [City 2, City 4]
+City 4 -> [City 1, City 2, City 3] 
+The city 0 has 1 neighboring city at a distanceThreshold = 2.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 100
  • +
  • 1 <= edges.length <= n * (n - 1) / 2
  • +
  • edges[i].length == 3
  • +
  • 0 <= fromi < toi < n
  • +
  • 1 <= weighti, distanceThreshold <= 10^4
  • +
  • All pairs (fromi, toi) are distinct.
  • +
+
\ No newline at end of file diff --git a/1335-minimum-difficulty-of-a-job-schedule/README.md b/final/1335-minimum-difficulty-of-a-job-schedule.html similarity index 100% rename from 1335-minimum-difficulty-of-a-job-schedule/README.md rename to final/1335-minimum-difficulty-of-a-job-schedule.html diff --git a/1337-the-k-weakest-rows-in-a-matrix/README.md b/final/1337-the-k-weakest-rows-in-a-matrix.html similarity index 100% rename from 1337-the-k-weakest-rows-in-a-matrix/README.md rename to final/1337-the-k-weakest-rows-in-a-matrix.html diff --git a/1347-minimum-number-of-steps-to-make-two-strings-anagram/README.md b/final/1347-minimum-number-of-steps-to-make-two-strings-anagram.html similarity index 100% rename from 1347-minimum-number-of-steps-to-make-two-strings-anagram/README.md rename to final/1347-minimum-number-of-steps-to-make-two-strings-anagram.html diff --git a/1356-sort-integers-by-the-number-of-1-bits/README.md b/final/1356-sort-integers-by-the-number-of-1-bits.html similarity index 100% rename from 1356-sort-integers-by-the-number-of-1-bits/README.md rename to final/1356-sort-integers-by-the-number-of-1-bits.html diff --git a/1359-count-all-valid-pickup-and-delivery-options/README.md b/final/1359-count-all-valid-pickup-and-delivery-options.html similarity index 100% rename from 1359-count-all-valid-pickup-and-delivery-options/README.md rename to final/1359-count-all-valid-pickup-and-delivery-options.html diff --git a/1361-validate-binary-tree-nodes/README.md b/final/1361-validate-binary-tree-nodes.html similarity index 100% rename from 1361-validate-binary-tree-nodes/README.md rename to final/1361-validate-binary-tree-nodes.html diff --git a/1380-lucky-numbers-in-a-matrix/README.md b/final/1380-lucky-numbers-in-a-matrix.html similarity index 100% rename from 1380-lucky-numbers-in-a-matrix/README.md rename to final/1380-lucky-numbers-in-a-matrix.html diff --git a/final/1382-balance-a-binary-search-tree.html b/final/1382-balance-a-binary-search-tree.html new file mode 100644 index 000000000..e69de29bb diff --git a/final/1395-count-number-of-teams.html b/final/1395-count-number-of-teams.html new file mode 100644 index 000000000..e0ebb7f20 --- /dev/null +++ b/final/1395-count-number-of-teams.html @@ -0,0 +1,42 @@ +

1395. Count Number of Teams

Medium


There are n soldiers standing in a line. Each soldier is assigned a unique rating value.

+ +

You have to form a team of 3 soldiers amongst them under the following rules:

+ +
    +
  • Choose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).
  • +
  • A team is valid if: (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]) where (0 <= i < j < k < n).
  • +
+ +

Return the number of teams you can form given the conditions. (soldiers can be part of multiple teams).

+ +

 

+

Example 1:

+ +
Input: rating = [2,5,3,4,1]
+Output: 3
+Explanation: We can form three teams given the conditions. (2,3,4), (5,4,1), (5,3,1). 
+
+ +

Example 2:

+ +
Input: rating = [2,1,3]
+Output: 0
+Explanation: We can't form any team given the conditions.
+
+ +

Example 3:

+ +
Input: rating = [1,2,3,4]
+Output: 4
+
+ +

 

+

Constraints:

+ +
    +
  • n == rating.length
  • +
  • 3 <= n <= 1000
  • +
  • 1 <= rating[i] <= 105
  • +
  • All the integers in rating are unique.
  • +
+
\ No newline at end of file diff --git a/final/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.html b/final/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.html new file mode 100644 index 000000000..d5797331c --- /dev/null +++ b/final/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.html @@ -0,0 +1,50 @@ +

1404. Number of Steps to Reduce a Number in Binary Representation to One

Medium


Given the binary representation of an integer as a string s, return the number of steps to reduce it to 1 under the following rules:

+ +
    +
  • +

    If the current number is even, you have to divide it by 2.

    +
  • +
  • +

    If the current number is odd, you have to add 1 to it.

    +
  • +
+ +

It is guaranteed that you can always reach one for all test cases.

+ +

 

+

Example 1:

+ +
Input: s = "1101"
+Output: 6
+Explanation: "1101" corressponds to number 13 in their decimal representation.
+Step 1) 13 is odd, add 1 and obtain 14. 
+Step 2) 14 is even, divide by 2 and obtain 7.
+Step 3) 7 is odd, add 1 and obtain 8.
+Step 4) 8 is even, divide by 2 and obtain 4.  
+Step 5) 4 is even, divide by 2 and obtain 2. 
+Step 6) 2 is even, divide by 2 and obtain 1.  
+
+ +

Example 2:

+ +
Input: s = "10"
+Output: 1
+Explanation: "10" corressponds to number 2 in their decimal representation.
+Step 1) 2 is even, divide by 2 and obtain 1.  
+
+ +

Example 3:

+ +
Input: s = "1"
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 500
  • +
  • s consists of characters '0' or '1'
  • +
  • s[0] == '1'
  • +
+
\ No newline at end of file diff --git a/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/README.md b/final/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.html similarity index 100% rename from 1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/README.md rename to final/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.html diff --git a/1422-maximum-score-after-splitting-a-string/README.md b/final/1422-maximum-score-after-splitting-a-string.html similarity index 100% rename from 1422-maximum-score-after-splitting-a-string/README.md rename to final/1422-maximum-score-after-splitting-a-string.html diff --git a/1424-diagonal-traverse-ii/README.md b/final/1424-diagonal-traverse-ii.html similarity index 100% rename from 1424-diagonal-traverse-ii/README.md rename to final/1424-diagonal-traverse-ii.html diff --git a/1425-constrained-subsequence-sum/README.md b/final/1425-constrained-subsequence-sum.html similarity index 100% rename from 1425-constrained-subsequence-sum/README.md rename to final/1425-constrained-subsequence-sum.html diff --git a/1428-leftmost-column-with-at-least-a-one/README.md b/final/1428-leftmost-column-with-at-least-a-one.html similarity index 100% rename from 1428-leftmost-column-with-at-least-a-one/README.md rename to final/1428-leftmost-column-with-at-least-a-one.html diff --git a/1436-destination-city/README.md b/final/1436-destination-city.html similarity index 100% rename from 1436-destination-city/README.md rename to final/1436-destination-city.html diff --git a/final/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.html b/final/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.html new file mode 100644 index 000000000..8081e9124 --- /dev/null +++ b/final/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.html @@ -0,0 +1,43 @@ +

1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

Medium


Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.

+ +

 

+

Example 1:

+ +
Input: nums = [8,2,4,7], limit = 4
+Output: 2 
+Explanation: All subarrays are: 
+[8] with maximum absolute diff |8-8| = 0 <= 4.
+[8,2] with maximum absolute diff |8-2| = 6 > 4. 
+[8,2,4] with maximum absolute diff |8-2| = 6 > 4.
+[8,2,4,7] with maximum absolute diff |8-2| = 6 > 4.
+[2] with maximum absolute diff |2-2| = 0 <= 4.
+[2,4] with maximum absolute diff |2-4| = 2 <= 4.
+[2,4,7] with maximum absolute diff |2-7| = 5 > 4.
+[4] with maximum absolute diff |4-4| = 0 <= 4.
+[4,7] with maximum absolute diff |4-7| = 3 <= 4.
+[7] with maximum absolute diff |7-7| = 0 <= 4. 
+Therefore, the size of the longest subarray is 2.
+
+ +

Example 2:

+ +
Input: nums = [10,1,2,4,7,2], limit = 5
+Output: 4 
+Explanation: The subarray [2,4,7,2] is the longest since the maximum absolute diff is |2-7| = 5 <= 5.
+
+ +

Example 3:

+ +
Input: nums = [4,2,2,2,4,4,2,2], limit = 0
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 109
  • +
  • 0 <= limit <= 109
  • +
+
\ No newline at end of file diff --git a/1441-build-an-array-with-stack-operations/README.md b/final/1441-build-an-array-with-stack-operations.html similarity index 100% rename from 1441-build-an-array-with-stack-operations/README.md rename to final/1441-build-an-array-with-stack-operations.html diff --git a/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/README.md b/final/1442-count-triplets-that-can-form-two-arrays-of-equal-xor.html similarity index 100% rename from 1442-count-triplets-that-can-form-two-arrays-of-equal-xor/README.md rename to final/1442-count-triplets-that-can-form-two-arrays-of-equal-xor.html diff --git a/final/1457-pseudo-palindromic-paths-in-a-binary-tree.html b/final/1457-pseudo-palindromic-paths-in-a-binary-tree.html new file mode 100644 index 000000000..746fb2595 --- /dev/null +++ b/final/1457-pseudo-palindromic-paths-in-a-binary-tree.html @@ -0,0 +1,37 @@ +

1457. Pseudo-Palindromic Paths in a Binary Tree

Medium


Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome.

+ +

Return the number of pseudo-palindromic paths going from the root node to leaf nodes.

+ +

 

+

Example 1:

+ +

+ +
Input: root = [2,3,1,3,1,null,1]
+Output: 2 
+Explanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the red path [2,3,3], the green path [2,1,1], and the path [2,3,1]. Among these paths only red path and green path are pseudo-palindromic paths since the red path [2,3,3] can be rearranged in [3,2,3] (palindrome) and the green path [2,1,1] can be rearranged in [1,2,1] (palindrome).
+
+ +

Example 2:

+ +

+ +
Input: root = [2,1,1,1,3,null,null,null,null,null,1]
+Output: 1 
+Explanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the green path [2,1,1], the path [2,1,3,1], and the path [2,1]. Among these paths only the green path is pseudo-palindromic since [2,1,1] can be rearranged in [1,2,1] (palindrome).
+
+ +

Example 3:

+ +
Input: root = [9]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 105].
  • +
  • 1 <= Node.val <= 9
  • +
+
\ No newline at end of file diff --git a/1458-max-dot-product-of-two-subsequences/README.md b/final/1458-max-dot-product-of-two-subsequences.html similarity index 100% rename from 1458-max-dot-product-of-two-subsequences/README.md rename to final/1458-max-dot-product-of-two-subsequences.html diff --git a/1460-make-two-arrays-equal-by-reversing-subarrays/README.md b/final/1460-make-two-arrays-equal-by-reversing-subarrays.html similarity index 100% rename from 1460-make-two-arrays-equal-by-reversing-subarrays/README.md rename to final/1460-make-two-arrays-equal-by-reversing-subarrays.html diff --git a/final/1463-cherry-pickup-ii.html b/final/1463-cherry-pickup-ii.html new file mode 100644 index 000000000..e69de29bb diff --git a/1464-maximum-product-of-two-elements-in-an-array/README.md b/final/1464-maximum-product-of-two-elements-in-an-array.html similarity index 100% rename from 1464-maximum-product-of-two-elements-in-an-array/README.md rename to final/1464-maximum-product-of-two-elements-in-an-array.html diff --git a/1469-find-all-the-lonely-nodes/README.md b/final/1469-find-all-the-lonely-nodes.html similarity index 100% rename from 1469-find-all-the-lonely-nodes/README.md rename to final/1469-find-all-the-lonely-nodes.html diff --git a/1470-shuffle-the-array/README.md b/final/1470-shuffle-the-array.html similarity index 100% rename from 1470-shuffle-the-array/README.md rename to final/1470-shuffle-the-array.html diff --git a/1481-least-number-of-unique-integers-after-k-removals/README.md b/final/1481-least-number-of-unique-integers-after-k-removals.html similarity index 100% rename from 1481-least-number-of-unique-integers-after-k-removals/README.md rename to final/1481-least-number-of-unique-integers-after-k-removals.html diff --git a/final/1482-minimum-number-of-days-to-make-m-bouquets.html b/final/1482-minimum-number-of-days-to-make-m-bouquets.html new file mode 100644 index 000000000..5d2527dff --- /dev/null +++ b/final/1482-minimum-number-of-days-to-make-m-bouquets.html @@ -0,0 +1,50 @@ +

1482. Minimum Number of Days to Make m Bouquets

Medium


You are given an integer array bloomDay, an integer m and an integer k.

+ +

You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.

+ +

The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.

+ +

Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.

+ +

 

+

Example 1:

+ +
Input: bloomDay = [1,10,3,10,2], m = 3, k = 1
+Output: 3
+Explanation: Let us see what happened in the first three days. x means flower bloomed and _ means flower did not bloom in the garden.
+We need 3 bouquets each should contain 1 flower.
+After day 1: [x, _, _, _, _]   // we can only make one bouquet.
+After day 2: [x, _, _, _, x]   // we can only make two bouquets.
+After day 3: [x, _, x, _, x]   // we can make 3 bouquets. The answer is 3.
+
+ +

Example 2:

+ +
Input: bloomDay = [1,10,3,10,2], m = 3, k = 2
+Output: -1
+Explanation: We need 3 bouquets each has 2 flowers, that means we need 6 flowers. We only have 5 flowers so it is impossible to get the needed bouquets and we return -1.
+
+ +

Example 3:

+ +
Input: bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3
+Output: 12
+Explanation: We need 2 bouquets each should have 3 flowers.
+Here is the garden after the 7 and 12 days:
+After day 7: [x, x, x, x, _, x, x]
+We can make one bouquet of the first three flowers that bloomed. We cannot make another bouquet from the last three flowers that bloomed because they are not adjacent.
+After day 12: [x, x, x, x, x, x, x]
+It is obvious that we can make two bouquets in different ways.
+
+ +

 

+

Constraints:

+ +
    +
  • bloomDay.length == n
  • +
  • 1 <= n <= 105
  • +
  • 1 <= bloomDay[i] <= 109
  • +
  • 1 <= m <= 106
  • +
  • 1 <= k <= n
  • +
+
\ No newline at end of file diff --git a/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/README.md b/final/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.html similarity index 100% rename from 1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/README.md rename to final/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.html diff --git a/1496-path-crossing/README.md b/final/1496-path-crossing.html similarity index 100% rename from 1496-path-crossing/README.md rename to final/1496-path-crossing.html diff --git a/1503-last-moment-before-all-ants-fall-out-of-a-plank/README.md b/final/1503-last-moment-before-all-ants-fall-out-of-a-plank.html similarity index 100% rename from 1503-last-moment-before-all-ants-fall-out-of-a-plank/README.md rename to final/1503-last-moment-before-all-ants-fall-out-of-a-plank.html diff --git a/final/1508-range-sum-of-sorted-subarray-sums.html b/final/1508-range-sum-of-sorted-subarray-sums.html new file mode 100644 index 000000000..ac175361e --- /dev/null +++ b/final/1508-range-sum-of-sorted-subarray-sums.html @@ -0,0 +1,35 @@ +

1508. Range Sum of Sorted Subarray Sums

Medium


You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.

+ +

Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4], n = 4, left = 1, right = 5
+Output: 13 
+Explanation: All subarray sums are 1, 3, 6, 10, 2, 5, 9, 3, 7, 4. After sorting them in non-decreasing order we have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 1 to ri = 5 is 1 + 2 + 3 + 3 + 4 = 13. 
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,4], n = 4, left = 3, right = 4
+Output: 6
+Explanation: The given array is the same as example 1. We have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 3 to ri = 4 is 3 + 3 = 6.
+
+ +

Example 3:

+ +
Input: nums = [1,2,3,4], n = 4, left = 1, right = 10
+Output: 50
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= nums.length <= 1000
  • +
  • 1 <= nums[i] <= 100
  • +
  • 1 <= left <= right <= n * (n + 1) / 2
  • +
+
\ No newline at end of file diff --git a/final/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.html b/final/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.html new file mode 100644 index 000000000..ea8a7485a --- /dev/null +++ b/final/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.html @@ -0,0 +1,48 @@ +

1509. Minimum Difference Between Largest and Smallest Value in Three Moves

Medium


You are given an integer array nums.

+ +

In one move, you can choose one element of nums and change it to any value.

+ +

Return the minimum difference between the largest and smallest value of nums after performing at most three moves.

+ +

 

+

Example 1:

+ +
Input: nums = [5,3,2,4]
+Output: 0
+Explanation: We can make at most 3 moves.
+In the first move, change 2 to 3. nums becomes [5,3,3,4].
+In the second move, change 4 to 3. nums becomes [5,3,3,3].
+In the third move, change 5 to 3. nums becomes [3,3,3,3].
+After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0.
+
+ +

Example 2:

+ +
Input: nums = [1,5,0,10,14]
+Output: 1
+Explanation: We can make at most 3 moves.
+In the first move, change 5 to 0. nums becomes [1,0,0,10,14].
+In the second move, change 10 to 0. nums becomes [1,0,0,0,14].
+In the third move, change 14 to 1. nums becomes [1,0,0,0,1].
+After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 1.
+It can be shown that there is no way to make the difference 0 in 3 moves.
+ +

Example 3:

+ +
Input: nums = [3,100,20]
+Output: 0
+Explanation: We can make at most 3 moves.
+In the first move, change 100 to 7. nums becomes [3,7,20].
+In the second move, change 20 to 7. nums becomes [3,7,7].
+In the third move, change 3 to 7. nums becomes [7,7,7].
+After performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/1512-number-of-good-pairs/README.md b/final/1512-number-of-good-pairs.html similarity index 100% rename from 1512-number-of-good-pairs/README.md rename to final/1512-number-of-good-pairs.html diff --git a/1518-water-bottles/README.md b/final/1518-water-bottles.html similarity index 100% rename from 1518-water-bottles/README.md rename to final/1518-water-bottles.html diff --git a/1530-number-of-good-leaf-nodes-pairs/README.md b/final/1530-number-of-good-leaf-nodes-pairs.html similarity index 100% rename from 1530-number-of-good-leaf-nodes-pairs/README.md rename to final/1530-number-of-good-leaf-nodes-pairs.html diff --git a/1531-string-compression-ii/README.md b/final/1531-string-compression-ii.html similarity index 100% rename from 1531-string-compression-ii/README.md rename to final/1531-string-compression-ii.html diff --git a/1535-find-the-winner-of-an-array-game/README.md b/final/1535-find-the-winner-of-an-array-game.html similarity index 100% rename from 1535-find-the-winner-of-an-array-game/README.md rename to final/1535-find-the-winner-of-an-array-game.html diff --git a/1544-make-the-string-great/README.md b/final/1544-make-the-string-great.html similarity index 100% rename from 1544-make-the-string-great/README.md rename to final/1544-make-the-string-great.html diff --git a/1550-three-consecutive-odds/README.md b/final/1550-three-consecutive-odds.html similarity index 100% rename from 1550-three-consecutive-odds/README.md rename to final/1550-three-consecutive-odds.html diff --git a/1552-magnetic-force-between-two-balls/README.md b/final/1552-magnetic-force-between-two-balls.html similarity index 100% rename from 1552-magnetic-force-between-two-balls/README.md rename to final/1552-magnetic-force-between-two-balls.html diff --git a/1561-maximum-number-of-coins-you-can-get/README.md b/final/1561-maximum-number-of-coins-you-can-get.html similarity index 100% rename from 1561-maximum-number-of-coins-you-can-get/README.md rename to final/1561-maximum-number-of-coins-you-can-get.html diff --git a/1568-minimum-number-of-days-to-disconnect-island/README.md b/final/1568-minimum-number-of-days-to-disconnect-island.html similarity index 100% rename from 1568-minimum-number-of-days-to-disconnect-island/README.md rename to final/1568-minimum-number-of-days-to-disconnect-island.html diff --git a/1578-minimum-time-to-make-rope-colorful/README.md b/final/1578-minimum-time-to-make-rope-colorful.html similarity index 100% rename from 1578-minimum-time-to-make-rope-colorful/README.md rename to final/1578-minimum-time-to-make-rope-colorful.html diff --git a/final/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable.html b/final/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable.html new file mode 100644 index 000000000..e69de29bb diff --git a/1580-put-boxes-into-the-warehouse-ii/README.md b/final/1580-put-boxes-into-the-warehouse-ii.html similarity index 100% rename from 1580-put-boxes-into-the-warehouse-ii/README.md rename to final/1580-put-boxes-into-the-warehouse-ii.html diff --git a/1582-special-positions-in-a-binary-matrix/README.md b/final/1582-special-positions-in-a-binary-matrix.html similarity index 100% rename from 1582-special-positions-in-a-binary-matrix/README.md rename to final/1582-special-positions-in-a-binary-matrix.html diff --git a/1584-min-cost-to-connect-all-points/README.md b/final/1584-min-cost-to-connect-all-points.html similarity index 100% rename from 1584-min-cost-to-connect-all-points/README.md rename to final/1584-min-cost-to-connect-all-points.html diff --git a/1598-crawler-log-folder/README.md b/final/1598-crawler-log-folder.html similarity index 100% rename from 1598-crawler-log-folder/README.md rename to final/1598-crawler-log-folder.html diff --git a/1605-find-valid-matrix-given-row-and-column-sums/README.md b/final/1605-find-valid-matrix-given-row-and-column-sums.html similarity index 100% rename from 1605-find-valid-matrix-given-row-and-column-sums/README.md rename to final/1605-find-valid-matrix-given-row-and-column-sums.html diff --git a/1608-special-array-with-x-elements-greater-than-or-equal-x/README.md b/final/1608-special-array-with-x-elements-greater-than-or-equal-x.html similarity index 100% rename from 1608-special-array-with-x-elements-greater-than-or-equal-x/README.md rename to final/1608-special-array-with-x-elements-greater-than-or-equal-x.html diff --git a/1609-even-odd-tree/README.md b/final/1609-even-odd-tree.html similarity index 100% rename from 1609-even-odd-tree/README.md rename to final/1609-even-odd-tree.html diff --git a/1611-minimum-one-bit-operations-to-make-integers-zero/README.md b/final/1611-minimum-one-bit-operations-to-make-integers-zero.html similarity index 100% rename from 1611-minimum-one-bit-operations-to-make-integers-zero/README.md rename to final/1611-minimum-one-bit-operations-to-make-integers-zero.html diff --git a/1614-maximum-nesting-depth-of-the-parentheses/README.md b/final/1614-maximum-nesting-depth-of-the-parentheses.html similarity index 100% rename from 1614-maximum-nesting-depth-of-the-parentheses/README.md rename to final/1614-maximum-nesting-depth-of-the-parentheses.html diff --git a/1615-maximal-network-rank/README.md b/final/1615-maximal-network-rank.html similarity index 100% rename from 1615-maximal-network-rank/README.md rename to final/1615-maximal-network-rank.html diff --git a/1624-largest-substring-between-two-equal-characters/README.md b/final/1624-largest-substring-between-two-equal-characters.html similarity index 100% rename from 1624-largest-substring-between-two-equal-characters/README.md rename to final/1624-largest-substring-between-two-equal-characters.html diff --git a/1630-arithmetic-subarrays/README.md b/final/1630-arithmetic-subarrays.html similarity index 100% rename from 1630-arithmetic-subarrays/README.md rename to final/1630-arithmetic-subarrays.html diff --git a/1631-path-with-minimum-effort/README.md b/final/1631-path-with-minimum-effort.html similarity index 100% rename from 1631-path-with-minimum-effort/README.md rename to final/1631-path-with-minimum-effort.html diff --git a/1636-sort-array-by-increasing-frequency/README.md b/final/1636-sort-array-by-increasing-frequency.html similarity index 100% rename from 1636-sort-array-by-increasing-frequency/README.md rename to final/1636-sort-array-by-increasing-frequency.html diff --git a/final/1637-widest-vertical-area-between-two-points-containing-no-points.html b/final/1637-widest-vertical-area-between-two-points-containing-no-points.html new file mode 100644 index 000000000..e69de29bb diff --git a/1642-furthest-building-you-can-reach/README.md b/final/1642-furthest-building-you-can-reach.html similarity index 100% rename from 1642-furthest-building-you-can-reach/README.md rename to final/1642-furthest-building-you-can-reach.html diff --git a/1647-minimum-deletions-to-make-character-frequencies-unique/README.md b/final/1647-minimum-deletions-to-make-character-frequencies-unique.html similarity index 100% rename from 1647-minimum-deletions-to-make-character-frequencies-unique/README.md rename to final/1647-minimum-deletions-to-make-character-frequencies-unique.html diff --git a/final/1653-minimum-deletions-to-make-string-balanced.html b/final/1653-minimum-deletions-to-make-string-balanced.html new file mode 100644 index 000000000..8dc82bd2d --- /dev/null +++ b/final/1653-minimum-deletions-to-make-string-balanced.html @@ -0,0 +1,31 @@ +

1653. Minimum Deletions to Make String Balanced

Medium


You are given a string s consisting only of characters 'a' and 'b'​​​​.

+ +

You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.

+ +

Return the minimum number of deletions needed to make s balanced.

+ +

 

+

Example 1:

+ +
Input: s = "aababbab"
+Output: 2
+Explanation: You can either:
+Delete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or
+Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
+
+ +

Example 2:

+ +
Input: s = "bbaaaaabb"
+Output: 2
+Explanation: The only solution is to delete the first two characters.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s[i] is 'a' or 'b'​​.
  • +
+
\ No newline at end of file diff --git a/1657-determine-if-two-strings-are-close/README.md b/final/1657-determine-if-two-strings-are-close.html similarity index 100% rename from 1657-determine-if-two-strings-are-close/README.md rename to final/1657-determine-if-two-strings-are-close.html diff --git a/1658-minimum-operations-to-reduce-x-to-zero/README.md b/final/1658-minimum-operations-to-reduce-x-to-zero.html similarity index 100% rename from 1658-minimum-operations-to-reduce-x-to-zero/README.md rename to final/1658-minimum-operations-to-reduce-x-to-zero.html diff --git a/1660-correct-a-binary-tree/README.md b/final/1660-correct-a-binary-tree.html similarity index 100% rename from 1660-correct-a-binary-tree/README.md rename to final/1660-correct-a-binary-tree.html diff --git a/1662-check-if-two-string-arrays-are-equivalent/README.md b/final/1662-check-if-two-string-arrays-are-equivalent.html similarity index 100% rename from 1662-check-if-two-string-arrays-are-equivalent/README.md rename to final/1662-check-if-two-string-arrays-are-equivalent.html diff --git a/final/1669-merge-in-between-linked-lists.html b/final/1669-merge-in-between-linked-lists.html new file mode 100644 index 000000000..80ce1897a --- /dev/null +++ b/final/1669-merge-in-between-linked-lists.html @@ -0,0 +1,32 @@ +

1669. Merge In Between Linked Lists

Medium


You are given two linked lists: list1 and list2 of sizes n and m respectively.

+ +

Remove list1's nodes from the ath node to the bth node, and put list2 in their place.

+ +

The blue edges and nodes in the following figure indicate the result:

+ +

Build the result list and return its head.

+ +

 

+

Example 1:

+ +
Input: list1 = [10,1,13,6,9,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]
+Output: [10,1,13,1000000,1000001,1000002,5]
+Explanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.
+
+ +

Example 2:

+ +
Input: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]
+Output: [0,1,1000000,1000001,1000002,1000003,1000004,6]
+Explanation: The blue edges and nodes in the above figure indicate the result.
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= list1.length <= 104
  • +
  • 1 <= a <= b < list1.length - 1
  • +
  • 1 <= list2.length <= 104
  • +
+
\ No newline at end of file diff --git a/1683-invalid-tweets/README.md b/final/1683-invalid-tweets.html similarity index 100% rename from 1683-invalid-tweets/README.md rename to final/1683-invalid-tweets.html diff --git a/1685-sum-of-absolute-differences-in-a-sorted-array/README.md b/final/1685-sum-of-absolute-differences-in-a-sorted-array.html similarity index 100% rename from 1685-sum-of-absolute-differences-in-a-sorted-array/README.md rename to final/1685-sum-of-absolute-differences-in-a-sorted-array.html diff --git a/1688-count-of-matches-in-tournament/README.md b/final/1688-count-of-matches-in-tournament.html similarity index 100% rename from 1688-count-of-matches-in-tournament/README.md rename to final/1688-count-of-matches-in-tournament.html diff --git a/1700-number-of-students-unable-to-eat-lunch/README.md b/final/1700-number-of-students-unable-to-eat-lunch.html similarity index 100% rename from 1700-number-of-students-unable-to-eat-lunch/README.md rename to final/1700-number-of-students-unable-to-eat-lunch.html diff --git a/final/1701-average-waiting-time.html b/final/1701-average-waiting-time.html new file mode 100644 index 000000000..1bc0b3660 --- /dev/null +++ b/final/1701-average-waiting-time.html @@ -0,0 +1,44 @@ +

1701. Average Waiting Time

Medium


There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:

+ +
    +
  • arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order.
  • +
  • timei is the time needed to prepare the order of the ith customer.
  • +
+ +

When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.

+ +

Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted.

+ +

 

+

Example 1:

+ +
Input: customers = [[1,2],[2,5],[4,3]]
+Output: 5.00000
+Explanation:
+1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.
+2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.
+3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.
+So the average waiting time = (2 + 6 + 7) / 3 = 5.
+
+ +

Example 2:

+ +
Input: customers = [[5,2],[5,4],[10,3],[20,1]]
+Output: 3.25000
+Explanation:
+1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.
+2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.
+3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.
+4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.
+So the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= customers.length <= 105
  • +
  • 1 <= arrivali, timei <= 104
  • +
  • arrival<= arrivali+1
  • +
+
\ No newline at end of file diff --git a/1704-determine-if-string-halves-are-alike/README.md b/final/1704-determine-if-string-halves-are-alike.html similarity index 100% rename from 1704-determine-if-string-halves-are-alike/README.md rename to final/1704-determine-if-string-halves-are-alike.html diff --git a/1716-calculate-money-in-leetcode-bank/README.md b/final/1716-calculate-money-in-leetcode-bank.html similarity index 100% rename from 1716-calculate-money-in-leetcode-bank/README.md rename to final/1716-calculate-money-in-leetcode-bank.html diff --git a/1717-maximum-score-from-removing-substrings/README.md b/final/1717-maximum-score-from-removing-substrings.html similarity index 100% rename from 1717-maximum-score-from-removing-substrings/README.md rename to final/1717-maximum-score-from-removing-substrings.html diff --git a/1727-largest-submatrix-with-rearrangements/README.md b/final/1727-largest-submatrix-with-rearrangements.html similarity index 100% rename from 1727-largest-submatrix-with-rearrangements/README.md rename to final/1727-largest-submatrix-with-rearrangements.html diff --git a/final/1740-find-distance-in-a-binary-tree.html b/final/1740-find-distance-in-a-binary-tree.html new file mode 100644 index 000000000..e02de46ad --- /dev/null +++ b/final/1740-find-distance-in-a-binary-tree.html @@ -0,0 +1,33 @@ +

1740. Find Distance in a Binary Tree

Medium


Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree.

+ +

The distance between two nodes is the number of edges on the path from one to the other.

+ +

 

+

Example 1:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 0
+Output: 3
+Explanation: There are 3 edges between 5 and 0: 5-3-1-0.
+ +

Example 2:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 7
+Output: 2
+Explanation: There are 2 edges between 5 and 7: 5-2-7.
+ +

Example 3:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 5
+Output: 0
+Explanation: The distance between a node and itself is 0.
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • 0 <= Node.val <= 109
  • +
  • All Node.val are unique.
  • +
  • p and q are values in the tree.
  • +
+
\ No newline at end of file diff --git a/1743-restore-the-array-from-adjacent-pairs/README.md b/final/1743-restore-the-array-from-adjacent-pairs.html similarity index 100% rename from 1743-restore-the-array-from-adjacent-pairs/README.md rename to final/1743-restore-the-array-from-adjacent-pairs.html diff --git a/final/1750-minimum-length-of-string-after-deleting-similar-ends.html b/final/1750-minimum-length-of-string-after-deleting-similar-ends.html new file mode 100644 index 000000000..c64aa7976 --- /dev/null +++ b/final/1750-minimum-length-of-string-after-deleting-similar-ends.html @@ -0,0 +1,47 @@ +

1750. Minimum Length of String After Deleting Similar Ends

Medium


Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:

+ +
    +
  1. Pick a non-empty prefix from the string s where all the characters in the prefix are equal.
  2. +
  3. Pick a non-empty suffix from the string s where all the characters in this suffix are equal.
  4. +
  5. The prefix and the suffix should not intersect at any index.
  6. +
  7. The characters from the prefix and suffix must be the same.
  8. +
  9. Delete both the prefix and the suffix.
  10. +
+ +

Return the minimum length of s after performing the above operation any number of times (possibly zero times).

+ +

 

+

Example 1:

+ +
Input: s = "ca"
+Output: 2
+Explanation: You can't remove any characters, so the string stays as is.
+
+ +

Example 2:

+ +
Input: s = "cabaabac"
+Output: 0
+Explanation: An optimal sequence of operations is:
+- Take prefix = "c" and suffix = "c" and remove them, s = "abaaba".
+- Take prefix = "a" and suffix = "a" and remove them, s = "baab".
+- Take prefix = "b" and suffix = "b" and remove them, s = "aa".
+- Take prefix = "a" and suffix = "a" and remove them, s = "".
+ +

Example 3:

+ +
Input: s = "aabccabba"
+Output: 3
+Explanation: An optimal sequence of operations is:
+- Take prefix = "aa" and suffix = "a" and remove them, s = "bccabb".
+- Take prefix = "b" and suffix = "bb" and remove them, s = "cca".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s only consists of characters 'a', 'b', and 'c'.
  • +
+
\ No newline at end of file diff --git a/1757-recyclable-and-low-fat-products/README.md b/final/1757-recyclable-and-low-fat-products.html similarity index 100% rename from 1757-recyclable-and-low-fat-products/README.md rename to final/1757-recyclable-and-low-fat-products.html diff --git a/1758-minimum-changes-to-make-alternating-binary-string/README.md b/final/1758-minimum-changes-to-make-alternating-binary-string.html similarity index 100% rename from 1758-minimum-changes-to-make-alternating-binary-string/README.md rename to final/1758-minimum-changes-to-make-alternating-binary-string.html diff --git a/1759-count-number-of-homogenous-substrings/README.md b/final/1759-count-number-of-homogenous-substrings.html similarity index 100% rename from 1759-count-number-of-homogenous-substrings/README.md rename to final/1759-count-number-of-homogenous-substrings.html diff --git a/1768-merge-strings-alternately/README.md b/final/1768-merge-strings-alternately.html similarity index 100% rename from 1768-merge-strings-alternately/README.md rename to final/1768-merge-strings-alternately.html diff --git a/1791-find-center-of-star-graph/README.md b/final/1791-find-center-of-star-graph.html similarity index 100% rename from 1791-find-center-of-star-graph/README.md rename to final/1791-find-center-of-star-graph.html diff --git a/1793-maximum-score-of-a-good-subarray/README.md b/final/1793-maximum-score-of-a-good-subarray.html similarity index 100% rename from 1793-maximum-score-of-a-good-subarray/README.md rename to final/1793-maximum-score-of-a-good-subarray.html diff --git a/1802-maximum-value-at-a-given-index-in-a-bounded-array/README.md b/final/1802-maximum-value-at-a-given-index-in-a-bounded-array.html similarity index 100% rename from 1802-maximum-value-at-a-given-index-in-a-bounded-array/README.md rename to final/1802-maximum-value-at-a-given-index-in-a-bounded-array.html diff --git a/1804-implement-trie-ii-prefix-tree/README.md b/final/1804-implement-trie-ii-prefix-tree.html similarity index 100% rename from 1804-implement-trie-ii-prefix-tree/README.md rename to final/1804-implement-trie-ii-prefix-tree.html diff --git a/1814-count-nice-pairs-in-an-array/README.md b/final/1814-count-nice-pairs-in-an-array.html similarity index 100% rename from 1814-count-nice-pairs-in-an-array/README.md rename to final/1814-count-nice-pairs-in-an-array.html diff --git a/1823-find-the-winner-of-the-circular-game/README.md b/final/1823-find-the-winner-of-the-circular-game.html similarity index 100% rename from 1823-find-the-winner-of-the-circular-game/README.md rename to final/1823-find-the-winner-of-the-circular-game.html diff --git a/1836-remove-duplicates-from-an-unsorted-linked-list/README.md b/final/1836-remove-duplicates-from-an-unsorted-linked-list.html similarity index 100% rename from 1836-remove-duplicates-from-an-unsorted-linked-list/README.md rename to final/1836-remove-duplicates-from-an-unsorted-linked-list.html diff --git a/final/1838-frequency-of-the-most-frequent-element.html b/final/1838-frequency-of-the-most-frequent-element.html new file mode 100644 index 000000000..9347d0b0f --- /dev/null +++ b/final/1838-frequency-of-the-most-frequent-element.html @@ -0,0 +1,39 @@ +

1838. Frequency of the Most Frequent Element

Medium


The frequency of an element is the number of times it occurs in an array.

+ +

You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.

+ +

Return the maximum possible frequency of an element after performing at most k operations.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,4], k = 5
+Output: 3
+Explanation: Increment the first element three times and the second element two times to make nums = [4,4,4].
+4 has a frequency of 3.
+ +

Example 2:

+ +
Input: nums = [1,4,8,13], k = 5
+Output: 2
+Explanation: There are multiple optimal solutions:
+- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.
+- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.
+- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.
+
+ +

Example 3:

+ +
Input: nums = [3,9,6], k = 2
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 105
  • +
  • 1 <= k <= 105
  • +
+
\ No newline at end of file diff --git a/1845-seat-reservation-manager/README.md b/final/1845-seat-reservation-manager.html similarity index 100% rename from 1845-seat-reservation-manager/README.md rename to final/1845-seat-reservation-manager.html diff --git a/final/1846-maximum-element-after-decreasing-and-rearranging.html b/final/1846-maximum-element-after-decreasing-and-rearranging.html new file mode 100644 index 000000000..cc83a9762 --- /dev/null +++ b/final/1846-maximum-element-after-decreasing-and-rearranging.html @@ -0,0 +1,54 @@ +

1846. Maximum Element After Decreasing and Rearranging

Medium


You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:

+ +
    +
  • The value of the first element in arr must be 1.
  • +
  • The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.
  • +
+ +

There are 2 types of operations that you can perform any number of times:

+ +
    +
  • Decrease the value of any element of arr to a smaller positive integer.
  • +
  • Rearrange the elements of arr to be in any order.
  • +
+ +

Return the maximum possible value of an element in arr after performing the operations to satisfy the conditions.

+ +

 

+

Example 1:

+ +
Input: arr = [2,2,1,2,1]
+Output: 2
+Explanation: 
+We can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].
+The largest element in arr is 2.
+
+ +

Example 2:

+ +
Input: arr = [100,1,1000]
+Output: 3
+Explanation: 
+One possible way to satisfy the conditions is by doing the following:
+1. Rearrange arr so it becomes [1,100,1000].
+2. Decrease the value of the second element to 2.
+3. Decrease the value of the third element to 3.
+Now arr = [1,2,3], which satisfies the conditions.
+The largest element in arr is 3.
+
+ +

Example 3:

+ +
Input: arr = [1,2,3,4,5]
+Output: 5
+Explanation: The array already satisfies the conditions, and the largest element is 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 105
  • +
  • 1 <= arr[i] <= 109
  • +
+
\ No newline at end of file diff --git a/1863-sum-of-all-subset-xor-totals/README.md b/final/1863-sum-of-all-subset-xor-totals.html similarity index 100% rename from 1863-sum-of-all-subset-xor-totals/README.md rename to final/1863-sum-of-all-subset-xor-totals.html diff --git a/1870-minimum-speed-to-arrive-on-time/README.md b/final/1870-minimum-speed-to-arrive-on-time.html similarity index 100% rename from 1870-minimum-speed-to-arrive-on-time/README.md rename to final/1870-minimum-speed-to-arrive-on-time.html diff --git a/1877-minimize-maximum-pair-sum-in-array/README.md b/final/1877-minimize-maximum-pair-sum-in-array.html similarity index 100% rename from 1877-minimize-maximum-pair-sum-in-array/README.md rename to final/1877-minimize-maximum-pair-sum-in-array.html diff --git a/1885-count-pairs-in-two-arrays/README.md b/final/1885-count-pairs-in-two-arrays.html similarity index 100% rename from 1885-count-pairs-in-two-arrays/README.md rename to final/1885-count-pairs-in-two-arrays.html diff --git a/1887-reduction-operations-to-make-the-array-elements-equal/README.md b/final/1887-reduction-operations-to-make-the-array-elements-equal.html similarity index 100% rename from 1887-reduction-operations-to-make-the-array-elements-equal/README.md rename to final/1887-reduction-operations-to-make-the-array-elements-equal.html diff --git a/1897-redistribute-characters-to-make-all-strings-equal/README.md b/final/1897-redistribute-characters-to-make-all-strings-equal.html similarity index 100% rename from 1897-redistribute-characters-to-make-all-strings-equal/README.md rename to final/1897-redistribute-characters-to-make-all-strings-equal.html diff --git a/1903-largest-odd-number-in-string/README.md b/final/1903-largest-odd-number-in-string.html similarity index 100% rename from 1903-largest-odd-number-in-string/README.md rename to final/1903-largest-odd-number-in-string.html diff --git a/1913-maximum-product-difference-between-two-pairs/README.md b/final/1913-maximum-product-difference-between-two-pairs.html similarity index 100% rename from 1913-maximum-product-difference-between-two-pairs/README.md rename to final/1913-maximum-product-difference-between-two-pairs.html diff --git a/final/1915-number-of-wonderful-substrings.html b/final/1915-number-of-wonderful-substrings.html new file mode 100644 index 000000000..c19d9e1f8 --- /dev/null +++ b/final/1915-number-of-wonderful-substrings.html @@ -0,0 +1,54 @@ +

1915. Number of Wonderful Substrings

Medium


A wonderful string is a string where at most one letter appears an odd number of times.

+ +
    +
  • For example, "ccjjc" and "abab" are wonderful, but "ab" is not.
  • +
+ +

Given a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately.

+ +

A substring is a contiguous sequence of characters in a string.

+ +

 

+

Example 1:

+ +
Input: word = "aba"
+Output: 4
+Explanation: The four wonderful substrings are underlined below:
+- "aba" -> "a"
+- "aba" -> "b"
+- "aba" -> "a"
+- "aba" -> "aba"
+
+ +

Example 2:

+ +
Input: word = "aabb"
+Output: 9
+Explanation: The nine wonderful substrings are underlined below:
+- "aabb" -> "a"
+- "aabb" -> "aa"
+- "aabb" -> "aab"
+- "aabb" -> "aabb"
+- "aabb" -> "a"
+- "aabb" -> "abb"
+- "aabb" -> "b"
+- "aabb" -> "bb"
+- "aabb" -> "b"
+
+ +

Example 3:

+ +
Input: word = "he"
+Output: 2
+Explanation: The two wonderful substrings are underlined below:
+- "he" -> "h"
+- "he" -> "e"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word.length <= 105
  • +
  • word consists of lowercase English letters from 'a' to 'j'.
  • +
\ No newline at end of file diff --git a/1920-build-array-from-permutation/README.md b/final/1920-build-array-from-permutation.html similarity index 100% rename from 1920-build-array-from-permutation/README.md rename to final/1920-build-array-from-permutation.html diff --git a/1921-eliminate-maximum-number-of-monsters/README.md b/final/1921-eliminate-maximum-number-of-monsters.html similarity index 100% rename from 1921-eliminate-maximum-number-of-monsters/README.md rename to final/1921-eliminate-maximum-number-of-monsters.html diff --git a/1930-unique-length-3-palindromic-subsequences/README.md b/final/1930-unique-length-3-palindromic-subsequences.html similarity index 100% rename from 1930-unique-length-3-palindromic-subsequences/README.md rename to final/1930-unique-length-3-palindromic-subsequences.html diff --git a/final/1937-maximum-number-of-points-with-cost.html b/final/1937-maximum-number-of-points-with-cost.html new file mode 100644 index 000000000..d07098621 --- /dev/null +++ b/final/1937-maximum-number-of-points-with-cost.html @@ -0,0 +1,49 @@ +

1937. Maximum Number of Points with Cost

Medium


You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix.

+ +

To gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score.

+ +

However, you will lose points if you pick a cell too far from the cell that you picked in the previous row. For every two adjacent rows r and r + 1 (where 0 <= r < m - 1), picking cells at coordinates (r, c1) and (r + 1, c2) will subtract abs(c1 - c2) from your score.

+ +

Return the maximum number of points you can achieve.

+ +

abs(x) is defined as:

+ +
    +
  • x for x >= 0.
  • +
  • -x for x < 0.
  • +
+ +

 

+

Example 1:

+ +
Input: points = [[1,2,3],[1,5,1],[3,1,1]]
+Output: 9
+Explanation:
+The blue cells denote the optimal cells to pick, which have coordinates (0, 2), (1, 1), and (2, 0).
+You add 3 + 5 + 3 = 11 to your score.
+However, you must subtract abs(2 - 1) + abs(1 - 0) = 2 from your score.
+Your final score is 11 - 2 = 9.
+
+ +

Example 2:

+ +
Input: points = [[1,5],[2,3],[4,2]]
+Output: 11
+Explanation:
+The blue cells denote the optimal cells to pick, which have coordinates (0, 1), (1, 1), and (2, 0).
+You add 5 + 3 + 4 = 12 to your score.
+However, you must subtract abs(1 - 1) + abs(1 - 0) = 1 from your score.
+Your final score is 12 - 1 = 11.
+
+ +

 

+

Constraints:

+ +
    +
  • m == points.length
  • +
  • n == points[r].length
  • +
  • 1 <= m, n <= 105
  • +
  • 1 <= m * n <= 105
  • +
  • 0 <= points[r][c] <= 105
  • +
+
\ No newline at end of file diff --git a/1940-longest-common-subsequence-between-sorted-arrays/README.md b/final/1940-longest-common-subsequence-between-sorted-arrays.html similarity index 100% rename from 1940-longest-common-subsequence-between-sorted-arrays/README.md rename to final/1940-longest-common-subsequence-between-sorted-arrays.html diff --git a/1971-find-if-path-exists-in-graph/README.md b/final/1971-find-if-path-exists-in-graph.html similarity index 100% rename from 1971-find-if-path-exists-in-graph/README.md rename to final/1971-find-if-path-exists-in-graph.html diff --git a/1973-count-nodes-equal-to-sum-of-descendants/README.md b/final/1973-count-nodes-equal-to-sum-of-descendants.html similarity index 100% rename from 1973-count-nodes-equal-to-sum-of-descendants/README.md rename to final/1973-count-nodes-equal-to-sum-of-descendants.html diff --git a/1980-find-unique-binary-string/README.md b/final/1980-find-unique-binary-string.html similarity index 100% rename from 1980-find-unique-binary-string/README.md rename to final/1980-find-unique-binary-string.html diff --git a/1992-find-all-groups-of-farmland/README.md b/final/1992-find-all-groups-of-farmland.html similarity index 100% rename from 1992-find-all-groups-of-farmland/README.md rename to final/1992-find-all-groups-of-farmland.html diff --git a/2000-reverse-prefix-of-word/README.md b/final/2000-reverse-prefix-of-word.html similarity index 100% rename from 2000-reverse-prefix-of-word/README.md rename to final/2000-reverse-prefix-of-word.html diff --git a/2009-minimum-number-of-operations-to-make-array-continuous/README.md b/final/2009-minimum-number-of-operations-to-make-array-continuous.html similarity index 100% rename from 2009-minimum-number-of-operations-to-make-array-continuous/README.md rename to final/2009-minimum-number-of-operations-to-make-array-continuous.html diff --git a/2037-minimum-number-of-moves-to-seat-everyone/README.md b/final/2037-minimum-number-of-moves-to-seat-everyone.html similarity index 100% rename from 2037-minimum-number-of-moves-to-seat-everyone/README.md rename to final/2037-minimum-number-of-moves-to-seat-everyone.html diff --git a/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/README.md b/final/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.html similarity index 100% rename from 2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/README.md rename to final/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.html diff --git a/2045-second-minimum-time-to-reach-destination/README.md b/final/2045-second-minimum-time-to-reach-destination.html similarity index 100% rename from 2045-second-minimum-time-to-reach-destination/README.md rename to final/2045-second-minimum-time-to-reach-destination.html diff --git a/2050-parallel-courses-iii/README.md b/final/2050-parallel-courses-iii.html similarity index 100% rename from 2050-parallel-courses-iii/README.md rename to final/2050-parallel-courses-iii.html diff --git a/2053-kth-distinct-string-in-an-array/README.md b/final/2053-kth-distinct-string-in-an-array.html similarity index 100% rename from 2053-kth-distinct-string-in-an-array/README.md rename to final/2053-kth-distinct-string-in-an-array.html diff --git a/final/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.html b/final/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.html new file mode 100644 index 000000000..530c9a237 --- /dev/null +++ b/final/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.html @@ -0,0 +1,50 @@ +

2058. Find the Minimum and Maximum Number of Nodes Between Critical Points

Medium


A critical point in a linked list is defined as either a local maxima or a local minima.

+ +

A node is a local maxima if the current node has a value strictly greater than the previous node and the next node.

+ +

A node is a local minima if the current node has a value strictly smaller than the previous node and the next node.

+ +

Note that a node can only be a local maxima/minima if there exists both a previous node and a next node.

+ +

Given a linked list head, return an array of length 2 containing [minDistance, maxDistance] where minDistance is the minimum distance between any two distinct critical points and maxDistance is the maximum distance between any two distinct critical points. If there are fewer than two critical points, return [-1, -1].

+ +

 

+

Example 1:

+ +
Input: head = [3,1]
+Output: [-1,-1]
+Explanation: There are no critical points in [3,1].
+
+ +

Example 2:

+ +
Input: head = [5,3,1,2,5,1,2]
+Output: [1,3]
+Explanation: There are three critical points:
+- [5,3,1,2,5,1,2]: The third node is a local minima because 1 is less than 3 and 2.
+- [5,3,1,2,5,1,2]: The fifth node is a local maxima because 5 is greater than 2 and 1.
+- [5,3,1,2,5,1,2]: The sixth node is a local minima because 1 is less than 5 and 2.
+The minimum distance is between the fifth and the sixth node. minDistance = 6 - 5 = 1.
+The maximum distance is between the third and the sixth node. maxDistance = 6 - 3 = 3.
+
+ +

Example 3:

+ +
Input: head = [1,3,2,2,3,2,2,2,7]
+Output: [3,3]
+Explanation: There are two critical points:
+- [1,3,2,2,3,2,2,2,7]: The second node is a local maxima because 3 is greater than 1 and 2.
+- [1,3,2,2,3,2,2,2,7]: The fifth node is a local maxima because 3 is greater than 2 and 2.
+Both the minimum and maximum distances are between the second and the fifth node.
+Thus, minDistance and maxDistance is 5 - 2 = 3.
+Note that the last node is not considered a local maxima because it does not have a next node.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [2, 105].
  • +
  • 1 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/2061-number-of-spaces-cleaning-robot-cleaned/README.md b/final/2061-number-of-spaces-cleaning-robot-cleaned.html similarity index 100% rename from 2061-number-of-spaces-cleaning-robot-cleaned/README.md rename to final/2061-number-of-spaces-cleaning-robot-cleaned.html diff --git a/2073-time-needed-to-buy-tickets/README.md b/final/2073-time-needed-to-buy-tickets.html similarity index 100% rename from 2073-time-needed-to-buy-tickets/README.md rename to final/2073-time-needed-to-buy-tickets.html diff --git a/2083-substrings-that-begin-and-end-with-the-same-letter/README.md b/final/2083-substrings-that-begin-and-end-with-the-same-letter.html similarity index 100% rename from 2083-substrings-that-begin-and-end-with-the-same-letter/README.md rename to final/2083-substrings-that-begin-and-end-with-the-same-letter.html diff --git a/2092-find-all-people-with-secret/README.md b/final/2092-find-all-people-with-secret.html similarity index 100% rename from 2092-find-all-people-with-secret/README.md rename to final/2092-find-all-people-with-secret.html diff --git a/final/2093-minimum-cost-to-reach-city-with-discounts.html b/final/2093-minimum-cost-to-reach-city-with-discounts.html new file mode 100644 index 000000000..e69de29bb diff --git a/final/2096-step-by-step-directions-from-a-binary-tree-node-to-another.html b/final/2096-step-by-step-directions-from-a-binary-tree-node-to-another.html new file mode 100644 index 000000000..e69de29bb diff --git a/2108-find-first-palindromic-string-in-the-array/README.md b/final/2108-find-first-palindromic-string-in-the-array.html similarity index 100% rename from 2108-find-first-palindromic-string-in-the-array/README.md rename to final/2108-find-first-palindromic-string-in-the-array.html diff --git a/final/2125-number-of-laser-beams-in-a-bank.html b/final/2125-number-of-laser-beams-in-a-bank.html new file mode 100644 index 000000000..6b3c5a3f7 --- /dev/null +++ b/final/2125-number-of-laser-beams-in-a-bank.html @@ -0,0 +1,48 @@ +

2125. Number of Laser Beams in a Bank

Medium


Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the ith row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.

+ +

There is one laser beam between any two security devices if both conditions are met:

+ +
    +
  • The two devices are located on two different rows: r1 and r2, where r1 < r2.
  • +
  • For each row i where r1 < i < r2, there are no security devices in the ith row.
  • +
+ +

Laser beams are independent, i.e., one beam does not interfere nor join with another.

+ +

Return the total number of laser beams in the bank.

+ +

 

+

Example 1:

+ +
Input: bank = ["011001","000000","010100","001000"]
+Output: 8
+Explanation: Between each of the following device pairs, there is one beam. In total, there are 8 beams:
+ * bank[0][1] -- bank[2][1]
+ * bank[0][1] -- bank[2][3]
+ * bank[0][2] -- bank[2][1]
+ * bank[0][2] -- bank[2][3]
+ * bank[0][5] -- bank[2][1]
+ * bank[0][5] -- bank[2][3]
+ * bank[2][1] -- bank[3][2]
+ * bank[2][3] -- bank[3][2]
+Note that there is no beam between any device on the 0th row with any on the 3rd row.
+This is because the 2nd row contains security devices, which breaks the second condition.
+
+ +

Example 2:

+ +
Input: bank = ["000","111","000"]
+Output: 0
+Explanation: There does not exist two devices located on two different rows.
+
+ +

 

+

Constraints:

+ +
    +
  • m == bank.length
  • +
  • n == bank[i].length
  • +
  • 1 <= m, n <= 500
  • +
  • bank[i][j] is either '0' or '1'.
  • +
+
\ No newline at end of file diff --git a/final/2134-minimum-swaps-to-group-all-1s-together-ii.html b/final/2134-minimum-swaps-to-group-all-1s-together-ii.html new file mode 100644 index 000000000..2c4dc53e4 --- /dev/null +++ b/final/2134-minimum-swaps-to-group-all-1s-together-ii.html @@ -0,0 +1,46 @@ +

2134. Minimum Swaps to Group All 1's Together II

Medium


A swap is defined as taking two distinct positions in an array and swapping the values in them.

+ +

A circular array is defined as an array where we consider the first element and the last element to be adjacent.

+ +

Given a binary circular array nums, return the minimum number of swaps required to group all 1's present in the array together at any location.

+ +

 

+

Example 1:

+ +
Input: nums = [0,1,0,1,1,0,0]
+Output: 1
+Explanation: Here are a few of the ways to group all the 1's together:
+[0,0,1,1,1,0,0] using 1 swap.
+[0,1,1,1,0,0,0] using 1 swap.
+[1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array).
+There is no way to group all 1's together with 0 swaps.
+Thus, the minimum number of swaps required is 1.
+
+ +

Example 2:

+ +
Input: nums = [0,1,1,1,0,0,1,1,0]
+Output: 2
+Explanation: Here are a few of the ways to group all the 1's together:
+[1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array).
+[1,1,1,1,1,0,0,0,0] using 2 swaps.
+There is no way to group all 1's together with 0 or 1 swaps.
+Thus, the minimum number of swaps required is 2.
+
+ +

Example 3:

+ +
Input: nums = [1,1,0,0,1]
+Output: 0
+Explanation: All the 1's are already grouped together due to the circular property of the array.
+Thus, the minimum number of swaps required is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • nums[i] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/2141-maximum-running-time-of-n-computers/README.md b/final/2141-maximum-running-time-of-n-computers.html similarity index 100% rename from 2141-maximum-running-time-of-n-computers/README.md rename to final/2141-maximum-running-time-of-n-computers.html diff --git a/2147-number-of-ways-to-divide-a-long-corridor/README.md b/final/2147-number-of-ways-to-divide-a-long-corridor.html similarity index 100% rename from 2147-number-of-ways-to-divide-a-long-corridor/README.md rename to final/2147-number-of-ways-to-divide-a-long-corridor.html diff --git a/final/2149-rearrange-array-elements-by-sign.html b/final/2149-rearrange-array-elements-by-sign.html new file mode 100644 index 000000000..06869c95b --- /dev/null +++ b/final/2149-rearrange-array-elements-by-sign.html @@ -0,0 +1,42 @@ +

2149. Rearrange Array Elements by Sign

Medium


You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.

+ +

You should rearrange the elements of nums such that the modified array follows the given conditions:

+ +
    +
  1. Every consecutive pair of integers have opposite signs.
  2. +
  3. For all integers with the same sign, the order in which they were present in nums is preserved.
  4. +
  5. The rearranged array begins with a positive integer.
  6. +
+ +

Return the modified array after rearranging the elements to satisfy the aforementioned conditions.

+ +

 

+

Example 1:

+ +
Input: nums = [3,1,-2,-5,2,-4]
+Output: [3,-2,1,-5,2,-4]
+Explanation:
+The positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].
+The only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].
+Other ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.  
+
+ +

Example 2:

+ +
Input: nums = [-1,1]
+Output: [1,-1]
+Explanation:
+1 is the only positive integer and -1 the only negative integer in nums.
+So nums is rearranged to [1,-1].
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 2 * 105
  • +
  • nums.length is even
  • +
  • 1 <= |nums[i]| <= 105
  • +
  • nums consists of equal number of positive and negative integers.
  • +
+
\ No newline at end of file diff --git a/2181-merge-nodes-in-between-zeros/README.md b/final/2181-merge-nodes-in-between-zeros.html similarity index 100% rename from 2181-merge-nodes-in-between-zeros/README.md rename to final/2181-merge-nodes-in-between-zeros.html diff --git a/final/2191-sort-the-jumbled-numbers.html b/final/2191-sort-the-jumbled-numbers.html new file mode 100644 index 000000000..c230b1a84 --- /dev/null +++ b/final/2191-sort-the-jumbled-numbers.html @@ -0,0 +1,47 @@ +

2191. Sort the Jumbled Numbers

Medium


You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.

+ +

The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.

+ +

You are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.

+ +

Notes:

+ +
    +
  • Elements with the same mapped values should appear in the same relative order as in the input.
  • +
  • The elements of nums should only be sorted based on their mapped values and not be replaced by them.
  • +
+ +

 

+

Example 1:

+ +
Input: mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]
+Output: [338,38,991]
+Explanation: 
+Map the number 991 as follows:
+1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.
+2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.
+Therefore, the mapped value of 991 is 669.
+338 maps to 007, or 7 after removing the leading zeros.
+38 maps to 07, which is also 7 after removing leading zeros.
+Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.
+Thus, the sorted array is [338,38,991].
+
+ +

Example 2:

+ +
Input: mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]
+Output: [123,456,789]
+Explanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].
+
+ +

 

+

Constraints:

+ +
    +
  • mapping.length == 10
  • +
  • 0 <= mapping[i] <= 9
  • +
  • All the values of mapping[i] are unique.
  • +
  • 1 <= nums.length <= 3 * 104
  • +
  • 0 <= nums[i] < 109
  • +
+
\ No newline at end of file diff --git a/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/README.md b/final/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph.html similarity index 100% rename from 2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/README.md rename to final/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph.html diff --git a/final/2196-create-binary-tree-from-descriptions.html b/final/2196-create-binary-tree-from-descriptions.html new file mode 100644 index 000000000..3d44829bf --- /dev/null +++ b/final/2196-create-binary-tree-from-descriptions.html @@ -0,0 +1,39 @@ +

2196. Create Binary Tree From Descriptions

Medium


You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore,

+ +
    +
  • If isLefti == 1, then childi is the left child of parenti.
  • +
  • If isLefti == 0, then childi is the right child of parenti.
  • +
+ +

Construct the binary tree described by descriptions and return its root.

+ +

The test cases will be generated such that the binary tree is valid.

+ +

 

+

Example 1:

+ +
Input: descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]]
+Output: [50,20,80,15,17,19]
+Explanation: The root node is the node with value 50 since it has no parent.
+The resulting binary tree is shown in the diagram.
+
+ +

Example 2:

+ +
Input: descriptions = [[1,2,1],[2,3,0],[3,4,1]]
+Output: [1,2,null,null,3,4]
+Explanation: The root node is the node with value 1 since it has no parent.
+The resulting binary tree is shown in the diagram.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= descriptions.length <= 104
  • +
  • descriptions[i].length == 3
  • +
  • 1 <= parenti, childi <= 105
  • +
  • 0 <= isLefti <= 1
  • +
  • The binary tree described by descriptions is valid.
  • +
+
\ No newline at end of file diff --git a/2225-find-players-with-zero-or-one-losses/README.md b/final/2225-find-players-with-zero-or-one-losses.html similarity index 100% rename from 2225-find-players-with-zero-or-one-losses/README.md rename to final/2225-find-players-with-zero-or-one-losses.html diff --git a/2251-number-of-flowers-in-full-bloom/README.md b/final/2251-number-of-flowers-in-full-bloom.html similarity index 100% rename from 2251-number-of-flowers-in-full-bloom/README.md rename to final/2251-number-of-flowers-in-full-bloom.html diff --git a/2264-largest-3-same-digit-number-in-string/README.md b/final/2264-largest-3-same-digit-number-in-string.html similarity index 100% rename from 2264-largest-3-same-digit-number-in-string/README.md rename to final/2264-largest-3-same-digit-number-in-string.html diff --git a/2265-count-nodes-equal-to-average-of-subtree/README.md b/final/2265-count-nodes-equal-to-average-of-subtree.html similarity index 100% rename from 2265-count-nodes-equal-to-average-of-subtree/README.md rename to final/2265-count-nodes-equal-to-average-of-subtree.html diff --git a/final/2285-maximum-total-importance-of-roads.html b/final/2285-maximum-total-importance-of-roads.html new file mode 100644 index 000000000..e69de29bb diff --git a/2331-evaluate-boolean-binary-tree/README.md b/final/2331-evaluate-boolean-binary-tree.html similarity index 100% rename from 2331-evaluate-boolean-binary-tree/README.md rename to final/2331-evaluate-boolean-binary-tree.html diff --git a/final/2353-design-a-food-rating-system.html b/final/2353-design-a-food-rating-system.html new file mode 100644 index 000000000..085588a8b --- /dev/null +++ b/final/2353-design-a-food-rating-system.html @@ -0,0 +1,63 @@ +

2353. Design a Food Rating System

Medium


Design a food rating system that can do the following:

+ +
    +
  • Modify the rating of a food item listed in the system.
  • +
  • Return the highest-rated food item for a type of cuisine in the system.
  • +
+ +

Implement the FoodRatings class:

+ +
    +
  • FoodRatings(String[] foods, String[] cuisines, int[] ratings) Initializes the system. The food items are described by foods, cuisines and ratings, all of which have a length of n. + +
      +
    • foods[i] is the name of the ith food,
    • +
    • cuisines[i] is the type of cuisine of the ith food, and
    • +
    • ratings[i] is the initial rating of the ith food.
    • +
    +
  • +
  • void changeRating(String food, int newRating) Changes the rating of the food item with the name food.
  • +
  • String highestRated(String cuisine) Returns the name of the food item that has the highest rating for the given type of cuisine. If there is a tie, return the item with the lexicographically smaller name.
  • +
+ +

Note that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.

+ +

 

+

Example 1:

+ +
Input
+["FoodRatings", "highestRated", "highestRated", "changeRating", "highestRated", "changeRating", "highestRated"]
+[[["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]], ["korean"], ["japanese"], ["sushi", 16], ["japanese"], ["ramen", 16], ["japanese"]]
+Output
+[null, "kimchi", "ramen", null, "sushi", null, "ramen"]
+
+Explanation
+FoodRatings foodRatings = new FoodRatings(["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]);
+foodRatings.highestRated("korean"); // return "kimchi"
+                                    // "kimchi" is the highest rated korean food with a rating of 9.
+foodRatings.highestRated("japanese"); // return "ramen"
+                                      // "ramen" is the highest rated japanese food with a rating of 14.
+foodRatings.changeRating("sushi", 16); // "sushi" now has a rating of 16.
+foodRatings.highestRated("japanese"); // return "sushi"
+                                      // "sushi" is the highest rated japanese food with a rating of 16.
+foodRatings.changeRating("ramen", 16); // "ramen" now has a rating of 16.
+foodRatings.highestRated("japanese"); // return "ramen"
+                                      // Both "sushi" and "ramen" have a rating of 16.
+                                      // However, "ramen" is lexicographically smaller than "sushi".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 2 * 104
  • +
  • n == foods.length == cuisines.length == ratings.length
  • +
  • 1 <= foods[i].length, cuisines[i].length <= 10
  • +
  • foods[i], cuisines[i] consist of lowercase English letters.
  • +
  • 1 <= ratings[i] <= 108
  • +
  • All the strings in foods are distinct.
  • +
  • food will be the name of a food item in the system across all calls to changeRating.
  • +
  • cuisine will be a type of cuisine of at least one food item in the system across all calls to highestRated.
  • +
  • At most 2 * 104 calls in total will be made to changeRating and highestRated.
  • +
+
\ No newline at end of file diff --git a/2355-maximum-number-of-books-you-can-take/README.md b/final/2355-maximum-number-of-books-you-can-take.html similarity index 100% rename from 2355-maximum-number-of-books-you-can-take/README.md rename to final/2355-maximum-number-of-books-you-can-take.html diff --git a/2361-minimum-costs-using-the-train-line/README.md b/final/2361-minimum-costs-using-the-train-line.html similarity index 100% rename from 2361-minimum-costs-using-the-train-line/README.md rename to final/2361-minimum-costs-using-the-train-line.html diff --git a/2366-minimum-replacements-to-sort-the-array/README.md b/final/2366-minimum-replacements-to-sort-the-array.html similarity index 100% rename from 2366-minimum-replacements-to-sort-the-array/README.md rename to final/2366-minimum-replacements-to-sort-the-array.html diff --git a/2369-check-if-there-is-a-valid-partition-for-the-array/README.md b/final/2369-check-if-there-is-a-valid-partition-for-the-array.html similarity index 100% rename from 2369-check-if-there-is-a-valid-partition-for-the-array/README.md rename to final/2369-check-if-there-is-a-valid-partition-for-the-array.html diff --git a/final/2370-longest-ideal-subsequence.html b/final/2370-longest-ideal-subsequence.html new file mode 100644 index 000000000..17c7257e5 --- /dev/null +++ b/final/2370-longest-ideal-subsequence.html @@ -0,0 +1,37 @@ +

2370. Longest Ideal Subsequence

Medium


You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:

+ +
    +
  • t is a subsequence of the string s.
  • +
  • The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.
  • +
+ +

Return the length of the longest ideal string.

+ +

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

+ +

Note that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of 'a' and 'z' is 25, not 1.

+ +

 

+

Example 1:

+ +
Input: s = "acfgbd", k = 2
+Output: 4
+Explanation: The longest ideal string is "acbd". The length of this string is 4, so 4 is returned.
+Note that "acfgbd" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.
+ +

Example 2:

+ +
Input: s = "abcd", k = 3
+Output: 4
+Explanation: The longest ideal string is "abcd". The length of this string is 4, so 4 is returned.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • 0 <= k <= 25
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2373-largest-local-values-in-a-matrix/README.md b/final/2373-largest-local-values-in-a-matrix.html similarity index 100% rename from 2373-largest-local-values-in-a-matrix/README.md rename to final/2373-largest-local-values-in-a-matrix.html diff --git a/final/2385-amount-of-time-for-binary-tree-to-be-infected.html b/final/2385-amount-of-time-for-binary-tree-to-be-infected.html new file mode 100644 index 000000000..4c9f31b3c --- /dev/null +++ b/final/2385-amount-of-time-for-binary-tree-to-be-infected.html @@ -0,0 +1,42 @@ +

2385. Amount of Time for Binary Tree to Be Infected

Medium


You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start.

+ +

Each minute, a node becomes infected if:

+ +
    +
  • The node is currently uninfected.
  • +
  • The node is adjacent to an infected node.
  • +
+ +

Return the number of minutes needed for the entire tree to be infected.

+ +

 

+

Example 1:

+ +
Input: root = [1,5,3,null,4,10,6,9,2], start = 3
+Output: 4
+Explanation: The following nodes are infected during:
+- Minute 0: Node 3
+- Minute 1: Nodes 1, 10 and 6
+- Minute 2: Node 5
+- Minute 3: Node 4
+- Minute 4: Nodes 9 and 2
+It takes 4 minutes for the whole tree to be infected so we return 4.
+
+ +

Example 2:

+ +
Input: root = [1], start = 1
+Output: 0
+Explanation: At minute 0, the only node in the tree is infected so we return 0.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 105].
  • +
  • 1 <= Node.val <= 105
  • +
  • Each node has a unique value.
  • +
  • A node with a value of start exists in the tree.
  • +
+
\ No newline at end of file diff --git a/final/2391-minimum-amount-of-time-to-collect-garbage.html b/final/2391-minimum-amount-of-time-to-collect-garbage.html new file mode 100644 index 000000000..8a44ad8cc --- /dev/null +++ b/final/2391-minimum-amount-of-time-to-collect-garbage.html @@ -0,0 +1,56 @@ +

2391. Minimum Amount of Time to Collect Garbage

Medium


You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.

+ +

You are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.

+ +

There are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.

+ +

Only one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.

+ +

Return the minimum number of minutes needed to pick up all the garbage.

+ +

 

+

Example 1:

+ +
Input: garbage = ["G","P","GP","GG"], travel = [2,4,3]
+Output: 21
+Explanation:
+The paper garbage truck:
+1. Travels from house 0 to house 1
+2. Collects the paper garbage at house 1
+3. Travels from house 1 to house 2
+4. Collects the paper garbage at house 2
+Altogether, it takes 8 minutes to pick up all the paper garbage.
+The glass garbage truck:
+1. Collects the glass garbage at house 0
+2. Travels from house 0 to house 1
+3. Travels from house 1 to house 2
+4. Collects the glass garbage at house 2
+5. Travels from house 2 to house 3
+6. Collects the glass garbage at house 3
+Altogether, it takes 13 minutes to pick up all the glass garbage.
+Since there is no metal garbage, we do not need to consider the metal garbage truck.
+Therefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.
+
+ +

Example 2:

+ +
Input: garbage = ["MMM","PGM","GP"], travel = [3,10]
+Output: 37
+Explanation:
+The metal garbage truck takes 7 minutes to pick up all the metal garbage.
+The paper garbage truck takes 15 minutes to pick up all the paper garbage.
+The glass garbage truck takes 15 minutes to pick up all the glass garbage.
+It takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= garbage.length <= 105
  • +
  • garbage[i] consists of only the letters 'M', 'P', and 'G'.
  • +
  • 1 <= garbage[i].length <= 10
  • +
  • travel.length == garbage.length - 1
  • +
  • 1 <= travel[i] <= 100
  • +
+
\ No newline at end of file diff --git a/2392-build-a-matrix-with-conditions/README.md b/final/2392-build-a-matrix-with-conditions.html similarity index 100% rename from 2392-build-a-matrix-with-conditions/README.md rename to final/2392-build-a-matrix-with-conditions.html diff --git a/2393-count-strictly-increasing-subarrays/README.md b/final/2393-count-strictly-increasing-subarrays.html similarity index 100% rename from 2393-count-strictly-increasing-subarrays/README.md rename to final/2393-count-strictly-increasing-subarrays.html diff --git a/2402-meeting-rooms-iii/README.md b/final/2402-meeting-rooms-iii.html similarity index 100% rename from 2402-meeting-rooms-iii/README.md rename to final/2402-meeting-rooms-iii.html diff --git a/2418-sort-the-people/README.md b/final/2418-sort-the-people.html similarity index 100% rename from 2418-sort-the-people/README.md rename to final/2418-sort-the-people.html diff --git a/final/2433-find-the-original-array-of-prefix-xor.html b/final/2433-find-the-original-array-of-prefix-xor.html new file mode 100644 index 000000000..380a3f994 --- /dev/null +++ b/final/2433-find-the-original-array-of-prefix-xor.html @@ -0,0 +1,38 @@ +

2433. Find The Original Array of Prefix Xor

Medium


You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:

+ +
    +
  • pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].
  • +
+ +

Note that ^ denotes the bitwise-xor operation.

+ +

It can be proven that the answer is unique.

+ +

 

+

Example 1:

+ +
Input: pref = [5,2,0,3,1]
+Output: [5,7,2,3,2]
+Explanation: From the array [5,7,2,3,2] we have the following:
+- pref[0] = 5.
+- pref[1] = 5 ^ 7 = 2.
+- pref[2] = 5 ^ 7 ^ 2 = 0.
+- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
+- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
+
+ +

Example 2:

+ +
Input: pref = [13]
+Output: [13]
+Explanation: We have pref[0] = arr[0] = 13.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= pref.length <= 105
  • +
  • 0 <= pref[i] <= 106
  • +
+
\ No newline at end of file diff --git a/2441-largest-positive-integer-that-exists-with-its-negative/README.md b/final/2441-largest-positive-integer-that-exists-with-its-negative.html similarity index 100% rename from 2441-largest-positive-integer-that-exists-with-its-negative/README.md rename to final/2441-largest-positive-integer-that-exists-with-its-negative.html diff --git a/2444-count-subarrays-with-fixed-bounds/README.md b/final/2444-count-subarrays-with-fixed-bounds.html similarity index 100% rename from 2444-count-subarrays-with-fixed-bounds/README.md rename to final/2444-count-subarrays-with-fixed-bounds.html diff --git a/2473-minimum-cost-to-buy-apples/README.md b/final/2473-minimum-cost-to-buy-apples.html similarity index 100% rename from 2473-minimum-cost-to-buy-apples/README.md rename to final/2473-minimum-cost-to-buy-apples.html diff --git a/final/2482-difference-between-ones-and-zeros-in-row-and-column.html b/final/2482-difference-between-ones-and-zeros-in-row-and-column.html new file mode 100644 index 000000000..3353ff560 --- /dev/null +++ b/final/2482-difference-between-ones-and-zeros-in-row-and-column.html @@ -0,0 +1,55 @@ +

2482. Difference Between Ones and Zeros in Row and Column

Medium


You are given a 0-indexed m x n binary matrix grid.

+ +

A 0-indexed m x n difference matrix diff is created with the following procedure:

+ +
    +
  • Let the number of ones in the ith row be onesRowi.
  • +
  • Let the number of ones in the jth column be onesColj.
  • +
  • Let the number of zeros in the ith row be zerosRowi.
  • +
  • Let the number of zeros in the jth column be zerosColj.
  • +
  • diff[i][j] = onesRowi + onesColj - zerosRowi - zerosColj
  • +
+ +

Return the difference matrix diff.

+ +

 

+

Example 1:

+ +
Input: grid = [[0,1,1],[1,0,1],[0,0,1]]
+Output: [[0,0,4],[0,0,4],[-2,-2,2]]
+Explanation:
+- diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 2 + 1 - 1 - 2 = 0 
+- diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 2 + 1 - 1 - 2 = 0 
+- diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 2 + 3 - 1 - 0 = 4 
+- diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 2 + 1 - 1 - 2 = 0 
+- diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 2 + 1 - 1 - 2 = 0 
+- diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 2 + 3 - 1 - 0 = 4 
+- diff[2][0] = onesRow2 + onesCol0 - zerosRow2 - zerosCol0 = 1 + 1 - 2 - 2 = -2
+- diff[2][1] = onesRow2 + onesCol1 - zerosRow2 - zerosCol1 = 1 + 1 - 2 - 2 = -2
+- diff[2][2] = onesRow2 + onesCol2 - zerosRow2 - zerosCol2 = 1 + 3 - 2 - 0 = 2
+
+ +

Example 2:

+ +
Input: grid = [[1,1,1],[1,1,1]]
+Output: [[5,5,5],[5,5,5]]
+Explanation:
+- diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 3 + 2 - 0 - 0 = 5
+- diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 3 + 2 - 0 - 0 = 5
+- diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 3 + 2 - 0 - 0 = 5
+- diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 3 + 2 - 0 - 0 = 5
+- diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 3 + 2 - 0 - 0 = 5
+- diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 3 + 2 - 0 - 0 = 5
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 105
  • +
  • 1 <= m * n <= 105
  • +
  • grid[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/2483-minimum-penalty-for-a-shop/README.md b/final/2483-minimum-penalty-for-a-shop.html similarity index 100% rename from 2483-minimum-penalty-for-a-shop/README.md rename to final/2483-minimum-penalty-for-a-shop.html diff --git a/2485-find-the-pivot-integer/README.md b/final/2485-find-the-pivot-integer.html similarity index 100% rename from 2485-find-the-pivot-integer/README.md rename to final/2485-find-the-pivot-integer.html diff --git a/final/2486-append-characters-to-string-to-make-subsequence.html b/final/2486-append-characters-to-string-to-make-subsequence.html new file mode 100644 index 000000000..3029053ca --- /dev/null +++ b/final/2486-append-characters-to-string-to-make-subsequence.html @@ -0,0 +1,40 @@ +

2486. Append Characters to String to Make Subsequence

Medium


You are given two strings s and t consisting of only lowercase English letters.

+ +

Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.

+ +

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

+ +

 

+

Example 1:

+ +
Input: s = "coaching", t = "coding"
+Output: 4
+Explanation: Append the characters "ding" to the end of s so that s = "coachingding".
+Now, t is a subsequence of s ("coachingding").
+It can be shown that appending any 3 characters to the end of s will never make t a subsequence.
+
+ +

Example 2:

+ +
Input: s = "abcde", t = "a"
+Output: 0
+Explanation: t is already a subsequence of s ("abcde").
+
+ +

Example 3:

+ +
Input: s = "z", t = "abcde"
+Output: 5
+Explanation: Append the characters "abcde" to the end of s so that s = "zabcde".
+Now, t is a subsequence of s ("zabcde").
+It can be shown that appending any 4 characters to the end of s will never make t a subsequence.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length, t.length <= 105
  • +
  • s and t consist only of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/final/2487-remove-nodes-from-linked-list.html b/final/2487-remove-nodes-from-linked-list.html new file mode 100644 index 000000000..e69de29bb diff --git a/2505-bitwise-or-of-all-subsequence-sums/README.md b/final/2505-bitwise-or-of-all-subsequence-sums.html similarity index 100% rename from 2505-bitwise-or-of-all-subsequence-sums/README.md rename to final/2505-bitwise-or-of-all-subsequence-sums.html diff --git a/final/2540-minimum-common-value.html b/final/2540-minimum-common-value.html new file mode 100644 index 000000000..e69de29bb diff --git a/2582-pass-the-pillow/README.md b/final/2582-pass-the-pillow.html similarity index 100% rename from 2582-pass-the-pillow/README.md rename to final/2582-pass-the-pillow.html diff --git a/final/2597-the-number-of-beautiful-subsets.html b/final/2597-the-number-of-beautiful-subsets.html new file mode 100644 index 000000000..1c16e7bef --- /dev/null +++ b/final/2597-the-number-of-beautiful-subsets.html @@ -0,0 +1,33 @@ +

2597. The Number of Beautiful Subsets

Medium


You are given an array nums of positive integers and a positive integer k.

+ +

A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.

+ +

Return the number of non-empty beautiful subsets of the array nums.

+ +

A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.

+ +

 

+

Example 1:

+ +
Input: nums = [2,4,6], k = 2
+Output: 4
+Explanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].
+It can be proved that there are only 4 beautiful subsets in the array [2,4,6].
+
+ +

Example 2:

+ +
Input: nums = [1], k = 1
+Output: 1
+Explanation: The beautiful subset of the array nums is [1].
+It can be proved that there is only 1 beautiful subset in the array [1].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 20
  • +
  • 1 <= nums[i], k <= 1000
  • +
+
\ No newline at end of file diff --git a/2610-convert-an-array-into-a-2d-array-with-conditions/README.md b/final/2610-convert-an-array-into-a-2d-array-with-conditions.html similarity index 100% rename from 2610-convert-an-array-into-a-2d-array-with-conditions/README.md rename to final/2610-convert-an-array-into-a-2d-array-with-conditions.html diff --git a/2616-minimize-the-maximum-difference-of-pairs/README.md b/final/2616-minimize-the-maximum-difference-of-pairs.html similarity index 100% rename from 2616-minimize-the-maximum-difference-of-pairs/README.md rename to final/2616-minimize-the-maximum-difference-of-pairs.html diff --git a/2618-check-if-object-instance-of-class/README.md b/final/2618-check-if-object-instance-of-class.html similarity index 100% rename from 2618-check-if-object-instance-of-class/README.md rename to final/2618-check-if-object-instance-of-class.html diff --git a/2619-array-prototype-last/README.md b/final/2619-array-prototype-last.html similarity index 100% rename from 2619-array-prototype-last/README.md rename to final/2619-array-prototype-last.html diff --git a/2620-counter/README.md b/final/2620-counter.html similarity index 100% rename from 2620-counter/README.md rename to final/2620-counter.html diff --git a/2621-sleep/README.md b/final/2621-sleep.html similarity index 100% rename from 2621-sleep/README.md rename to final/2621-sleep.html diff --git a/2622-cache-with-time-limit/README.md b/final/2622-cache-with-time-limit.html similarity index 100% rename from 2622-cache-with-time-limit/README.md rename to final/2622-cache-with-time-limit.html diff --git a/2623-memoize/README.md b/final/2623-memoize.html similarity index 100% rename from 2623-memoize/README.md rename to final/2623-memoize.html diff --git a/2624-snail-traversal/README.md b/final/2624-snail-traversal.html similarity index 100% rename from 2624-snail-traversal/README.md rename to final/2624-snail-traversal.html diff --git a/2625-flatten-deeply-nested-array/README.md b/final/2625-flatten-deeply-nested-array.html similarity index 100% rename from 2625-flatten-deeply-nested-array/README.md rename to final/2625-flatten-deeply-nested-array.html diff --git a/2626-array-reduce-transformation/README.md b/final/2626-array-reduce-transformation.html similarity index 100% rename from 2626-array-reduce-transformation/README.md rename to final/2626-array-reduce-transformation.html diff --git a/2627-debounce/README.md b/final/2627-debounce.html similarity index 100% rename from 2627-debounce/README.md rename to final/2627-debounce.html diff --git a/2628-json-deep-equal/README.md b/final/2628-json-deep-equal.html similarity index 100% rename from 2628-json-deep-equal/README.md rename to final/2628-json-deep-equal.html diff --git a/2629-function-composition/README.md b/final/2629-function-composition.html similarity index 100% rename from 2629-function-composition/README.md rename to final/2629-function-composition.html diff --git a/2630-memoize-ii/README.md b/final/2630-memoize-ii.html similarity index 100% rename from 2630-memoize-ii/README.md rename to final/2630-memoize-ii.html diff --git a/2631-group-by/README.md b/final/2631-group-by.html similarity index 100% rename from 2631-group-by/README.md rename to final/2631-group-by.html diff --git a/2632-curry/README.md b/final/2632-curry.html similarity index 100% rename from 2632-curry/README.md rename to final/2632-curry.html diff --git a/2633-convert-object-to-json-string/README.md b/final/2633-convert-object-to-json-string.html similarity index 100% rename from 2633-convert-object-to-json-string/README.md rename to final/2633-convert-object-to-json-string.html diff --git a/2634-filter-elements-from-array/README.md b/final/2634-filter-elements-from-array.html similarity index 100% rename from 2634-filter-elements-from-array/README.md rename to final/2634-filter-elements-from-array.html diff --git a/2635-apply-transform-over-each-element-in-array/README.md b/final/2635-apply-transform-over-each-element-in-array.html similarity index 100% rename from 2635-apply-transform-over-each-element-in-array/README.md rename to final/2635-apply-transform-over-each-element-in-array.html diff --git a/2636-promise-pool/README.md b/final/2636-promise-pool.html similarity index 100% rename from 2636-promise-pool/README.md rename to final/2636-promise-pool.html diff --git a/2637-promise-time-limit/README.md b/final/2637-promise-time-limit.html similarity index 100% rename from 2637-promise-time-limit/README.md rename to final/2637-promise-time-limit.html diff --git a/2642-design-graph-with-shortest-path-calculator/README.md b/final/2642-design-graph-with-shortest-path-calculator.html similarity index 100% rename from 2642-design-graph-with-shortest-path-calculator/README.md rename to final/2642-design-graph-with-shortest-path-calculator.html diff --git a/2648-generate-fibonacci-sequence/README.md b/final/2648-generate-fibonacci-sequence.html similarity index 100% rename from 2648-generate-fibonacci-sequence/README.md rename to final/2648-generate-fibonacci-sequence.html diff --git a/2649-nested-array-generator/README.md b/final/2649-nested-array-generator.html similarity index 100% rename from 2649-nested-array-generator/README.md rename to final/2649-nested-array-generator.html diff --git a/2650-design-cancellable-function/README.md b/final/2650-design-cancellable-function.html similarity index 100% rename from 2650-design-cancellable-function/README.md rename to final/2650-design-cancellable-function.html diff --git a/2665-counter-ii/README.md b/final/2665-counter-ii.html similarity index 100% rename from 2665-counter-ii/README.md rename to final/2665-counter-ii.html diff --git a/2666-allow-one-function-call/README.md b/final/2666-allow-one-function-call.html similarity index 100% rename from 2666-allow-one-function-call/README.md rename to final/2666-allow-one-function-call.html diff --git a/2667-create-hello-world-function/README.md b/final/2667-create-hello-world-function.html similarity index 100% rename from 2667-create-hello-world-function/README.md rename to final/2667-create-hello-world-function.html diff --git a/2675-array-of-objects-to-matrix/README.md b/final/2675-array-of-objects-to-matrix.html similarity index 100% rename from 2675-array-of-objects-to-matrix/README.md rename to final/2675-array-of-objects-to-matrix.html diff --git a/2676-throttle/README.md b/final/2676-throttle.html similarity index 100% rename from 2676-throttle/README.md rename to final/2676-throttle.html diff --git a/2677-chunk-array/README.md b/final/2677-chunk-array.html similarity index 100% rename from 2677-chunk-array/README.md rename to final/2677-chunk-array.html diff --git a/2678-number-of-senior-citizens/README.md b/final/2678-number-of-senior-citizens.html similarity index 100% rename from 2678-number-of-senior-citizens/README.md rename to final/2678-number-of-senior-citizens.html diff --git a/2690-infinite-method-object/README.md b/final/2690-infinite-method-object.html similarity index 100% rename from 2690-infinite-method-object/README.md rename to final/2690-infinite-method-object.html diff --git a/2692-make-object-immutable/README.md b/final/2692-make-object-immutable.html similarity index 100% rename from 2692-make-object-immutable/README.md rename to final/2692-make-object-immutable.html diff --git a/final/2694-event-emitter.html b/final/2694-event-emitter.html new file mode 100644 index 000000000..1771223aa --- /dev/null +++ b/final/2694-event-emitter.html @@ -0,0 +1,73 @@ +

2694. Event Emitter

Medium


Design an EventEmitter class. This interface is similar (but with some differences) to the one found in Node.js or the Event Target interface of the DOM. The EventEmitter should allow for subscribing to events and emitting them.

+ +

Your EventEmitter class should have the following two methods:

+ +
    +
  • subscribe - This method takes in two arguments: the name of an event as a string and a callback function. This callback function will later be called when the event is emitted.
    + An event should be able to have multiple listeners for the same event. When emitting an event with multiple callbacks, each should be called in the order in which they were subscribed. An array of results should be returned. You can assume no callbacks passed to subscribe are referentially identical.
    + The subscribe method should also return an object with an unsubscribe method that enables the user to unsubscribe. When it is called, the callback should be removed from the list of subscriptions and undefined should be returned.
  • +
  • emit - This method takes in two arguments: the name of an event as a string and an optional array of arguments that will be passed to the callback(s). If there are no callbacks subscribed to the given event, return an empty array. Otherwise, return an array of the results of all callback calls in the order they were subscribed.
  • +
+ +

 

+

Example 1:

+ +
Input: actions = ["EventEmitter", "emit", "subscribe", "subscribe", "emit"], values = [[], ["firstEvent", "function cb1() { return 5; }"],  ["firstEvent", "function cb1() { return 5; }"], ["firstEvent"]]
+Output: [[],["emitted",[]],["subscribed"],["subscribed"],["emitted",[5,6]]]
+Explanation: 
+const emitter = new EventEmitter();
+emitter.emit("firstEvent"); // [], no callback are subscribed yet
+emitter.subscribe("firstEvent", function cb1() { return 5; });
+emitter.subscribe("firstEvent", function cb2() { return 6; });
+emitter.emit("firstEvent"); // [5, 6], returns the output of cb1 and cb2
+
+ +

Example 2:

+ +
Input: actions = ["EventEmitter", "subscribe", "emit", "emit"], values = [[], ["firstEvent", "function cb1(...args) { return args.join(','); }"], ["firstEvent", [1,2,3]], ["firstEvent", [3,4,6]]]
+Output: [[],["subscribed"],["emitted",["1,2,3"]],["emitted",["3,4,6"]]]
+Explanation: Note that the emit method should be able to accept an OPTIONAL array of arguments.
+
+const emitter = new EventEmitter();
+emitter.subscribe("firstEvent, function cb1(...args) { return args.join(','); });
+emitter.emit("firstEvent", [1, 2, 3]); // ["1,2,3"]
+emitter.emit("firstEvent", [3, 4, 6]); // ["3,4,6"]
+
+ +

Example 3:

+ +
Input: actions = ["EventEmitter", "subscribe", "emit", "unsubscribe", "emit"], values = [[], ["firstEvent", "(...args) => args.join(',')"], ["firstEvent", [1,2,3]], [0], ["firstEvent", [4,5,6]]]
+Output: [[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[]]]
+Explanation:
+const emitter = new EventEmitter();
+const sub = emitter.subscribe("firstEvent", (...args) => args.join(','));
+emitter.emit("firstEvent", [1, 2, 3]); // ["1,2,3"]
+sub.unsubscribe(); // undefined
+emitter.emit("firstEvent", [4, 5, 6]); // [], there are no subscriptions
+
+ +

Example 4:

+ +
Input: actions = ["EventEmitter", "subscribe", "subscribe", "unsubscribe", "emit"], values = [[], ["firstEvent", "x => x + 1"], ["firstEvent", "x => x + 2"], [0], ["firstEvent", [5]]]
+Output: [[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[7]]]
+Explanation:
+const emitter = new EventEmitter();
+const sub1 = emitter.subscribe("firstEvent", x => x + 1);
+const sub2 = emitter.subscribe("firstEvent", x => x + 2);
+sub1.unsubscribe(); // undefined
+emitter.emit("firstEvent", [5]); // [7]
+ +

 

+

Constraints:

+ +
    +
  • 1 <= actions.length <= 10
  • +
  • values.length === actions.length
  • +
  • All test cases are valid, e.g. you don't need to handle scenarios when unsubscribing from a non-existing subscription.
  • +
  • There are only 4 different actions: EventEmitter, emit, subscribe, and unsubscribe.
  • +
  • The EventEmitter action doesn't take any arguments.
  • +
  • The emit action takes between either 1 or 2 arguments. The first argument is the name of the event we want to emit, and the 2nd argument is passed to the callback functions.
  • +
  • The subscribe action takes 2 arguments, where the first one is the event name and the second is the callback function.
  • +
  • The unsubscribe action takes one argument, which is the 0-indexed order of the subscription made before.
  • +
+
\ No newline at end of file diff --git a/2695-array-wrapper/README.md b/final/2695-array-wrapper.html similarity index 100% rename from 2695-array-wrapper/README.md rename to final/2695-array-wrapper.html diff --git a/2703-return-length-of-arguments-passed/README.md b/final/2703-return-length-of-arguments-passed.html similarity index 100% rename from 2703-return-length-of-arguments-passed/README.md rename to final/2703-return-length-of-arguments-passed.html diff --git a/2704-to-be-or-not-to-be/README.md b/final/2704-to-be-or-not-to-be.html similarity index 100% rename from 2704-to-be-or-not-to-be/README.md rename to final/2704-to-be-or-not-to-be.html diff --git a/2705-compact-object/README.md b/final/2705-compact-object.html similarity index 100% rename from 2705-compact-object/README.md rename to final/2705-compact-object.html diff --git a/2706-buy-two-chocolates/README.md b/final/2706-buy-two-chocolates.html similarity index 100% rename from 2706-buy-two-chocolates/README.md rename to final/2706-buy-two-chocolates.html diff --git a/2707-extra-characters-in-a-string/README.md b/final/2707-extra-characters-in-a-string.html similarity index 100% rename from 2707-extra-characters-in-a-string/README.md rename to final/2707-extra-characters-in-a-string.html diff --git a/2709-greatest-common-divisor-traversal/README.md b/final/2709-greatest-common-divisor-traversal.html similarity index 100% rename from 2709-greatest-common-divisor-traversal/README.md rename to final/2709-greatest-common-divisor-traversal.html diff --git a/2715-execute-cancellable-function-with-delay/README.md b/final/2715-execute-cancellable-function-with-delay.html similarity index 100% rename from 2715-execute-cancellable-function-with-delay/README.md rename to final/2715-execute-cancellable-function-with-delay.html diff --git a/2721-execute-asynchronous-functions-in-parallel/README.md b/final/2721-execute-asynchronous-functions-in-parallel.html similarity index 100% rename from 2721-execute-asynchronous-functions-in-parallel/README.md rename to final/2721-execute-asynchronous-functions-in-parallel.html diff --git a/2722-join-two-arrays-by-id/README.md b/final/2722-join-two-arrays-by-id.html similarity index 100% rename from 2722-join-two-arrays-by-id/README.md rename to final/2722-join-two-arrays-by-id.html diff --git a/2723-add-two-promises/README.md b/final/2723-add-two-promises.html similarity index 100% rename from 2723-add-two-promises/README.md rename to final/2723-add-two-promises.html diff --git a/2724-sort-by/README.md b/final/2724-sort-by.html similarity index 100% rename from 2724-sort-by/README.md rename to final/2724-sort-by.html diff --git a/2725-interval-cancellation/README.md b/final/2725-interval-cancellation.html similarity index 100% rename from 2725-interval-cancellation/README.md rename to final/2725-interval-cancellation.html diff --git a/2726-calculator-with-method-chaining/README.md b/final/2726-calculator-with-method-chaining.html similarity index 100% rename from 2726-calculator-with-method-chaining/README.md rename to final/2726-calculator-with-method-chaining.html diff --git a/2727-is-object-empty/README.md b/final/2727-is-object-empty.html similarity index 100% rename from 2727-is-object-empty/README.md rename to final/2727-is-object-empty.html diff --git a/2742-painting-the-walls/README.md b/final/2742-painting-the-walls.html similarity index 100% rename from 2742-painting-the-walls/README.md rename to final/2742-painting-the-walls.html diff --git a/2743-count-substrings-without-repeating-character/README.md b/final/2743-count-substrings-without-repeating-character.html similarity index 100% rename from 2743-count-substrings-without-repeating-character/README.md rename to final/2743-count-substrings-without-repeating-character.html diff --git a/2751-robot-collisions/README.md b/final/2751-robot-collisions.html similarity index 100% rename from 2751-robot-collisions/README.md rename to final/2751-robot-collisions.html diff --git a/2762-continuous-subarrays/README.md b/final/2762-continuous-subarrays.html similarity index 100% rename from 2762-continuous-subarrays/README.md rename to final/2762-continuous-subarrays.html diff --git a/2778-sum-of-squares-of-special-elements/README.md b/final/2778-sum-of-squares-of-special-elements.html similarity index 100% rename from 2778-sum-of-squares-of-special-elements/README.md rename to final/2778-sum-of-squares-of-special-elements.html diff --git a/2784-check-if-array-is-good/README.md b/final/2784-check-if-array-is-good.html similarity index 100% rename from 2784-check-if-array-is-good/README.md rename to final/2784-check-if-array-is-good.html diff --git a/2785-sort-vowels-in-a-string/README.md b/final/2785-sort-vowels-in-a-string.html similarity index 100% rename from 2785-sort-vowels-in-a-string/README.md rename to final/2785-sort-vowels-in-a-string.html diff --git a/2788-split-strings-by-separator/README.md b/final/2788-split-strings-by-separator.html similarity index 100% rename from 2788-split-strings-by-separator/README.md rename to final/2788-split-strings-by-separator.html diff --git a/2789-largest-element-in-an-array-after-merge-operations/README.md b/final/2789-largest-element-in-an-array-after-merge-operations.html similarity index 100% rename from 2789-largest-element-in-an-array-after-merge-operations/README.md rename to final/2789-largest-element-in-an-array-after-merge-operations.html diff --git a/2798-number-of-employees-who-met-the-target/README.md b/final/2798-number-of-employees-who-met-the-target.html similarity index 100% rename from 2798-number-of-employees-who-met-the-target/README.md rename to final/2798-number-of-employees-who-met-the-target.html diff --git a/final/2802-find-the-k-th-lucky-number.html b/final/2802-find-the-k-th-lucky-number.html new file mode 100644 index 000000000..9bf499270 --- /dev/null +++ b/final/2802-find-the-k-th-lucky-number.html @@ -0,0 +1,33 @@ +

2802. Find The K-th Lucky Number

Medium


We know that 4 and 7 are lucky digits. Also, a number is called lucky if it contains only lucky digits.

+ +

You are given an integer k, return the kth lucky number represented as a string.

+ +

 

+

Example 1:

+ +
Input: k = 4
+Output: "47"
+Explanation: The first lucky number is 4, the second one is 7, the third one is 44 and the fourth one is 47.
+
+ +

Example 2:

+ +
Input: k = 10
+Output: "477"
+Explanation: Here are lucky numbers sorted in increasing order:
+4, 7, 44, 47, 74, 77, 444, 447, 474, 477. So the 10th lucky number is 477.
+ +

Example 3:

+ +
Input: k = 1000
+Output: "777747447"
+Explanation: It can be shown that the 1000th lucky number is 777747447.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= 109
  • +
+
\ No newline at end of file diff --git a/2806-account-balance-after-rounded-purchase/README.md b/final/2806-account-balance-after-rounded-purchase.html similarity index 100% rename from 2806-account-balance-after-rounded-purchase/README.md rename to final/2806-account-balance-after-rounded-purchase.html diff --git a/2807-insert-greatest-common-divisors-in-linked-list/README.md b/final/2807-insert-greatest-common-divisors-in-linked-list.html similarity index 100% rename from 2807-insert-greatest-common-divisors-in-linked-list/README.md rename to final/2807-insert-greatest-common-divisors-in-linked-list.html diff --git a/2810-faulty-keyboard/README.md b/final/2810-faulty-keyboard.html similarity index 100% rename from 2810-faulty-keyboard/README.md rename to final/2810-faulty-keyboard.html diff --git a/2811-check-if-it-is-possible-to-split-array/README.md b/final/2811-check-if-it-is-possible-to-split-array.html similarity index 100% rename from 2811-check-if-it-is-possible-to-split-array/README.md rename to final/2811-check-if-it-is-possible-to-split-array.html diff --git a/2812-find-the-safest-path-in-a-grid/README.md b/final/2812-find-the-safest-path-in-a-grid.html similarity index 100% rename from 2812-find-the-safest-path-in-a-grid/README.md rename to final/2812-find-the-safest-path-in-a-grid.html diff --git a/final/2816-double-a-number-represented-as-a-linked-list.html b/final/2816-double-a-number-represented-as-a-linked-list.html new file mode 100644 index 000000000..57ca97b02 --- /dev/null +++ b/final/2816-double-a-number-represented-as-a-linked-list.html @@ -0,0 +1,28 @@ +

2816. Double a Number Represented as a Linked List

Medium


You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.

+ +

Return the head of the linked list after doubling it.

+ +

 

+

Example 1:

+ +
Input: head = [1,8,9]
+Output: [3,7,8]
+Explanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.
+
+ +

Example 2:

+ +
Input: head = [9,9,9]
+Output: [1,9,9,8]
+Explanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998. 
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 104]
  • +
  • 0 <= Node.val <= 9
  • +
  • The input is generated such that the list represents a number that does not have leading zeros, except the number 0 itself.
  • +
+
\ No newline at end of file diff --git a/2824-count-pairs-whose-sum-is-less-than-target/README.md b/final/2824-count-pairs-whose-sum-is-less-than-target.html similarity index 100% rename from 2824-count-pairs-whose-sum-is-less-than-target/README.md rename to final/2824-count-pairs-whose-sum-is-less-than-target.html diff --git a/final/2825-make-string-a-subsequence-using-cyclic-increments.html b/final/2825-make-string-a-subsequence-using-cyclic-increments.html new file mode 100644 index 000000000..d0e26cf1c --- /dev/null +++ b/final/2825-make-string-a-subsequence-using-cyclic-increments.html @@ -0,0 +1,42 @@ +

2825. Make String a Subsequence Using Cyclic Increments

Medium


You are given two 0-indexed strings str1 and str2.

+ +

In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.

+ +

Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.

+ +

Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.

+ +

 

+

Example 1:

+ +
Input: str1 = "abc", str2 = "ad"
+Output: true
+Explanation: Select index 2 in str1.
+Increment str1[2] to become 'd'. 
+Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.
+ +

Example 2:

+ +
Input: str1 = "zc", str2 = "ad"
+Output: true
+Explanation: Select indices 0 and 1 in str1. 
+Increment str1[0] to become 'a'. 
+Increment str1[1] to become 'd'. 
+Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.
+ +

Example 3:

+ +
Input: str1 = "ab", str2 = "d"
+Output: false
+Explanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once. 
+Therefore, false is returned.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= str1.length <= 105
  • +
  • 1 <= str2.length <= 105
  • +
  • str1 and str2 consist of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2833-furthest-point-from-origin/README.md b/final/2833-furthest-point-from-origin.html similarity index 100% rename from 2833-furthest-point-from-origin/README.md rename to final/2833-furthest-point-from-origin.html diff --git a/2834-find-the-minimum-possible-sum-of-a-beautiful-array/README.md b/final/2834-find-the-minimum-possible-sum-of-a-beautiful-array.html similarity index 100% rename from 2834-find-the-minimum-possible-sum-of-a-beautiful-array/README.md rename to final/2834-find-the-minimum-possible-sum-of-a-beautiful-array.html diff --git a/2849-determine-if-a-cell-is-reachable-at-a-given-time/README.md b/final/2849-determine-if-a-cell-is-reachable-at-a-given-time.html similarity index 100% rename from 2849-determine-if-a-cell-is-reachable-at-a-given-time/README.md rename to final/2849-determine-if-a-cell-is-reachable-at-a-given-time.html diff --git a/2864-maximum-odd-binary-number/README.md b/final/2864-maximum-odd-binary-number.html similarity index 100% rename from 2864-maximum-odd-binary-number/README.md rename to final/2864-maximum-odd-binary-number.html diff --git a/final/2870-minimum-number-of-operations-to-make-array-empty.html b/final/2870-minimum-number-of-operations-to-make-array-empty.html new file mode 100644 index 000000000..e32a87163 --- /dev/null +++ b/final/2870-minimum-number-of-operations-to-make-array-empty.html @@ -0,0 +1,39 @@ +

2870. Minimum Number of Operations to Make Array Empty

Medium


You are given a 0-indexed array nums consisting of positive integers.

+ +

There are two types of operations that you can apply on the array any number of times:

+ +
    +
  • Choose two elements with equal values and delete them from the array.
  • +
  • Choose three elements with equal values and delete them from the array.
  • +
+ +

Return the minimum number of operations required to make the array empty, or -1 if it is not possible.

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,3,2,2,4,2,3,4]
+Output: 4
+Explanation: We can apply the following operations to make the array empty:
+- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].
+- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].
+- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].
+- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].
+It can be shown that we cannot make the array empty in less than 4 operations.
+
+ +

Example 2:

+ +
Input: nums = [2,1,2,2,3,3]
+Output: -1
+Explanation: It is impossible to empty the array.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 106
  • +
+
\ No newline at end of file diff --git a/final/2958-length-of-longest-subarray-with-at-most-k-frequency.html b/final/2958-length-of-longest-subarray-with-at-most-k-frequency.html new file mode 100644 index 000000000..768756e8a --- /dev/null +++ b/final/2958-length-of-longest-subarray-with-at-most-k-frequency.html @@ -0,0 +1,44 @@ +

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/final/2962-count-subarrays-where-max-element-appears-at-least-k-times.html b/final/2962-count-subarrays-where-max-element-appears-at-least-k-times.html new file mode 100644 index 000000000..499c8675c --- /dev/null +++ b/final/2962-count-subarrays-where-max-element-appears-at-least-k-times.html @@ -0,0 +1,30 @@ +

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/2966-divide-array-into-arrays-with-max-difference/README.md b/final/2966-divide-array-into-arrays-with-max-difference.html similarity index 100% rename from 2966-divide-array-into-arrays-with-max-difference/README.md rename to final/2966-divide-array-into-arrays-with-max-difference.html diff --git a/2971-find-polygon-with-the-largest-perimeter/README.md b/final/2971-find-polygon-with-the-largest-perimeter.html similarity index 100% rename from 2971-find-polygon-with-the-largest-perimeter/README.md rename to final/2971-find-polygon-with-the-largest-perimeter.html diff --git a/final/2976-minimum-cost-to-convert-string-i.html b/final/2976-minimum-cost-to-convert-string-i.html new file mode 100644 index 000000000..cc8d73c02 --- /dev/null +++ b/final/2976-minimum-cost-to-convert-string-i.html @@ -0,0 +1,48 @@ +

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/final/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.html b/final/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.html new file mode 100644 index 000000000..8da447843 --- /dev/null +++ b/final/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.html @@ -0,0 +1,40 @@ +

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/3005-count-elements-with-maximum-frequency/README.md b/final/3005-count-elements-with-maximum-frequency.html similarity index 100% rename from 3005-count-elements-with-maximum-frequency/README.md rename to final/3005-count-elements-with-maximum-frequency.html diff --git a/final/3016-minimum-number-of-pushes-to-type-word-ii.html b/final/3016-minimum-number-of-pushes-to-type-word-ii.html new file mode 100644 index 000000000..c7bae1b53 --- /dev/null +++ b/final/3016-minimum-number-of-pushes-to-type-word-ii.html @@ -0,0 +1,64 @@ +

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/3062-winner-of-the-linked-list-game/README.md b/final/3062-winner-of-the-linked-list-game.html similarity index 100% rename from 3062-winner-of-the-linked-list-game/README.md rename to final/3062-winner-of-the-linked-list-game.html diff --git a/3063-linked-list-frequency/README.md b/final/3063-linked-list-frequency.html similarity index 100% rename from 3063-linked-list-frequency/README.md rename to final/3063-linked-list-frequency.html diff --git a/3068-find-the-maximum-sum-of-node-values/README.md b/final/3068-find-the-maximum-sum-of-node-values.html similarity index 100% rename from 3068-find-the-maximum-sum-of-node-values/README.md rename to final/3068-find-the-maximum-sum-of-node-values.html diff --git a/final/3075-maximize-happiness-of-selected-children.html b/final/3075-maximize-happiness-of-selected-children.html new file mode 100644 index 000000000..16567a73b --- /dev/null +++ b/final/3075-maximize-happiness-of-selected-children.html @@ -0,0 +1,47 @@ +

3075. Maximize Happiness of Selected Children

Medium


You are given an array happiness of length n, and a positive integer k.

+ +

There are n children standing in a queue, where the ith child has happiness value happiness[i]. You want to select k children from these n children in k turns.

+ +

In each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by 1. Note that the happiness value cannot become negative and gets decremented only if it is positive.

+ +

Return the maximum sum of the happiness values of the selected children you can achieve by selecting k children.

+ +

 

+

Example 1:

+ +
Input: happiness = [1,2,3], k = 2
+Output: 4
+Explanation: We can pick 2 children in the following way:
+- Pick the child with the happiness value == 3. The happiness value of the remaining children becomes [0,1].
+- Pick the child with the happiness value == 1. The happiness value of the remaining child becomes [0]. Note that the happiness value cannot become less than 0.
+The sum of the happiness values of the selected children is 3 + 1 = 4.
+
+ +

Example 2:

+ +
Input: happiness = [1,1,1,1], k = 2
+Output: 1
+Explanation: We can pick 2 children in the following way:
+- Pick any child with the happiness value == 1. The happiness value of the remaining children becomes [0,0,0].
+- Pick the child with the happiness value == 0. The happiness value of the remaining child becomes [0,0].
+The sum of the happiness values of the selected children is 1 + 0 = 1.
+
+ +

Example 3:

+ +
Input: happiness = [2,3,4,5], k = 1
+Output: 5
+Explanation: We can pick 1 child in the following way:
+- Pick the child with the happiness value == 5. The happiness value of the remaining children becomes [1,2,3].
+The sum of the happiness values of the selected children is 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n == happiness.length <= 2 * 105
  • +
  • 1 <= happiness[i] <= 108
  • +
  • 1 <= k <= n
  • +
+
\ No newline at end of file diff --git a/3110-score-of-a-string/README.md b/final/3110-score-of-a-string.html similarity index 100% rename from 3110-score-of-a-string/README.md rename to final/3110-score-of-a-string.html diff --git a/3189-minimum-moves-to-get-a-peaceful-board/README.md b/final/3189-minimum-moves-to-get-a-peaceful-board.html similarity index 100% rename from 3189-minimum-moves-to-get-a-peaceful-board/README.md rename to final/3189-minimum-moves-to-get-a-peaceful-board.html diff --git a/get_amazon.py b/get_amazon.py new file mode 100644 index 000000000..32e57737a --- /dev/null +++ b/get_amazon.py @@ -0,0 +1,42 @@ +import os +import shutil + +# Using readlines() +file1 = open('amazon_6months.txt', 'r') +Lines = file1.readlines() + +count = 0 +# Strips the newline character +for line in Lines: + count += 1 + if line.strip() != "" and line.split(" ")[0].split(".")[0] != "Med": + str = line.split(" ")[0].split(".")[0] + if len(str) == 1: + str = "000" + str + elif len(str) == 2: + str = "00" + str + elif len(str) == 3: + str = "0" + str + else: + pass + + # + print("Line{}: {}".format(count, str)) + + #copy target file to a targeted folder + # Assign directory + directory = r"./final/" + destination = r"./amazon_6months/" + + for filename in os.listdir(directory): + # Open file + if str in filename: + print("filename " + filename) + oldfilename = directory + filename + newfilename = destination + filename + shutil.copyfile(oldfilename, newfilename) + pass + + + + \ No newline at end of file diff --git a/0001-two-sum/0001-two-sum.py b/problems/0001-two-sum/0001-two-sum.py similarity index 100% rename from 0001-two-sum/0001-two-sum.py rename to problems/0001-two-sum/0001-two-sum.py diff --git a/0001-two-sum/0001-two-sum.ts b/problems/0001-two-sum/0001-two-sum.ts similarity index 100% rename from 0001-two-sum/0001-two-sum.ts rename to problems/0001-two-sum/0001-two-sum.ts diff --git a/0001-two-sum/NOTES.md b/problems/0001-two-sum/NOTES.md similarity index 100% rename from 0001-two-sum/NOTES.md rename to problems/0001-two-sum/NOTES.md diff --git a/problems/0001-two-sum/README.md b/problems/0001-two-sum/README.md new file mode 100644 index 000000000..26767690e --- /dev/null +++ b/problems/0001-two-sum/README.md @@ -0,0 +1,38 @@ +

1. Two Sum

Easy


Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

+ +

You may assume that each input would have exactly one solution, and you may not use the same element twice.

+ +

You can return the answer in any order.

+ +

 

+

Example 1:

+ +
Input: nums = [2,7,11,15], target = 9
+Output: [0,1]
+Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
+
+ +

Example 2:

+ +
Input: nums = [3,2,4], target = 6
+Output: [1,2]
+
+ +

Example 3:

+ +
Input: nums = [3,3], target = 6
+Output: [0,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 104
  • +
  • -109 <= nums[i] <= 109
  • +
  • -109 <= target <= 109
  • +
  • Only one valid answer exists.
  • +
+ +

 

+Follow-up: Can you come up with an algorithm that is less than O(n2time complexity?
\ No newline at end of file diff --git a/0002-add-two-numbers/0002-add-two-numbers.cpp b/problems/0002-add-two-numbers/0002-add-two-numbers.cpp similarity index 100% rename from 0002-add-two-numbers/0002-add-two-numbers.cpp rename to problems/0002-add-two-numbers/0002-add-two-numbers.cpp diff --git a/0002-add-two-numbers/NOTES.md b/problems/0002-add-two-numbers/NOTES.md similarity index 100% rename from 0002-add-two-numbers/NOTES.md rename to problems/0002-add-two-numbers/NOTES.md diff --git a/problems/0002-add-two-numbers/README.md b/problems/0002-add-two-numbers/README.md new file mode 100644 index 000000000..0ec64b7cf --- /dev/null +++ b/problems/0002-add-two-numbers/README.md @@ -0,0 +1,33 @@ +

2. Add Two Numbers

Medium


You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

+ +

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

+ +

 

+

Example 1:

+ +
Input: l1 = [2,4,3], l2 = [5,6,4]
+Output: [7,0,8]
+Explanation: 342 + 465 = 807.
+
+ +

Example 2:

+ +
Input: l1 = [0], l2 = [0]
+Output: [0]
+
+ +

Example 3:

+ +
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
+Output: [8,9,9,9,0,0,0,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 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 diff --git a/0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.cpp b/problems/0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.cpp similarity index 100% rename from 0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.cpp rename to problems/0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.cpp diff --git a/0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.py b/problems/0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.py similarity index 100% rename from 0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.py rename to problems/0003-longest-substring-without-repeating-characters/0003-longest-substring-without-repeating-characters.py diff --git a/0003-longest-substring-without-repeating-characters/NOTES.md b/problems/0003-longest-substring-without-repeating-characters/NOTES.md similarity index 100% rename from 0003-longest-substring-without-repeating-characters/NOTES.md rename to problems/0003-longest-substring-without-repeating-characters/NOTES.md diff --git a/problems/0003-longest-substring-without-repeating-characters/README.md b/problems/0003-longest-substring-without-repeating-characters/README.md new file mode 100644 index 000000000..857ec8b40 --- /dev/null +++ b/problems/0003-longest-substring-without-repeating-characters/README.md @@ -0,0 +1,33 @@ +

3. Longest Substring Without Repeating Characters

Medium


Given a string s, find the length of the longest substring without repeating characters.

+ +

 

+

Example 1:

+ +
Input: s = "abcabcbb"
+Output: 3
+Explanation: The answer is "abc", with the length of 3.
+
+ +

Example 2:

+ +
Input: s = "bbbbb"
+Output: 1
+Explanation: The answer is "b", with the length of 1.
+
+ +

Example 3:

+ +
Input: s = "pwwkew"
+Output: 3
+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.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= s.length <= 5 * 104
  • +
  • s consists of English letters, digits, symbols and spaces.
  • +
+
\ No newline at end of file diff --git a/0004-median-of-two-sorted-arrays/0004-median-of-two-sorted-arrays.py b/problems/0004-median-of-two-sorted-arrays/0004-median-of-two-sorted-arrays.py similarity index 100% rename from 0004-median-of-two-sorted-arrays/0004-median-of-two-sorted-arrays.py rename to problems/0004-median-of-two-sorted-arrays/0004-median-of-two-sorted-arrays.py diff --git a/0004-median-of-two-sorted-arrays/NOTES.md b/problems/0004-median-of-two-sorted-arrays/NOTES.md similarity index 100% rename from 0004-median-of-two-sorted-arrays/NOTES.md rename to problems/0004-median-of-two-sorted-arrays/NOTES.md diff --git a/problems/0004-median-of-two-sorted-arrays/README.md b/problems/0004-median-of-two-sorted-arrays/README.md new file mode 100644 index 000000000..e547cad46 --- /dev/null +++ b/problems/0004-median-of-two-sorted-arrays/README.md @@ -0,0 +1,31 @@ +

4. Median of Two Sorted Arrays

Hard


Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

+ +

The overall run time complexity should be O(log (m+n)).

+ +

 

+

Example 1:

+ +
Input: nums1 = [1,3], nums2 = [2]
+Output: 2.00000
+Explanation: merged array = [1,2,3] and median is 2.
+
+ +

Example 2:

+ +
Input: nums1 = [1,2], nums2 = [3,4]
+Output: 2.50000
+Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
+
+ +

 

+

Constraints:

+ +
    +
  • nums1.length == m
  • +
  • nums2.length == n
  • +
  • 0 <= m <= 1000
  • +
  • 0 <= n <= 1000
  • +
  • 1 <= m + n <= 2000
  • +
  • -106 <= nums1[i], nums2[i] <= 106
  • +
+
\ No newline at end of file diff --git a/0005-longest-palindromic-substring/0005-longest-palindromic-substring.py b/problems/0005-longest-palindromic-substring/0005-longest-palindromic-substring.py similarity index 100% rename from 0005-longest-palindromic-substring/0005-longest-palindromic-substring.py rename to problems/0005-longest-palindromic-substring/0005-longest-palindromic-substring.py diff --git a/0005-longest-palindromic-substring/NOTES.md b/problems/0005-longest-palindromic-substring/NOTES.md similarity index 100% rename from 0005-longest-palindromic-substring/NOTES.md rename to problems/0005-longest-palindromic-substring/NOTES.md diff --git a/problems/0005-longest-palindromic-substring/README.md b/problems/0005-longest-palindromic-substring/README.md new file mode 100644 index 000000000..ea3d65712 --- /dev/null +++ b/problems/0005-longest-palindromic-substring/README.md @@ -0,0 +1,24 @@ +

5. Longest Palindromic Substring

Medium


Given a string s, return the longest palindromic substring in s.

+ +

 

+

Example 1:

+ +
Input: s = "babad"
+Output: "bab"
+Explanation: "aba" is also a valid answer.
+
+ +

Example 2:

+ +
Input: s = "cbbd"
+Output: "bb"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consist of only digits and English letters.
  • +
+
\ No newline at end of file diff --git a/0006-zigzag-conversion/0006-zigzag-conversion.py b/problems/0006-zigzag-conversion/0006-zigzag-conversion.py similarity index 100% rename from 0006-zigzag-conversion/0006-zigzag-conversion.py rename to problems/0006-zigzag-conversion/0006-zigzag-conversion.py diff --git a/0006-zigzag-conversion/NOTES.md b/problems/0006-zigzag-conversion/NOTES.md similarity index 100% rename from 0006-zigzag-conversion/NOTES.md rename to problems/0006-zigzag-conversion/NOTES.md diff --git a/problems/0006-zigzag-conversion/README.md b/problems/0006-zigzag-conversion/README.md new file mode 100644 index 000000000..b4396e037 --- /dev/null +++ b/problems/0006-zigzag-conversion/README.md @@ -0,0 +1,47 @@ +

6. Zigzag Conversion

Medium


The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

+ +
P   A   H   N
+A P L S I I G
+Y   I   R
+
+ +

And then read line by line: "PAHNAPLSIIGYIR"

+ +

Write the code that will take a string and make this conversion given a number of rows:

+ +
string convert(string s, int numRows);
+
+ +

 

+

Example 1:

+ +
Input: s = "PAYPALISHIRING", numRows = 3
+Output: "PAHNAPLSIIGYIR"
+
+ +

Example 2:

+ +
Input: s = "PAYPALISHIRING", numRows = 4
+Output: "PINALSIGYAHRPI"
+Explanation:
+P     I    N
+A   L S  I G
+Y A   H R
+P     I
+
+ +

Example 3:

+ +
Input: s = "A", numRows = 1
+Output: "A"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consists of English letters (lower-case and upper-case), ',' and '.'.
  • +
  • 1 <= numRows <= 1000
  • +
+
\ No newline at end of file diff --git a/0007-reverse-integer/0007-reverse-integer.py b/problems/0007-reverse-integer/0007-reverse-integer.py similarity index 100% rename from 0007-reverse-integer/0007-reverse-integer.py rename to problems/0007-reverse-integer/0007-reverse-integer.py diff --git a/0007-reverse-integer/NOTES.md b/problems/0007-reverse-integer/NOTES.md similarity index 100% rename from 0007-reverse-integer/NOTES.md rename to problems/0007-reverse-integer/NOTES.md diff --git a/problems/0007-reverse-integer/README.md b/problems/0007-reverse-integer/README.md new file mode 100644 index 000000000..db5afe4a5 --- /dev/null +++ b/problems/0007-reverse-integer/README.md @@ -0,0 +1,30 @@ +

7. Reverse Integer

Medium


Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

+ +

Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

+ +

 

+

Example 1:

+ +
Input: x = 123
+Output: 321
+
+ +

Example 2:

+ +
Input: x = -123
+Output: -321
+
+ +

Example 3:

+ +
Input: x = 120
+Output: 21
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= x <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0008-string-to-integer-atoi/0008-string-to-integer-atoi.py b/problems/0008-string-to-integer-atoi/0008-string-to-integer-atoi.py similarity index 100% rename from 0008-string-to-integer-atoi/0008-string-to-integer-atoi.py rename to problems/0008-string-to-integer-atoi/0008-string-to-integer-atoi.py diff --git a/0008-string-to-integer-atoi/NOTES.md b/problems/0008-string-to-integer-atoi/NOTES.md similarity index 100% rename from 0008-string-to-integer-atoi/NOTES.md rename to problems/0008-string-to-integer-atoi/NOTES.md diff --git a/problems/0008-string-to-integer-atoi/README.md b/problems/0008-string-to-integer-atoi/README.md new file mode 100644 index 000000000..4bb3ba712 --- /dev/null +++ b/problems/0008-string-to-integer-atoi/README.md @@ -0,0 +1,74 @@ +

8. String to Integer (atoi)

Medium


Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).

+ +

The algorithm for myAtoi(string s) is as follows:

+ +
    +
  1. Read in and ignore any leading whitespace.
  2. +
  3. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
  4. +
  5. Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.
  6. +
  7. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
  8. +
  9. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
  10. +
  11. Return the integer as the final result.
  12. +
+ +

Note:

+ +
    +
  • Only the space character ' ' is considered a whitespace character.
  • +
  • Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.
  • +
+ +

 

+

Example 1:

+ +
Input: s = "42"
+Output: 42
+Explanation: The underlined characters are what is read in, the caret is the current reader position.
+Step 1: "42" (no characters read because there is no leading whitespace)
+         ^
+Step 2: "42" (no characters read because there is neither a '-' nor '+')
+         ^
+Step 3: "42" ("42" is read in)
+           ^
+The parsed integer is 42.
+Since 42 is in the range [-231, 231 - 1], the final result is 42.
+
+ +

Example 2:

+ +
Input: s = "   -42"
+Output: -42
+Explanation:
+Step 1: "   -42" (leading whitespace is read and ignored)
+            ^
+Step 2: "   -42" ('-' is read, so the result should be negative)
+             ^
+Step 3: "   -42" ("42" is read in)
+               ^
+The parsed integer is -42.
+Since -42 is in the range [-231, 231 - 1], the final result is -42.
+
+ +

Example 3:

+ +
Input: s = "4193 with words"
+Output: 4193
+Explanation:
+Step 1: "4193 with words" (no characters read because there is no leading whitespace)
+         ^
+Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+')
+         ^
+Step 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit)
+             ^
+The parsed integer is 4193.
+Since 4193 is in the range [-231, 231 - 1], the final result is 4193.
+
+ +

 

+

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 diff --git a/0009-palindrome-number/0009-palindrome-number.cpp b/problems/0009-palindrome-number/0009-palindrome-number.cpp similarity index 100% rename from 0009-palindrome-number/0009-palindrome-number.cpp rename to problems/0009-palindrome-number/0009-palindrome-number.cpp diff --git a/0009-palindrome-number/NOTES.md b/problems/0009-palindrome-number/NOTES.md similarity index 100% rename from 0009-palindrome-number/NOTES.md rename to problems/0009-palindrome-number/NOTES.md diff --git a/problems/0009-palindrome-number/README.md b/problems/0009-palindrome-number/README.md new file mode 100644 index 000000000..135519dbf --- /dev/null +++ b/problems/0009-palindrome-number/README.md @@ -0,0 +1,33 @@ +

9. Palindrome Number

Easy


Given an integer x, return true if x is a palindrome, and false otherwise.

+ +

 

+

Example 1:

+ +
Input: x = 121
+Output: true
+Explanation: 121 reads as 121 from left to right and from right to left.
+
+ +

Example 2:

+ +
Input: x = -121
+Output: false
+Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
+
+ +

Example 3:

+ +
Input: x = 10
+Output: false
+Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= x <= 231 - 1
  • +
+ +

 

+Follow up: Could you solve it without converting the integer to a string?
\ No newline at end of file diff --git a/0010-regular-expression-matching/0010-regular-expression-matching.py b/problems/0010-regular-expression-matching/0010-regular-expression-matching.py similarity index 100% rename from 0010-regular-expression-matching/0010-regular-expression-matching.py rename to problems/0010-regular-expression-matching/0010-regular-expression-matching.py diff --git a/0010-regular-expression-matching/NOTES.md b/problems/0010-regular-expression-matching/NOTES.md similarity index 100% rename from 0010-regular-expression-matching/NOTES.md rename to problems/0010-regular-expression-matching/NOTES.md diff --git a/problems/0010-regular-expression-matching/README.md b/problems/0010-regular-expression-matching/README.md new file mode 100644 index 000000000..ea59567d1 --- /dev/null +++ b/problems/0010-regular-expression-matching/README.md @@ -0,0 +1,42 @@ +

10. Regular Expression Matching

Hard


Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:

+ +
    +
  • '.' Matches any single character.​​​​
  • +
  • '*' Matches zero or more of the preceding element.
  • +
+ +

The matching should cover the entire input string (not partial).

+ +

 

+

Example 1:

+ +
Input: s = "aa", p = "a"
+Output: false
+Explanation: "a" does not match the entire string "aa".
+
+ +

Example 2:

+ +
Input: s = "aa", p = "a*"
+Output: true
+Explanation: '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
+
+ +

Example 3:

+ +
Input: s = "ab", p = ".*"
+Output: true
+Explanation: ".*" means "zero or more (*) of any character (.)".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 20
  • +
  • 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 diff --git a/0011-container-with-most-water/0011-container-with-most-water.py b/problems/0011-container-with-most-water/0011-container-with-most-water.py similarity index 100% rename from 0011-container-with-most-water/0011-container-with-most-water.py rename to problems/0011-container-with-most-water/0011-container-with-most-water.py diff --git a/0011-container-with-most-water/NOTES.md b/problems/0011-container-with-most-water/NOTES.md similarity index 100% rename from 0011-container-with-most-water/NOTES.md rename to problems/0011-container-with-most-water/NOTES.md diff --git a/problems/0011-container-with-most-water/README.md b/problems/0011-container-with-most-water/README.md new file mode 100644 index 000000000..6c932927c --- /dev/null +++ b/problems/0011-container-with-most-water/README.md @@ -0,0 +1,31 @@ +

11. Container With Most Water

Medium


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.

+ +

 

+

Example 1:

+ +
Input: height = [1,8,6,2,5,4,8,3,7]
+Output: 49
+Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
+
+ +

Example 2:

+ +
Input: height = [1,1]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • n == height.length
  • +
  • 2 <= n <= 105
  • +
  • 0 <= height[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0012-integer-to-roman/0012-integer-to-roman.py b/problems/0012-integer-to-roman/0012-integer-to-roman.py similarity index 100% rename from 0012-integer-to-roman/0012-integer-to-roman.py rename to problems/0012-integer-to-roman/0012-integer-to-roman.py diff --git a/0012-integer-to-roman/NOTES.md b/problems/0012-integer-to-roman/NOTES.md similarity index 100% rename from 0012-integer-to-roman/NOTES.md rename to problems/0012-integer-to-roman/NOTES.md diff --git a/problems/0012-integer-to-roman/README.md b/problems/0012-integer-to-roman/README.md new file mode 100644 index 000000000..627b4bb1f --- /dev/null +++ b/problems/0012-integer-to-roman/README.md @@ -0,0 +1,52 @@ +

12. Integer to Roman

Medium


Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

+ +
Symbol       Value
+I             1
+V             5
+X             10
+L             50
+C             100
+D             500
+M             1000
+ +

For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

+ +

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

+ +
    +
  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • +
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • +
  • C can be placed before D (500) and M (1000) to make 400 and 900.
  • +
+ +

Given an integer, convert it to a roman numeral.

+ +

 

+

Example 1:

+ +
Input: num = 3
+Output: "III"
+Explanation: 3 is represented as 3 ones.
+
+ +

Example 2:

+ +
Input: num = 58
+Output: "LVIII"
+Explanation: L = 50, V = 5, III = 3.
+
+ +

Example 3:

+ +
Input: num = 1994
+Output: "MCMXCIV"
+Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= num <= 3999
  • +
+
\ No newline at end of file diff --git a/0013-roman-to-integer/0013-roman-to-integer.cpp b/problems/0013-roman-to-integer/0013-roman-to-integer.cpp similarity index 100% rename from 0013-roman-to-integer/0013-roman-to-integer.cpp rename to problems/0013-roman-to-integer/0013-roman-to-integer.cpp diff --git a/0013-roman-to-integer/NOTES.md b/problems/0013-roman-to-integer/NOTES.md similarity index 100% rename from 0013-roman-to-integer/NOTES.md rename to problems/0013-roman-to-integer/NOTES.md diff --git a/problems/0013-roman-to-integer/README.md b/problems/0013-roman-to-integer/README.md new file mode 100644 index 000000000..5e4b0674d --- /dev/null +++ b/problems/0013-roman-to-integer/README.md @@ -0,0 +1,54 @@ +

13. Roman to Integer

Easy


Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

+ +
Symbol       Value
+I             1
+V             5
+X             10
+L             50
+C             100
+D             500
+M             1000
+ +

For example, 2 is written as II in Roman numeral, just two 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:

+ +
    +
  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • +
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • +
  • C can be placed before D (500) and M (1000) to make 400 and 900.
  • +
+ +

Given a roman numeral, convert it to an integer.

+ +

 

+

Example 1:

+ +
Input: s = "III"
+Output: 3
+Explanation: III = 3.
+
+ +

Example 2:

+ +
Input: s = "LVIII"
+Output: 58
+Explanation: L = 50, V= 5, III = 3.
+
+ +

Example 3:

+ +
Input: s = "MCMXCIV"
+Output: 1994
+Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 15
  • +
  • s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').
  • +
  • It is guaranteed that s is a valid roman numeral in the range [1, 3999].
  • +
+
\ No newline at end of file diff --git a/0014-longest-common-prefix/0014-longest-common-prefix.cpp b/problems/0014-longest-common-prefix/0014-longest-common-prefix.cpp similarity index 100% rename from 0014-longest-common-prefix/0014-longest-common-prefix.cpp rename to problems/0014-longest-common-prefix/0014-longest-common-prefix.cpp diff --git a/0014-longest-common-prefix/NOTES.md b/problems/0014-longest-common-prefix/NOTES.md similarity index 100% rename from 0014-longest-common-prefix/NOTES.md rename to problems/0014-longest-common-prefix/NOTES.md diff --git a/problems/0014-longest-common-prefix/README.md b/problems/0014-longest-common-prefix/README.md new file mode 100644 index 000000000..712faf3e8 --- /dev/null +++ b/problems/0014-longest-common-prefix/README.md @@ -0,0 +1,27 @@ +

14. Longest Common Prefix

Easy


Write a function to find the longest common prefix string amongst an array of strings.

+ +

If there is no common prefix, return an empty string "".

+ +

 

+

Example 1:

+ +
Input: strs = ["flower","flow","flight"]
+Output: "fl"
+
+ +

Example 2:

+ +
Input: strs = ["dog","racecar","car"]
+Output: ""
+Explanation: There is no common prefix among the input strings.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= strs.length <= 200
  • +
  • 0 <= strs[i].length <= 200
  • +
  • strs[i] consists of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0015-3sum/0015-3sum.cpp b/problems/0015-3sum/0015-3sum.cpp similarity index 100% rename from 0015-3sum/0015-3sum.cpp rename to problems/0015-3sum/0015-3sum.cpp diff --git a/0015-3sum/0015-3sum.py b/problems/0015-3sum/0015-3sum.py similarity index 100% rename from 0015-3sum/0015-3sum.py rename to problems/0015-3sum/0015-3sum.py diff --git a/0015-3sum/NOTES.md b/problems/0015-3sum/NOTES.md similarity index 100% rename from 0015-3sum/NOTES.md rename to problems/0015-3sum/NOTES.md diff --git a/problems/0015-3sum/README.md b/problems/0015-3sum/README.md new file mode 100644 index 000000000..6dd16400f --- /dev/null +++ b/problems/0015-3sum/README.md @@ -0,0 +1,39 @@ +

15. 3Sum

Medium


Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

+ +

Notice that the solution set must not contain duplicate triplets.

+ +

 

+

Example 1:

+ +
Input: nums = [-1,0,1,2,-1,-4]
+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 = [0,1,1]
+Output: []
+Explanation: The only possible triplet does not sum up to 0.
+
+ +

Example 3:

+ +
Input: nums = [0,0,0]
+Output: [[0,0,0]]
+Explanation: The only possible triplet sums up to 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= nums.length <= 3000
  • +
  • -105 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/0016-3sum-closest/0016-3sum-closest.py b/problems/0016-3sum-closest/0016-3sum-closest.py similarity index 100% rename from 0016-3sum-closest/0016-3sum-closest.py rename to problems/0016-3sum-closest/0016-3sum-closest.py diff --git a/0016-3sum-closest/NOTES.md b/problems/0016-3sum-closest/NOTES.md similarity index 100% rename from 0016-3sum-closest/NOTES.md rename to problems/0016-3sum-closest/NOTES.md diff --git a/problems/0016-3sum-closest/README.md b/problems/0016-3sum-closest/README.md new file mode 100644 index 000000000..d362ac2dc --- /dev/null +++ b/problems/0016-3sum-closest/README.md @@ -0,0 +1,30 @@ +

16. 3Sum Closest

Medium


Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.

+ +

Return the sum of the three integers.

+ +

You may assume that each input would have exactly one solution.

+ +

 

+

Example 1:

+ +
Input: nums = [-1,2,1,-4], target = 1
+Output: 2
+Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
+
+ +

Example 2:

+ +
Input: nums = [0,0,0], target = 1
+Output: 0
+Explanation: The sum that is closest to the target is 0. (0 + 0 + 0 = 0).
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= nums.length <= 500
  • +
  • -1000 <= nums[i] <= 1000
  • +
  • -104 <= target <= 104
  • +
+
\ No newline at end of file diff --git a/0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py b/problems/0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py similarity index 100% rename from 0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py rename to problems/0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py diff --git a/0017-letter-combinations-of-a-phone-number/NOTES.md b/problems/0017-letter-combinations-of-a-phone-number/NOTES.md similarity index 100% rename from 0017-letter-combinations-of-a-phone-number/NOTES.md rename to problems/0017-letter-combinations-of-a-phone-number/NOTES.md diff --git a/problems/0017-letter-combinations-of-a-phone-number/README.md b/problems/0017-letter-combinations-of-a-phone-number/README.md new file mode 100644 index 000000000..81e0b1fbb --- /dev/null +++ b/problems/0017-letter-combinations-of-a-phone-number/README.md @@ -0,0 +1,31 @@ +

17. Letter Combinations of a Phone Number

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 digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

+ +

 

+

Example 1:

+ +
Input: digits = "23"
+Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
+
+ +

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 diff --git a/0018-4sum/0018-4sum.py b/problems/0018-4sum/0018-4sum.py similarity index 100% rename from 0018-4sum/0018-4sum.py rename to problems/0018-4sum/0018-4sum.py diff --git a/0018-4sum/NOTES.md b/problems/0018-4sum/NOTES.md similarity index 100% rename from 0018-4sum/NOTES.md rename to problems/0018-4sum/NOTES.md diff --git a/problems/0018-4sum/README.md b/problems/0018-4sum/README.md new file mode 100644 index 000000000..31fd5edda --- /dev/null +++ b/problems/0018-4sum/README.md @@ -0,0 +1,32 @@ +

18. 4Sum

Medium


Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:

+ +
    +
  • 0 <= a, b, c, d < n
  • +
  • a, b, c, and d are distinct.
  • +
  • nums[a] + nums[b] + nums[c] + nums[d] == target
  • +
+ +

You may return the answer in any order.

+ +

 

+

Example 1:

+ +
Input: nums = [1,0,-1,0,-2,2], target = 0
+Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
+
+ +

Example 2:

+ +
Input: nums = [2,2,2,2,2], target = 8
+Output: [[2,2,2,2]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 200
  • +
  • -109 <= nums[i] <= 109
  • +
  • -109 <= target <= 109
  • +
+
\ No newline at end of file diff --git a/0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.cpp b/problems/0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.cpp similarity index 100% rename from 0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.cpp rename to problems/0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.cpp diff --git a/0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.py b/problems/0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.py similarity index 100% rename from 0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.py rename to problems/0019-remove-nth-node-from-end-of-list/0019-remove-nth-node-from-end-of-list.py diff --git a/0019-remove-nth-node-from-end-of-list/NOTES.md b/problems/0019-remove-nth-node-from-end-of-list/NOTES.md similarity index 100% rename from 0019-remove-nth-node-from-end-of-list/NOTES.md rename to problems/0019-remove-nth-node-from-end-of-list/NOTES.md diff --git a/problems/0019-remove-nth-node-from-end-of-list/README.md b/problems/0019-remove-nth-node-from-end-of-list/README.md new file mode 100644 index 000000000..b1ecfb615 --- /dev/null +++ b/problems/0019-remove-nth-node-from-end-of-list/README.md @@ -0,0 +1,34 @@ +

19. Remove Nth Node From End of List

Medium


Given the head of a linked list, remove the nth node from the end of the list and return its head.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5], n = 2
+Output: [1,2,3,5]
+
+ +

Example 2:

+ +
Input: head = [1], n = 1
+Output: []
+
+ +

Example 3:

+ +
Input: head = [1,2], n = 1
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is sz.
  • +
  • 1 <= sz <= 30
  • +
  • 0 <= Node.val <= 100
  • +
  • 1 <= n <= sz
  • +
+ +

 

+

Follow up: Could you do this in one pass?

+
\ No newline at end of file diff --git a/0020-valid-parentheses/0020-valid-parentheses.cpp b/problems/0020-valid-parentheses/0020-valid-parentheses.cpp similarity index 100% rename from 0020-valid-parentheses/0020-valid-parentheses.cpp rename to problems/0020-valid-parentheses/0020-valid-parentheses.cpp diff --git a/0020-valid-parentheses/0020-valid-parentheses.js b/problems/0020-valid-parentheses/0020-valid-parentheses.js similarity index 100% rename from 0020-valid-parentheses/0020-valid-parentheses.js rename to problems/0020-valid-parentheses/0020-valid-parentheses.js diff --git a/0020-valid-parentheses/0020-valid-parentheses.py b/problems/0020-valid-parentheses/0020-valid-parentheses.py similarity index 100% rename from 0020-valid-parentheses/0020-valid-parentheses.py rename to problems/0020-valid-parentheses/0020-valid-parentheses.py diff --git a/0020-valid-parentheses/NOTES.md b/problems/0020-valid-parentheses/NOTES.md similarity index 100% rename from 0020-valid-parentheses/NOTES.md rename to problems/0020-valid-parentheses/NOTES.md diff --git a/problems/0020-valid-parentheses/README.md b/problems/0020-valid-parentheses/README.md new file mode 100644 index 000000000..5c5bf1e27 --- /dev/null +++ b/problems/0020-valid-parentheses/README.md @@ -0,0 +1,37 @@ +

20. Valid Parentheses

Easy


Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

+ +

An input string is valid if:

+ +
    +
  1. Open brackets must be closed by the same type of brackets.
  2. +
  3. Open brackets must be closed in the correct order.
  4. +
  5. Every close bracket has a corresponding open bracket of the same type.
  6. +
+ +

 

+

Example 1:

+ +
Input: s = "()"
+Output: true
+
+ +

Example 2:

+ +
Input: s = "()[]{}"
+Output: true
+
+ +

Example 3:

+ +
Input: s = "(]"
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 104
  • +
  • s consists of parentheses only '()[]{}'.
  • +
+
\ No newline at end of file diff --git a/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.cpp b/problems/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.cpp similarity index 100% rename from 0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.cpp rename to problems/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.cpp diff --git a/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.js b/problems/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.js similarity index 100% rename from 0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.js rename to problems/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.js diff --git a/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.py b/problems/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.py similarity index 100% rename from 0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.py rename to problems/0021-merge-two-sorted-lists/0021-merge-two-sorted-lists.py diff --git a/0021-merge-two-sorted-lists/NOTES.md b/problems/0021-merge-two-sorted-lists/NOTES.md similarity index 100% rename from 0021-merge-two-sorted-lists/NOTES.md rename to problems/0021-merge-two-sorted-lists/NOTES.md diff --git a/problems/0021-merge-two-sorted-lists/README.md b/problems/0021-merge-two-sorted-lists/README.md new file mode 100644 index 000000000..d9a9154d7 --- /dev/null +++ b/problems/0021-merge-two-sorted-lists/README.md @@ -0,0 +1,34 @@ +

21. Merge Two Sorted Lists

Easy


You are given the heads of two sorted linked lists list1 and list2.

+ +

Merge the two lists in a 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: list1 = [1,2,4], list2 = [1,3,4]
+Output: [1,1,2,3,4,4]
+
+ +

Example 2:

+ +
Input: list1 = [], list2 = []
+Output: []
+
+ +

Example 3:

+ +
Input: list1 = [], list2 = [0]
+Output: [0]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in both lists is in the range [0, 50].
  • +
  • -100 <= Node.val <= 100
  • +
  • Both list1 and list2 are sorted in non-decreasing order.
  • +
+
\ No newline at end of file diff --git a/0022-generate-parentheses/0022-generate-parentheses.py b/problems/0022-generate-parentheses/0022-generate-parentheses.py similarity index 100% rename from 0022-generate-parentheses/0022-generate-parentheses.py rename to problems/0022-generate-parentheses/0022-generate-parentheses.py diff --git a/0022-generate-parentheses/NOTES.md b/problems/0022-generate-parentheses/NOTES.md similarity index 100% rename from 0022-generate-parentheses/NOTES.md rename to problems/0022-generate-parentheses/NOTES.md diff --git a/problems/0022-generate-parentheses/README.md b/problems/0022-generate-parentheses/README.md new file mode 100644 index 000000000..154f576c0 --- /dev/null +++ b/problems/0022-generate-parentheses/README.md @@ -0,0 +1,17 @@ +

22. Generate Parentheses

Medium


Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

+ +

 

+

Example 1:

+
Input: n = 3
+Output: ["((()))","(()())","(())()","()(())","()()()"]
+

Example 2:

+
Input: n = 1
+Output: ["()"]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= n <= 8
  • +
+
\ No newline at end of file diff --git a/0023-merge-k-sorted-lists/0023-merge-k-sorted-lists.py b/problems/0023-merge-k-sorted-lists/0023-merge-k-sorted-lists.py similarity index 100% rename from 0023-merge-k-sorted-lists/0023-merge-k-sorted-lists.py rename to problems/0023-merge-k-sorted-lists/0023-merge-k-sorted-lists.py diff --git a/0023-merge-k-sorted-lists/NOTES.md b/problems/0023-merge-k-sorted-lists/NOTES.md similarity index 100% rename from 0023-merge-k-sorted-lists/NOTES.md rename to problems/0023-merge-k-sorted-lists/NOTES.md diff --git a/problems/0023-merge-k-sorted-lists/README.md b/problems/0023-merge-k-sorted-lists/README.md new file mode 100644 index 000000000..1f0df1fb9 --- /dev/null +++ b/problems/0023-merge-k-sorted-lists/README.md @@ -0,0 +1,43 @@ +

23. Merge k Sorted Lists

Hard


You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.

+ +

Merge all the linked-lists into one sorted linked-list and return it.

+ +

 

+

Example 1:

+ +
Input: lists = [[1,4,5],[1,3,4],[2,6]]
+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
+
+ +

Example 2:

+ +
Input: lists = []
+Output: []
+
+ +

Example 3:

+ +
Input: lists = [[]]
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • k == lists.length
  • +
  • 0 <= k <= 104
  • +
  • 0 <= lists[i].length <= 500
  • +
  • -104 <= lists[i][j] <= 104
  • +
  • lists[i] is sorted in ascending order.
  • +
  • The sum of lists[i].length will not exceed 104.
  • +
+
\ No newline at end of file diff --git a/0024-swap-nodes-in-pairs/0024-swap-nodes-in-pairs.py b/problems/0024-swap-nodes-in-pairs/0024-swap-nodes-in-pairs.py similarity index 100% rename from 0024-swap-nodes-in-pairs/0024-swap-nodes-in-pairs.py rename to problems/0024-swap-nodes-in-pairs/0024-swap-nodes-in-pairs.py diff --git a/0024-swap-nodes-in-pairs/NOTES.md b/problems/0024-swap-nodes-in-pairs/NOTES.md similarity index 100% rename from 0024-swap-nodes-in-pairs/NOTES.md rename to problems/0024-swap-nodes-in-pairs/NOTES.md diff --git a/problems/0024-swap-nodes-in-pairs/README.md b/problems/0024-swap-nodes-in-pairs/README.md new file mode 100644 index 000000000..f410f5b08 --- /dev/null +++ b/problems/0024-swap-nodes-in-pairs/README.md @@ -0,0 +1,29 @@ +

24. Swap Nodes in Pairs

Medium


Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4]
+Output: [2,1,4,3]
+
+ +

Example 2:

+ +
Input: head = []
+Output: []
+
+ +

Example 3:

+ +
Input: head = [1]
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 100].
  • +
  • 0 <= Node.val <= 100
  • +
+
\ No newline at end of file diff --git a/0025-reverse-nodes-in-k-group/0025-reverse-nodes-in-k-group.py b/problems/0025-reverse-nodes-in-k-group/0025-reverse-nodes-in-k-group.py similarity index 100% rename from 0025-reverse-nodes-in-k-group/0025-reverse-nodes-in-k-group.py rename to problems/0025-reverse-nodes-in-k-group/0025-reverse-nodes-in-k-group.py diff --git a/0025-reverse-nodes-in-k-group/NOTES.md b/problems/0025-reverse-nodes-in-k-group/NOTES.md similarity index 100% rename from 0025-reverse-nodes-in-k-group/NOTES.md rename to problems/0025-reverse-nodes-in-k-group/NOTES.md diff --git a/problems/0025-reverse-nodes-in-k-group/README.md b/problems/0025-reverse-nodes-in-k-group/README.md new file mode 100644 index 000000000..2c7afecac --- /dev/null +++ b/problems/0025-reverse-nodes-in-k-group/README.md @@ -0,0 +1,31 @@ +

25. Reverse Nodes in k-Group

Hard


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.

+ +

You may not alter the values in the list's nodes, only nodes themselves may be changed.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5], k = 2
+Output: [2,1,4,3,5]
+
+ +

Example 2:

+ +
Input: head = [1,2,3,4,5], k = 3
+Output: [3,2,1,4,5]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is n.
  • +
  • 1 <= k <= n <= 5000
  • +
  • 0 <= Node.val <= 1000
  • +
+ +

 

+

Follow-up: Can you solve the problem in O(1) extra memory space?

+
\ No newline at end of file diff --git a/0026-remove-duplicates-from-sorted-array/0026-remove-duplicates-from-sorted-array.py b/problems/0026-remove-duplicates-from-sorted-array/0026-remove-duplicates-from-sorted-array.py similarity index 100% rename from 0026-remove-duplicates-from-sorted-array/0026-remove-duplicates-from-sorted-array.py rename to problems/0026-remove-duplicates-from-sorted-array/0026-remove-duplicates-from-sorted-array.py diff --git a/0026-remove-duplicates-from-sorted-array/NOTES.md b/problems/0026-remove-duplicates-from-sorted-array/NOTES.md similarity index 100% rename from 0026-remove-duplicates-from-sorted-array/NOTES.md rename to problems/0026-remove-duplicates-from-sorted-array/NOTES.md diff --git a/problems/0026-remove-duplicates-from-sorted-array/README.md b/problems/0026-remove-duplicates-from-sorted-array/README.md new file mode 100644 index 000000000..ec0275917 --- /dev/null +++ b/problems/0026-remove-duplicates-from-sorted-array/README.md @@ -0,0 +1,52 @@ +

26. Remove Duplicates from Sorted Array

Easy


Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.

+ +

Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:

+ +
    +
  • Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums.
  • +
  • Return k.
  • +
+ +

Custom Judge:

+ +

The judge will test your solution with the following code:

+ +
int[] nums = [...]; // Input array
+int[] expectedNums = [...]; // The expected answer with correct length
+
+int k = removeDuplicates(nums); // Calls your implementation
+
+assert k == expectedNums.length;
+for (int i = 0; i < k; i++) {
+    assert nums[i] == expectedNums[i];
+}
+
+ +

If all assertions pass, then your solution will be accepted.

+ +

 

+

Example 1:

+ +
Input: nums = [1,1,2]
+Output: 2, nums = [1,2,_]
+Explanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.
+It does not matter what you leave beyond the returned k (hence they are underscores).
+
+ +

Example 2:

+ +
Input: nums = [0,0,1,1,1,2,2,3,3,4]
+Output: 5, nums = [0,1,2,3,4,_,_,_,_,_]
+Explanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
+It does not matter what you leave beyond the returned k (hence they are underscores).
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • -100 <= nums[i] <= 100
  • +
  • nums is sorted in non-decreasing order.
  • +
+
\ No newline at end of file diff --git a/0027-remove-element/0027-remove-element.py b/problems/0027-remove-element/0027-remove-element.py similarity index 100% rename from 0027-remove-element/0027-remove-element.py rename to problems/0027-remove-element/0027-remove-element.py diff --git a/0027-remove-element/NOTES.md b/problems/0027-remove-element/NOTES.md similarity index 100% rename from 0027-remove-element/NOTES.md rename to problems/0027-remove-element/NOTES.md diff --git a/problems/0027-remove-element/README.md b/problems/0027-remove-element/README.md new file mode 100644 index 000000000..f907255d9 --- /dev/null +++ b/problems/0027-remove-element/README.md @@ -0,0 +1,56 @@ +

27. Remove Element

Easy


Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.

+ +

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:

+ +
    +
  • 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:

+ +

The judge will test your solution with the following code:

+ +
int[] nums = [...]; // Input array
+int val = ...; // Value to remove
+int[] expectedNums = [...]; // The expected answer with correct length.
+                            // It is sorted with no values equaling val.
+
+int k = removeElement(nums, val); // Calls your implementation
+
+assert k == expectedNums.length;
+sort(nums, 0, k); // Sort the first k elements of nums
+for (int i = 0; i < actualLength; i++) {
+    assert nums[i] == expectedNums[i];
+}
+
+ +

If all assertions pass, then your solution will be accepted.

+ +

 

+

Example 1:

+ +
Input: nums = [3,2,2,3], val = 3
+Output: 2, nums = [2,2,_,_]
+Explanation: Your function should return k = 2, with the first two elements of nums being 2.
+It does not matter what you leave beyond the returned k (hence they are underscores).
+
+ +

Example 2:

+ +
Input: nums = [0,1,2,2,3,0,4,2], val = 2
+Output: 5, nums = [0,1,4,0,3,_,_,_]
+Explanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4.
+Note that the five elements can be returned in any order.
+It does not matter what you leave beyond the returned k (hence they are underscores).
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 50
  • +
  • 0 <= val <= 100
  • +
+
\ No newline at end of file diff --git a/0028-find-the-index-of-the-first-occurrence-in-a-string/0028-find-the-index-of-the-first-occurrence-in-a-string.py b/problems/0028-find-the-index-of-the-first-occurrence-in-a-string/0028-find-the-index-of-the-first-occurrence-in-a-string.py similarity index 100% rename from 0028-find-the-index-of-the-first-occurrence-in-a-string/0028-find-the-index-of-the-first-occurrence-in-a-string.py rename to problems/0028-find-the-index-of-the-first-occurrence-in-a-string/0028-find-the-index-of-the-first-occurrence-in-a-string.py diff --git a/0028-find-the-index-of-the-first-occurrence-in-a-string/NOTES.md b/problems/0028-find-the-index-of-the-first-occurrence-in-a-string/NOTES.md similarity index 100% rename from 0028-find-the-index-of-the-first-occurrence-in-a-string/NOTES.md rename to problems/0028-find-the-index-of-the-first-occurrence-in-a-string/NOTES.md diff --git a/problems/0028-find-the-index-of-the-first-occurrence-in-a-string/README.md b/problems/0028-find-the-index-of-the-first-occurrence-in-a-string/README.md new file mode 100644 index 000000000..f1a24eee4 --- /dev/null +++ b/problems/0028-find-the-index-of-the-first-occurrence-in-a-string/README.md @@ -0,0 +1,26 @@ +

28. Find the Index of the First Occurrence in a String

Easy


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 = "sadbutsad", needle = "sad"
+Output: 0
+Explanation: "sad" occurs at index 0 and 6.
+The first occurrence is at index 0, so we return 0.
+
+ +

Example 2:

+ +
Input: haystack = "leetcode", needle = "leeto"
+Output: -1
+Explanation: "leeto" did not occur in "leetcode", so we return -1.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= haystack.length, needle.length <= 104
  • +
  • haystack and needle consist of only lowercase English characters.
  • +
+
\ No newline at end of file diff --git a/0029-divide-two-integers/0029-divide-two-integers.py b/problems/0029-divide-two-integers/0029-divide-two-integers.py similarity index 100% rename from 0029-divide-two-integers/0029-divide-two-integers.py rename to problems/0029-divide-two-integers/0029-divide-two-integers.py diff --git a/0029-divide-two-integers/NOTES.md b/problems/0029-divide-two-integers/NOTES.md similarity index 100% rename from 0029-divide-two-integers/NOTES.md rename to problems/0029-divide-two-integers/NOTES.md diff --git a/problems/0029-divide-two-integers/README.md b/problems/0029-divide-two-integers/README.md new file mode 100644 index 000000000..9f694a561 --- /dev/null +++ b/problems/0029-divide-two-integers/README.md @@ -0,0 +1,31 @@ +

29. Divide Two Integers

Medium


Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.

+ +

The integer division should truncate toward zero, which means losing its fractional part. For example, 8.345 would be truncated to 8, and -2.7335 would be truncated to -2.

+ +

Return the quotient after dividing dividend by divisor.

+ +

Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For this problem, if the quotient is strictly greater than 231 - 1, then return 231 - 1, and if the quotient is strictly less than -231, then return -231.

+ +

 

+

Example 1:

+ +
Input: dividend = 10, divisor = 3
+Output: 3
+Explanation: 10/3 = 3.33333.. which is truncated to 3.
+
+ +

Example 2:

+ +
Input: dividend = 7, divisor = -3
+Output: -2
+Explanation: 7/-3 = -2.33333.. which is truncated to -2.
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= dividend, divisor <= 231 - 1
  • +
  • divisor != 0
  • +
+
\ No newline at end of file diff --git a/0031-next-permutation/0031-next-permutation.py b/problems/0031-next-permutation/0031-next-permutation.py similarity index 100% rename from 0031-next-permutation/0031-next-permutation.py rename to problems/0031-next-permutation/0031-next-permutation.py diff --git a/0031-next-permutation/NOTES.md b/problems/0031-next-permutation/NOTES.md similarity index 100% rename from 0031-next-permutation/NOTES.md rename to problems/0031-next-permutation/NOTES.md diff --git a/problems/0031-next-permutation/README.md b/problems/0031-next-permutation/README.md new file mode 100644 index 000000000..5d4986530 --- /dev/null +++ b/problems/0031-next-permutation/README.md @@ -0,0 +1,45 @@ +

31. Next Permutation

Medium


A permutation of an array of integers is an arrangement of its members into a sequence or linear 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 and use only constant extra memory.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3]
+Output: [1,3,2]
+
+ +

Example 2:

+ +
Input: nums = [3,2,1]
+Output: [1,2,3]
+
+ +

Example 3:

+ +
Input: nums = [1,1,5]
+Output: [1,5,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 100
  • +
+
\ No newline at end of file diff --git a/0033-search-in-rotated-sorted-array/0033-search-in-rotated-sorted-array.py b/problems/0033-search-in-rotated-sorted-array/0033-search-in-rotated-sorted-array.py similarity index 100% rename from 0033-search-in-rotated-sorted-array/0033-search-in-rotated-sorted-array.py rename to problems/0033-search-in-rotated-sorted-array/0033-search-in-rotated-sorted-array.py diff --git a/0033-search-in-rotated-sorted-array/NOTES.md b/problems/0033-search-in-rotated-sorted-array/NOTES.md similarity index 100% rename from 0033-search-in-rotated-sorted-array/NOTES.md rename to problems/0033-search-in-rotated-sorted-array/NOTES.md diff --git a/problems/0033-search-in-rotated-sorted-array/README.md b/problems/0033-search-in-rotated-sorted-array/README.md new file mode 100644 index 000000000..0e622ad12 --- /dev/null +++ b/problems/0033-search-in-rotated-sorted-array/README.md @@ -0,0 +1,30 @@ +

33. Search in Rotated Sorted Array

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].

+ +

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.

+ +

You must write an algorithm with O(log n) runtime complexity.

+ +

 

+

Example 1:

+
Input: nums = [4,5,6,7,0,1,2], target = 0
+Output: 4
+

Example 2:

+
Input: nums = [4,5,6,7,0,1,2], target = 3
+Output: -1
+

Example 3:

+
Input: nums = [1], target = 0
+Output: -1
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5000
  • +
  • -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 diff --git a/0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.py b/problems/0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.py similarity index 100% rename from 0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.py rename to problems/0034-find-first-and-last-position-of-element-in-sorted-array/0034-find-first-and-last-position-of-element-in-sorted-array.py diff --git a/0034-find-first-and-last-position-of-element-in-sorted-array/NOTES.md b/problems/0034-find-first-and-last-position-of-element-in-sorted-array/NOTES.md similarity index 100% rename from 0034-find-first-and-last-position-of-element-in-sorted-array/NOTES.md rename to problems/0034-find-first-and-last-position-of-element-in-sorted-array/NOTES.md diff --git a/problems/0034-find-first-and-last-position-of-element-in-sorted-array/README.md b/problems/0034-find-first-and-last-position-of-element-in-sorted-array/README.md new file mode 100644 index 000000000..3ba57ee9b --- /dev/null +++ b/problems/0034-find-first-and-last-position-of-element-in-sorted-array/README.md @@ -0,0 +1,27 @@ +

34. Find First and Last Position of Element in Sorted Array

Medium


Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.

+ +

If target is not found in the array, return [-1, -1].

+ +

You must write an algorithm with O(log n) runtime complexity.

+ +

 

+

Example 1:

+
Input: nums = [5,7,7,8,8,10], target = 8
+Output: [3,4]
+

Example 2:

+
Input: nums = [5,7,7,8,8,10], target = 6
+Output: [-1,-1]
+

Example 3:

+
Input: nums = [], target = 0
+Output: [-1,-1]
+
+

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
  • nums is a non-decreasing array.
  • +
  • -109 <= target <= 109
  • +
+
\ No newline at end of file diff --git a/0035-search-insert-position/0035-search-insert-position.cpp b/problems/0035-search-insert-position/0035-search-insert-position.cpp similarity index 100% rename from 0035-search-insert-position/0035-search-insert-position.cpp rename to problems/0035-search-insert-position/0035-search-insert-position.cpp diff --git a/0035-search-insert-position/NOTES.md b/problems/0035-search-insert-position/NOTES.md similarity index 100% rename from 0035-search-insert-position/NOTES.md rename to problems/0035-search-insert-position/NOTES.md diff --git a/problems/0035-search-insert-position/README.md b/problems/0035-search-insert-position/README.md new file mode 100644 index 000000000..8a61ea87e --- /dev/null +++ b/problems/0035-search-insert-position/README.md @@ -0,0 +1,33 @@ +

35. Search Insert Position

Easy


Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

+ +

You must write an algorithm with O(log n) runtime complexity.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3,5,6], target = 5
+Output: 2
+
+ +

Example 2:

+ +
Input: nums = [1,3,5,6], target = 2
+Output: 1
+
+ +

Example 3:

+ +
Input: nums = [1,3,5,6], target = 7
+Output: 4
+
+ +

 

+

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 diff --git a/0036-valid-sudoku/0036-valid-sudoku.cpp b/problems/0036-valid-sudoku/0036-valid-sudoku.cpp similarity index 100% rename from 0036-valid-sudoku/0036-valid-sudoku.cpp rename to problems/0036-valid-sudoku/0036-valid-sudoku.cpp diff --git a/0036-valid-sudoku/0036-valid-sudoku.py b/problems/0036-valid-sudoku/0036-valid-sudoku.py similarity index 100% rename from 0036-valid-sudoku/0036-valid-sudoku.py rename to problems/0036-valid-sudoku/0036-valid-sudoku.py diff --git a/0036-valid-sudoku/NOTES.md b/problems/0036-valid-sudoku/NOTES.md similarity index 100% rename from 0036-valid-sudoku/NOTES.md rename to problems/0036-valid-sudoku/NOTES.md diff --git a/problems/0036-valid-sudoku/README.md b/problems/0036-valid-sudoku/README.md new file mode 100644 index 000000000..b8a273938 --- /dev/null +++ b/problems/0036-valid-sudoku/README.md @@ -0,0 +1,56 @@ +

36. Valid Sudoku

Medium


Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

+ +
    +
  1. Each row must contain the digits 1-9 without repetition.
  2. +
  3. Each column must contain the digits 1-9 without repetition.
  4. +
  5. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
  6. +
+ +

Note:

+ +
    +
  • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
  • +
  • Only the filled cells need to be validated according to the mentioned rules.
  • +
+ +

 

+

Example 1:

+ +
Input: board = 
+[["5","3",".",".","7",".",".",".","."]
+,["6",".",".","1","9","5",".",".","."]
+,[".","9","8",".",".",".",".","6","."]
+,["8",".",".",".","6",".",".",".","3"]
+,["4",".",".","8",".","3",".",".","1"]
+,["7",".",".",".","2",".",".",".","6"]
+,[".","6",".",".",".",".","2","8","."]
+,[".",".",".","4","1","9",".",".","5"]
+,[".",".",".",".","8",".",".","7","9"]]
+Output: true
+
+ +

Example 2:

+ +
Input: board = 
+[["8","3",".",".","7",".",".",".","."]
+,["6",".",".","1","9","5",".",".","."]
+,[".","9","8",".",".",".",".","6","."]
+,["8",".",".",".","6",".",".",".","3"]
+,["4",".",".","8",".","3",".",".","1"]
+,["7",".",".",".","2",".",".",".","6"]
+,[".","6",".",".",".",".","2","8","."]
+,[".",".",".","4","1","9",".",".","5"]
+,[".",".",".",".","8",".",".","7","9"]]
+Output: false
+Explanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.
+
+ +

 

+

Constraints:

+ +
    +
  • board.length == 9
  • +
  • board[i].length == 9
  • +
  • board[i][j] is a digit 1-9 or '.'.
  • +
+
\ No newline at end of file diff --git a/0039-combination-sum/0039-combination-sum.py b/problems/0039-combination-sum/0039-combination-sum.py similarity index 100% rename from 0039-combination-sum/0039-combination-sum.py rename to problems/0039-combination-sum/0039-combination-sum.py diff --git a/0039-combination-sum/NOTES.md b/problems/0039-combination-sum/NOTES.md similarity index 100% rename from 0039-combination-sum/NOTES.md rename to problems/0039-combination-sum/NOTES.md diff --git a/problems/0039-combination-sum/README.md b/problems/0039-combination-sum/README.md new file mode 100644 index 000000000..5b4816e03 --- /dev/null +++ b/problems/0039-combination-sum/README.md @@ -0,0 +1,39 @@ +

39. Combination Sum

Medium


Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.

+ +

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.

+ +

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:

+ +
Input: candidates = [2,3,6,7], target = 7
+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.
+
+ +

Example 2:

+ +
Input: candidates = [2,3,5], target = 8
+Output: [[2,2,2,2],[2,3,3],[3,5]]
+
+ +

Example 3:

+ +
Input: candidates = [2], target = 1
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= candidates.length <= 30
  • +
  • 2 <= candidates[i] <= 40
  • +
  • All elements of candidates are distinct.
  • +
  • 1 <= target <= 40
  • +
+
\ No newline at end of file diff --git a/0040-combination-sum-ii/0040-combination-sum-ii.py b/problems/0040-combination-sum-ii/0040-combination-sum-ii.py similarity index 100% rename from 0040-combination-sum-ii/0040-combination-sum-ii.py rename to problems/0040-combination-sum-ii/0040-combination-sum-ii.py diff --git a/problems/0040-combination-sum-ii/README.md b/problems/0040-combination-sum-ii/README.md new file mode 100644 index 000000000..41ac5070f --- /dev/null +++ b/problems/0040-combination-sum-ii/README.md @@ -0,0 +1,38 @@ +

40. Combination Sum II

Medium


Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.

+ +

Each number in candidates may only be used once in the combination.

+ +

Note: The solution set must not contain duplicate combinations.

+ +

 

+

Example 1:

+ +
Input: candidates = [10,1,2,7,6,1,5], target = 8
+Output: 
+[
+[1,1,6],
+[1,2,5],
+[1,7],
+[2,6]
+]
+
+ +

Example 2:

+ +
Input: candidates = [2,5,2,1,2], target = 5
+Output: 
+[
+[1,2,2],
+[5]
+]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= candidates.length <= 100
  • +
  • 1 <= candidates[i] <= 50
  • +
  • 1 <= target <= 30
  • +
+
\ No newline at end of file diff --git a/0041-first-missing-positive/0041-first-missing-positive.py b/problems/0041-first-missing-positive/0041-first-missing-positive.py similarity index 100% rename from 0041-first-missing-positive/0041-first-missing-positive.py rename to problems/0041-first-missing-positive/0041-first-missing-positive.py diff --git a/0041-first-missing-positive/NOTES.md b/problems/0041-first-missing-positive/NOTES.md similarity index 100% rename from 0041-first-missing-positive/NOTES.md rename to problems/0041-first-missing-positive/NOTES.md diff --git a/problems/0041-first-missing-positive/README.md b/problems/0041-first-missing-positive/README.md new file mode 100644 index 000000000..8c35883a9 --- /dev/null +++ b/problems/0041-first-missing-positive/README.md @@ -0,0 +1,34 @@ +

41. First Missing Positive

Hard


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 O(1) auxiliary space.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,0]
+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
+Explanation: 1 is in the array but 2 is missing.
+
+ +

Example 3:

+ +
Input: nums = [7,8,9,11,12]
+Output: 1
+Explanation: The smallest positive integer 1 is missing.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0042-trapping-rain-water/0042-trapping-rain-water.py b/problems/0042-trapping-rain-water/0042-trapping-rain-water.py similarity index 100% rename from 0042-trapping-rain-water/0042-trapping-rain-water.py rename to problems/0042-trapping-rain-water/0042-trapping-rain-water.py diff --git a/0042-trapping-rain-water/NOTES.md b/problems/0042-trapping-rain-water/NOTES.md similarity index 100% rename from 0042-trapping-rain-water/NOTES.md rename to problems/0042-trapping-rain-water/NOTES.md diff --git a/problems/0042-trapping-rain-water/README.md b/problems/0042-trapping-rain-water/README.md new file mode 100644 index 000000000..9d727dd1c --- /dev/null +++ b/problems/0042-trapping-rain-water/README.md @@ -0,0 +1,25 @@ +

42. Trapping Rain Water

Hard


Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

+ +

 

+

Example 1:

+ +
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
+Output: 6
+Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
+
+ +

Example 2:

+ +
Input: height = [4,2,0,3,2,5]
+Output: 9
+
+ +

 

+

Constraints:

+ +
    +
  • n == height.length
  • +
  • 1 <= n <= 2 * 104
  • +
  • 0 <= height[i] <= 105
  • +
+
\ No newline at end of file diff --git a/0045-jump-game-ii/0045-jump-game-ii.cpp b/problems/0045-jump-game-ii/0045-jump-game-ii.cpp similarity index 100% rename from 0045-jump-game-ii/0045-jump-game-ii.cpp rename to problems/0045-jump-game-ii/0045-jump-game-ii.cpp diff --git a/0045-jump-game-ii/NOTES.md b/problems/0045-jump-game-ii/NOTES.md similarity index 100% rename from 0045-jump-game-ii/NOTES.md rename to problems/0045-jump-game-ii/NOTES.md diff --git a/problems/0045-jump-game-ii/README.md b/problems/0045-jump-game-ii/README.md new file mode 100644 index 000000000..57bef2ed9 --- /dev/null +++ b/problems/0045-jump-game-ii/README.md @@ -0,0 +1,34 @@ +

45. Jump Game II

Medium


You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0].

+ +

Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where:

+ +
    +
  • 0 <= j <= nums[i] and
  • +
  • i + j < n
  • +
+ +

Return the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1].

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,1,1,4]
+Output: 2
+Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
+
+ +

Example 2:

+ +
Input: nums = [2,3,0,1,4]
+Output: 2
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 104
  • +
  • 0 <= nums[i] <= 1000
  • +
  • It's guaranteed that you can reach nums[n - 1].
  • +
+
\ No newline at end of file diff --git a/0046-permutations/0046-permutations.cpp b/problems/0046-permutations/0046-permutations.cpp similarity index 100% rename from 0046-permutations/0046-permutations.cpp rename to problems/0046-permutations/0046-permutations.cpp diff --git a/0046-permutations/0046-permutations.py b/problems/0046-permutations/0046-permutations.py similarity index 100% rename from 0046-permutations/0046-permutations.py rename to problems/0046-permutations/0046-permutations.py diff --git a/0046-permutations/NOTES.md b/problems/0046-permutations/NOTES.md similarity index 100% rename from 0046-permutations/NOTES.md rename to problems/0046-permutations/NOTES.md diff --git a/problems/0046-permutations/README.md b/problems/0046-permutations/README.md new file mode 100644 index 000000000..25218c6e2 --- /dev/null +++ b/problems/0046-permutations/README.md @@ -0,0 +1,22 @@ +

46. Permutations

Medium


Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

+ +

 

+

Example 1:

+
Input: nums = [1,2,3]
+Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
+

Example 2:

+
Input: nums = [0,1]
+Output: [[0,1],[1,0]]
+

Example 3:

+
Input: nums = [1]
+Output: [[1]]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 6
  • +
  • -10 <= nums[i] <= 10
  • +
  • All the integers of nums are unique.
  • +
+
\ No newline at end of file diff --git a/0048-rotate-image/0048-rotate-image.cpp b/problems/0048-rotate-image/0048-rotate-image.cpp similarity index 100% rename from 0048-rotate-image/0048-rotate-image.cpp rename to problems/0048-rotate-image/0048-rotate-image.cpp diff --git a/0048-rotate-image/NOTES.md b/problems/0048-rotate-image/NOTES.md similarity index 100% rename from 0048-rotate-image/NOTES.md rename to problems/0048-rotate-image/NOTES.md diff --git a/problems/0048-rotate-image/README.md b/problems/0048-rotate-image/README.md new file mode 100644 index 000000000..c415d5c42 --- /dev/null +++ b/problems/0048-rotate-image/README.md @@ -0,0 +1,26 @@ +

48. Rotate Image

Medium


You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

+ +

You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

+ +

 

+

Example 1:

+ +
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
+Output: [[7,4,1],[8,5,2],[9,6,3]]
+
+ +

Example 2:

+ +
Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
+Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
+
+ +

 

+

Constraints:

+ +
    +
  • n == matrix.length == matrix[i].length
  • +
  • 1 <= n <= 20
  • +
  • -1000 <= matrix[i][j] <= 1000
  • +
+
\ No newline at end of file diff --git a/0049-group-anagrams/0049-group-anagrams.js b/problems/0049-group-anagrams/0049-group-anagrams.js similarity index 100% rename from 0049-group-anagrams/0049-group-anagrams.js rename to problems/0049-group-anagrams/0049-group-anagrams.js diff --git a/0049-group-anagrams/0049-group-anagrams.py b/problems/0049-group-anagrams/0049-group-anagrams.py similarity index 100% rename from 0049-group-anagrams/0049-group-anagrams.py rename to problems/0049-group-anagrams/0049-group-anagrams.py diff --git a/0049-group-anagrams/NOTES.md b/problems/0049-group-anagrams/NOTES.md similarity index 100% rename from 0049-group-anagrams/NOTES.md rename to problems/0049-group-anagrams/NOTES.md diff --git a/problems/0049-group-anagrams/README.md b/problems/0049-group-anagrams/README.md new file mode 100644 index 000000000..3da623eb5 --- /dev/null +++ b/problems/0049-group-anagrams/README.md @@ -0,0 +1,24 @@ +

49. Group Anagrams

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.

+ +

 

+

Example 1:

+
Input: strs = ["eat","tea","tan","ate","nat","bat"]
+Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
+

Example 2:

+
Input: strs = [""]
+Output: [[""]]
+

Example 3:

+
Input: strs = ["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 diff --git a/0050-powx-n/0050-powx-n.py b/problems/0050-powx-n/0050-powx-n.py similarity index 100% rename from 0050-powx-n/0050-powx-n.py rename to problems/0050-powx-n/0050-powx-n.py diff --git a/0050-powx-n/NOTES.md b/problems/0050-powx-n/NOTES.md similarity index 100% rename from 0050-powx-n/NOTES.md rename to problems/0050-powx-n/NOTES.md diff --git a/problems/0050-powx-n/README.md b/problems/0050-powx-n/README.md new file mode 100644 index 000000000..b4380f4bf --- /dev/null +++ b/problems/0050-powx-n/README.md @@ -0,0 +1,33 @@ +

50. Pow(x, n)

Medium


Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

+ +

 

+

Example 1:

+ +
Input: x = 2.00000, n = 10
+Output: 1024.00000
+
+ +

Example 2:

+ +
Input: x = 2.10000, n = 3
+Output: 9.26100
+
+ +

Example 3:

+ +
Input: x = 2.00000, n = -2
+Output: 0.25000
+Explanation: 2-2 = 1/22 = 1/4 = 0.25
+
+ +

 

+

Constraints:

+ +
    +
  • -100.0 < x < 100.0
  • +
  • -231 <= n <= 231-1
  • +
  • n is an integer.
  • +
  • Either x is not zero or n > 0.
  • +
  • -104 <= xn <= 104
  • +
+
\ No newline at end of file diff --git a/0053-maximum-subarray/0053-maximum-subarray.cpp b/problems/0053-maximum-subarray/0053-maximum-subarray.cpp similarity index 100% rename from 0053-maximum-subarray/0053-maximum-subarray.cpp rename to problems/0053-maximum-subarray/0053-maximum-subarray.cpp diff --git a/0053-maximum-subarray/0053-maximum-subarray.py b/problems/0053-maximum-subarray/0053-maximum-subarray.py similarity index 100% rename from 0053-maximum-subarray/0053-maximum-subarray.py rename to problems/0053-maximum-subarray/0053-maximum-subarray.py diff --git a/0053-maximum-subarray/NOTES.md b/problems/0053-maximum-subarray/NOTES.md similarity index 100% rename from 0053-maximum-subarray/NOTES.md rename to problems/0053-maximum-subarray/NOTES.md diff --git a/problems/0053-maximum-subarray/README.md b/problems/0053-maximum-subarray/README.md new file mode 100644 index 000000000..8c856c7c3 --- /dev/null +++ b/problems/0053-maximum-subarray/README.md @@ -0,0 +1,35 @@ +

53. Maximum Subarray

Medium


Given an integer array nums, find the subarray with the largest sum, and return its sum.

+ +

 

+

Example 1:

+ +
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
+Output: 6
+Explanation: The subarray [4,-1,2,1] has the largest sum 6.
+
+ +

Example 2:

+ +
Input: nums = [1]
+Output: 1
+Explanation: The subarray [1] has the largest sum 1.
+
+ +

Example 3:

+ +
Input: nums = [5,4,-1,7,8]
+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 diff --git a/0054-spiral-matrix/0054-spiral-matrix.cpp b/problems/0054-spiral-matrix/0054-spiral-matrix.cpp similarity index 100% rename from 0054-spiral-matrix/0054-spiral-matrix.cpp rename to problems/0054-spiral-matrix/0054-spiral-matrix.cpp diff --git a/0054-spiral-matrix/0054-spiral-matrix.py b/problems/0054-spiral-matrix/0054-spiral-matrix.py similarity index 100% rename from 0054-spiral-matrix/0054-spiral-matrix.py rename to problems/0054-spiral-matrix/0054-spiral-matrix.py diff --git a/0054-spiral-matrix/NOTES.md b/problems/0054-spiral-matrix/NOTES.md similarity index 100% rename from 0054-spiral-matrix/NOTES.md rename to problems/0054-spiral-matrix/NOTES.md diff --git a/problems/0054-spiral-matrix/README.md b/problems/0054-spiral-matrix/README.md new file mode 100644 index 000000000..afec7a07d --- /dev/null +++ b/problems/0054-spiral-matrix/README.md @@ -0,0 +1,25 @@ +

54. Spiral Matrix

Medium


Given an m x n matrix, return all elements of the matrix in spiral order.

+ +

 

+

Example 1:

+ +
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
+Output: [1,2,3,6,9,8,7,4,5]
+
+ +

Example 2:

+ +
Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
+Output: [1,2,3,4,8,12,11,10,9,5,6,7]
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m, n <= 10
  • +
  • -100 <= matrix[i][j] <= 100
  • +
+
\ No newline at end of file diff --git a/0055-jump-game/0055-jump-game.cpp b/problems/0055-jump-game/0055-jump-game.cpp similarity index 100% rename from 0055-jump-game/0055-jump-game.cpp rename to problems/0055-jump-game/0055-jump-game.cpp diff --git a/0055-jump-game/NOTES.md b/problems/0055-jump-game/NOTES.md similarity index 100% rename from 0055-jump-game/NOTES.md rename to problems/0055-jump-game/NOTES.md diff --git a/0056-merge-intervals/0056-merge-intervals.cpp b/problems/0056-merge-intervals/0056-merge-intervals.cpp similarity index 100% rename from 0056-merge-intervals/0056-merge-intervals.cpp rename to problems/0056-merge-intervals/0056-merge-intervals.cpp diff --git a/0056-merge-intervals/0056-merge-intervals.py b/problems/0056-merge-intervals/0056-merge-intervals.py similarity index 100% rename from 0056-merge-intervals/0056-merge-intervals.py rename to problems/0056-merge-intervals/0056-merge-intervals.py diff --git a/0056-merge-intervals/NOTES.md b/problems/0056-merge-intervals/NOTES.md similarity index 100% rename from 0056-merge-intervals/NOTES.md rename to problems/0056-merge-intervals/NOTES.md diff --git a/problems/0056-merge-intervals/README.md b/problems/0056-merge-intervals/README.md new file mode 100644 index 000000000..78870292f --- /dev/null +++ b/problems/0056-merge-intervals/README.md @@ -0,0 +1,26 @@ +

56. Merge Intervals

Medium


Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

+ +

 

+

Example 1:

+ +
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
+Output: [[1,6],[8,10],[15,18]]
+Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6].
+
+ +

Example 2:

+ +
Input: intervals = [[1,4],[4,5]]
+Output: [[1,5]]
+Explanation: Intervals [1,4] and [4,5] are considered overlapping.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= intervals.length <= 104
  • +
  • intervals[i].length == 2
  • +
  • 0 <= starti <= endi <= 104
  • +
+
\ No newline at end of file diff --git a/0057-insert-interval/0057-insert-interval.py b/problems/0057-insert-interval/0057-insert-interval.py similarity index 100% rename from 0057-insert-interval/0057-insert-interval.py rename to problems/0057-insert-interval/0057-insert-interval.py diff --git a/0057-insert-interval/NOTES.md b/problems/0057-insert-interval/NOTES.md similarity index 100% rename from 0057-insert-interval/NOTES.md rename to problems/0057-insert-interval/NOTES.md diff --git a/problems/0057-insert-interval/README.md b/problems/0057-insert-interval/README.md new file mode 100644 index 000000000..3805102b5 --- /dev/null +++ b/problems/0057-insert-interval/README.md @@ -0,0 +1,32 @@ +

57. Insert Interval

Medium


You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval.

+ +

Insert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping intervals (merge overlapping intervals if necessary).

+ +

Return intervals after the insertion.

+ +

 

+

Example 1:

+ +
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
+Output: [[1,5],[6,9]]
+
+ +

Example 2:

+ +
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
+Output: [[1,2],[3,10],[12,16]]
+Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= intervals.length <= 104
  • +
  • intervals[i].length == 2
  • +
  • 0 <= starti <= endi <= 105
  • +
  • intervals is sorted by starti in ascending order.
  • +
  • newInterval.length == 2
  • +
  • 0 <= start <= end <= 105
  • +
+
\ No newline at end of file diff --git a/0058-length-of-last-word/0058-length-of-last-word.py b/problems/0058-length-of-last-word/0058-length-of-last-word.py similarity index 100% rename from 0058-length-of-last-word/0058-length-of-last-word.py rename to problems/0058-length-of-last-word/0058-length-of-last-word.py diff --git a/0058-length-of-last-word/NOTES.md b/problems/0058-length-of-last-word/NOTES.md similarity index 100% rename from 0058-length-of-last-word/NOTES.md rename to problems/0058-length-of-last-word/NOTES.md diff --git a/problems/0058-length-of-last-word/README.md b/problems/0058-length-of-last-word/README.md new file mode 100644 index 000000000..f5d2873af --- /dev/null +++ b/problems/0058-length-of-last-word/README.md @@ -0,0 +1,35 @@ +

58. Length of Last Word

Easy


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.

+ +

 

+

Example 1:

+ +
Input: s = "Hello World"
+Output: 5
+Explanation: The last word is "World" with length 5.
+
+ +

Example 2:

+ +
Input: s = "   fly me   to   the moon  "
+Output: 4
+Explanation: The last word is "moon" with length 4.
+
+ +

Example 3:

+ +
Input: s = "luffy is still joyboy"
+Output: 6
+Explanation: The last word is "joyboy" with length 6.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 104
  • +
  • s consists of only English letters and spaces ' '.
  • +
  • There will be at least one word in s.
  • +
+
\ No newline at end of file diff --git a/0059-spiral-matrix-ii/0059-spiral-matrix-ii.cpp b/problems/0059-spiral-matrix-ii/0059-spiral-matrix-ii.cpp similarity index 100% rename from 0059-spiral-matrix-ii/0059-spiral-matrix-ii.cpp rename to problems/0059-spiral-matrix-ii/0059-spiral-matrix-ii.cpp diff --git a/0059-spiral-matrix-ii/NOTES.md b/problems/0059-spiral-matrix-ii/NOTES.md similarity index 100% rename from 0059-spiral-matrix-ii/NOTES.md rename to problems/0059-spiral-matrix-ii/NOTES.md diff --git a/problems/0059-spiral-matrix-ii/README.md b/problems/0059-spiral-matrix-ii/README.md new file mode 100644 index 000000000..69fe38f84 --- /dev/null +++ b/problems/0059-spiral-matrix-ii/README.md @@ -0,0 +1,22 @@ +

59. Spiral Matrix II

Medium


Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.

+ +

 

+

Example 1:

+ +
Input: n = 3
+Output: [[1,2,3],[8,9,4],[7,6,5]]
+
+ +

Example 2:

+ +
Input: n = 1
+Output: [[1]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 20
  • +
+
\ No newline at end of file diff --git a/0061-rotate-list/0061-rotate-list.py b/problems/0061-rotate-list/0061-rotate-list.py similarity index 100% rename from 0061-rotate-list/0061-rotate-list.py rename to problems/0061-rotate-list/0061-rotate-list.py diff --git a/0061-rotate-list/NOTES.md b/problems/0061-rotate-list/NOTES.md similarity index 100% rename from 0061-rotate-list/NOTES.md rename to problems/0061-rotate-list/NOTES.md diff --git a/problems/0061-rotate-list/README.md b/problems/0061-rotate-list/README.md new file mode 100644 index 000000000..390023b42 --- /dev/null +++ b/problems/0061-rotate-list/README.md @@ -0,0 +1,24 @@ +

61. Rotate List

Medium


Given the head of a linked list, rotate the list to the right by k places.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5], k = 2
+Output: [4,5,1,2,3]
+
+ +

Example 2:

+ +
Input: head = [0,1,2], k = 4
+Output: [2,0,1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 500].
  • +
  • -100 <= Node.val <= 100
  • +
  • 0 <= k <= 2 * 109
  • +
+
\ No newline at end of file diff --git a/0062-unique-paths/0062-unique-paths.py b/problems/0062-unique-paths/0062-unique-paths.py similarity index 100% rename from 0062-unique-paths/0062-unique-paths.py rename to problems/0062-unique-paths/0062-unique-paths.py diff --git a/0062-unique-paths/NOTES.md b/problems/0062-unique-paths/NOTES.md similarity index 100% rename from 0062-unique-paths/NOTES.md rename to problems/0062-unique-paths/NOTES.md diff --git a/problems/0062-unique-paths/README.md b/problems/0062-unique-paths/README.md new file mode 100644 index 000000000..ec1dd06ab --- /dev/null +++ b/problems/0062-unique-paths/README.md @@ -0,0 +1,30 @@ +

62. Unique Paths

Medium


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.

+ +

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.

+ +

The test cases are generated so that the answer will be less than or equal to 2 * 109.

+ +

 

+

Example 1:

+ +
Input: m = 3, n = 7
+Output: 28
+
+ +

Example 2:

+ +
Input: m = 3, n = 2
+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
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= m, n <= 100
  • +
+
\ No newline at end of file diff --git a/0063-unique-paths-ii/0063-unique-paths-ii.py b/problems/0063-unique-paths-ii/0063-unique-paths-ii.py similarity index 100% rename from 0063-unique-paths-ii/0063-unique-paths-ii.py rename to problems/0063-unique-paths-ii/0063-unique-paths-ii.py diff --git a/problems/0063-unique-paths-ii/README.md b/problems/0063-unique-paths-ii/README.md new file mode 100644 index 000000000..bdcad1fe1 --- /dev/null +++ b/problems/0063-unique-paths-ii/README.md @@ -0,0 +1,35 @@ +

63. Unique Paths II

Medium


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.

+ +

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.

+ +

Return the number of possible unique paths that the robot can take to reach the bottom-right corner.

+ +

The testcases are generated so that the answer will be less than or equal to 2 * 109.

+ +

 

+

Example 1:

+ +
Input: obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]
+Output: 2
+Explanation: There is one obstacle in the middle of the 3x3 grid above.
+There are two ways to reach the bottom-right corner:
+1. Right -> Right -> Down -> Down
+2. Down -> Down -> Right -> Right
+
+ +

Example 2:

+ +
Input: obstacleGrid = [[0,1],[0,0]]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • m == obstacleGrid.length
  • +
  • n == obstacleGrid[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • obstacleGrid[i][j] is 0 or 1.
  • +
+
\ No newline at end of file diff --git a/0064-minimum-path-sum/0064-minimum-path-sum.py b/problems/0064-minimum-path-sum/0064-minimum-path-sum.py similarity index 100% rename from 0064-minimum-path-sum/0064-minimum-path-sum.py rename to problems/0064-minimum-path-sum/0064-minimum-path-sum.py diff --git a/0064-minimum-path-sum/NOTES.md b/problems/0064-minimum-path-sum/NOTES.md similarity index 100% rename from 0064-minimum-path-sum/NOTES.md rename to problems/0064-minimum-path-sum/NOTES.md diff --git a/problems/0064-minimum-path-sum/README.md b/problems/0064-minimum-path-sum/README.md new file mode 100644 index 000000000..8da7737ce --- /dev/null +++ b/problems/0064-minimum-path-sum/README.md @@ -0,0 +1,28 @@ +

64. Minimum Path Sum

Medium


Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.

+ +

Note: You can only move either down or right at any point in time.

+ +

 

+

Example 1:

+ +
Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
+Output: 7
+Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.
+
+ +

Example 2:

+ +
Input: grid = [[1,2,3],[4,5,6]]
+Output: 12
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 200
  • +
  • 0 <= grid[i][j] <= 200
  • +
+
\ No newline at end of file diff --git a/0066-plus-one/0066-plus-one.py b/problems/0066-plus-one/0066-plus-one.py similarity index 100% rename from 0066-plus-one/0066-plus-one.py rename to problems/0066-plus-one/0066-plus-one.py diff --git a/0066-plus-one/NOTES.md b/problems/0066-plus-one/NOTES.md similarity index 100% rename from 0066-plus-one/NOTES.md rename to problems/0066-plus-one/NOTES.md diff --git a/problems/0066-plus-one/README.md b/problems/0066-plus-one/README.md new file mode 100644 index 000000000..f3cdb2530 --- /dev/null +++ b/problems/0066-plus-one/README.md @@ -0,0 +1,41 @@ +

66. Plus One

Easy


You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.

+ +

Increment the large integer by one and return the resulting array of digits.

+ +

 

+

Example 1:

+ +
Input: digits = [1,2,3]
+Output: [1,2,4]
+Explanation: The array represents the integer 123.
+Incrementing by one gives 123 + 1 = 124.
+Thus, the result should be [1,2,4].
+
+ +

Example 2:

+ +
Input: digits = [4,3,2,1]
+Output: [4,3,2,2]
+Explanation: The array represents the integer 4321.
+Incrementing by one gives 4321 + 1 = 4322.
+Thus, the result should be [4,3,2,2].
+
+ +

Example 3:

+ +
Input: digits = [9]
+Output: [1,0]
+Explanation: The array represents the integer 9.
+Incrementing by one gives 9 + 1 = 10.
+Thus, the result should be [1,0].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= digits.length <= 100
  • +
  • 0 <= digits[i] <= 9
  • +
  • digits does not contain any leading 0's.
  • +
+
\ No newline at end of file diff --git a/0067-add-binary/0067-add-binary.py b/problems/0067-add-binary/0067-add-binary.py similarity index 100% rename from 0067-add-binary/0067-add-binary.py rename to problems/0067-add-binary/0067-add-binary.py diff --git a/0067-add-binary/NOTES.md b/problems/0067-add-binary/NOTES.md similarity index 100% rename from 0067-add-binary/NOTES.md rename to problems/0067-add-binary/NOTES.md diff --git a/problems/0067-add-binary/README.md b/problems/0067-add-binary/README.md new file mode 100644 index 000000000..ecb580d89 --- /dev/null +++ b/problems/0067-add-binary/README.md @@ -0,0 +1,19 @@ +

67. Add Binary

Easy


Given two binary strings a and b, return their sum as a binary string.

+ +

 

+

Example 1:

+
Input: a = "11", b = "1"
+Output: "100"
+

Example 2:

+
Input: a = "1010", b = "1011"
+Output: "10101"
+
+

 

+

Constraints:

+ +
    +
  • 1 <= a.length, b.length <= 104
  • +
  • a and b consist only of '0' or '1' characters.
  • +
  • Each string does not contain leading zeros except for the zero itself.
  • +
+
\ No newline at end of file diff --git a/0068-text-justification/0068-text-justification.py b/problems/0068-text-justification/0068-text-justification.py similarity index 100% rename from 0068-text-justification/0068-text-justification.py rename to problems/0068-text-justification/0068-text-justification.py diff --git a/0068-text-justification/NOTES.md b/problems/0068-text-justification/NOTES.md similarity index 100% rename from 0068-text-justification/NOTES.md rename to problems/0068-text-justification/NOTES.md diff --git a/problems/0068-text-justification/README.md b/problems/0068-text-justification/README.md new file mode 100644 index 000000000..69126ecf1 --- /dev/null +++ b/problems/0068-text-justification/README.md @@ -0,0 +1,63 @@ +

68. Text Justification

Hard


Given an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.

+ +

You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.

+ +

Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.

+ +

For the last line of text, it should be left-justified, and no extra space is inserted between words.

+ +

Note:

+ +
    +
  • A word is defined as a character sequence consisting of non-space characters only.
  • +
  • Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
  • +
  • The input array words contains at least one word.
  • +
+ +

 

+

Example 1:

+ +
Input: words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16
+Output:
+[
+   "This    is    an",
+   "example  of text",
+   "justification.  "
+]
+ +

Example 2:

+ +
Input: words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16
+Output:
+[
+  "What   must   be",
+  "acknowledgment  ",
+  "shall be        "
+]
+Explanation: Note that the last line is "shall be    " instead of "shall     be", because the last line must be left-justified instead of fully-justified.
+Note that the second line is also left-justified because it contains only one word.
+ +

Example 3:

+ +
Input: words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20
+Output:
+[
+  "Science  is  what we",
+  "understand      well",
+  "enough to explain to",
+  "a  computer.  Art is",
+  "everything  else  we",
+  "do                  "
+]
+ +

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 300
  • +
  • 1 <= words[i].length <= 20
  • +
  • words[i] consists of only English letters and symbols.
  • +
  • 1 <= maxWidth <= 100
  • +
  • words[i].length <= maxWidth
  • +
+
\ No newline at end of file diff --git a/0069-sqrtx/0069-sqrtx.py b/problems/0069-sqrtx/0069-sqrtx.py similarity index 100% rename from 0069-sqrtx/0069-sqrtx.py rename to problems/0069-sqrtx/0069-sqrtx.py diff --git a/0069-sqrtx/NOTES.md b/problems/0069-sqrtx/NOTES.md similarity index 100% rename from 0069-sqrtx/NOTES.md rename to problems/0069-sqrtx/NOTES.md diff --git a/problems/0069-sqrtx/README.md b/problems/0069-sqrtx/README.md new file mode 100644 index 000000000..3b33c2e0d --- /dev/null +++ b/problems/0069-sqrtx/README.md @@ -0,0 +1,30 @@ +

69. Sqrt(x)

Easy


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.

+ +

You must not use any built-in exponent function or operator.

+ +
    +
  • For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python.
  • +
+ +

 

+

Example 1:

+ +
Input: x = 4
+Output: 2
+Explanation: The square root of 4 is 2, so we return 2.
+
+ +

Example 2:

+ +
Input: x = 8
+Output: 2
+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
  • +
+
\ No newline at end of file diff --git a/0070-climbing-stairs/0070-climbing-stairs.cpp b/problems/0070-climbing-stairs/0070-climbing-stairs.cpp similarity index 100% rename from 0070-climbing-stairs/0070-climbing-stairs.cpp rename to problems/0070-climbing-stairs/0070-climbing-stairs.cpp diff --git a/0070-climbing-stairs/0070-climbing-stairs.py b/problems/0070-climbing-stairs/0070-climbing-stairs.py similarity index 100% rename from 0070-climbing-stairs/0070-climbing-stairs.py rename to problems/0070-climbing-stairs/0070-climbing-stairs.py diff --git a/0070-climbing-stairs/NOTES.md b/problems/0070-climbing-stairs/NOTES.md similarity index 100% rename from 0070-climbing-stairs/NOTES.md rename to problems/0070-climbing-stairs/NOTES.md diff --git a/problems/0070-climbing-stairs/README.md b/problems/0070-climbing-stairs/README.md new file mode 100644 index 000000000..c864654b7 --- /dev/null +++ b/problems/0070-climbing-stairs/README.md @@ -0,0 +1,31 @@ +

70. Climbing Stairs

Easy


You are climbing a staircase. It takes n steps to reach the top.

+ +

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

+ +

 

+

Example 1:

+ +
Input: n = 2
+Output: 2
+Explanation: There are two ways to climb to the top.
+1. 1 step + 1 step
+2. 2 steps
+
+ +

Example 2:

+ +
Input: n = 3
+Output: 3
+Explanation: There are three ways to climb to the top.
+1. 1 step + 1 step + 1 step
+2. 1 step + 2 steps
+3. 2 steps + 1 step
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 45
  • +
+
\ No newline at end of file diff --git a/0073-set-matrix-zeroes/0073-set-matrix-zeroes.py b/problems/0073-set-matrix-zeroes/0073-set-matrix-zeroes.py similarity index 100% rename from 0073-set-matrix-zeroes/0073-set-matrix-zeroes.py rename to problems/0073-set-matrix-zeroes/0073-set-matrix-zeroes.py diff --git a/0073-set-matrix-zeroes/NOTES.md b/problems/0073-set-matrix-zeroes/NOTES.md similarity index 100% rename from 0073-set-matrix-zeroes/NOTES.md rename to problems/0073-set-matrix-zeroes/NOTES.md diff --git a/problems/0073-set-matrix-zeroes/README.md b/problems/0073-set-matrix-zeroes/README.md new file mode 100644 index 000000000..574d6249a --- /dev/null +++ b/problems/0073-set-matrix-zeroes/README.md @@ -0,0 +1,36 @@ +

73. Set Matrix Zeroes

Medium


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.

+ +

 

+

Example 1:

+ +
Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
+Output: [[1,0,1],[0,0,0],[1,0,1]]
+
+ +

Example 2:

+ +
Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
+Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[0].length
  • +
  • 1 <= m, n <= 200
  • +
  • -231 <= matrix[i][j] <= 231 - 1
  • +
+ +

 

+

Follow up:

+ +
    +
  • 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 diff --git a/0074-search-a-2d-matrix/0074-search-a-2d-matrix.cpp b/problems/0074-search-a-2d-matrix/0074-search-a-2d-matrix.cpp similarity index 100% rename from 0074-search-a-2d-matrix/0074-search-a-2d-matrix.cpp rename to problems/0074-search-a-2d-matrix/0074-search-a-2d-matrix.cpp diff --git a/0074-search-a-2d-matrix/0074-search-a-2d-matrix.js b/problems/0074-search-a-2d-matrix/0074-search-a-2d-matrix.js similarity index 100% rename from 0074-search-a-2d-matrix/0074-search-a-2d-matrix.js rename to problems/0074-search-a-2d-matrix/0074-search-a-2d-matrix.js diff --git a/0074-search-a-2d-matrix/0074-search-a-2d-matrix.py b/problems/0074-search-a-2d-matrix/0074-search-a-2d-matrix.py similarity index 100% rename from 0074-search-a-2d-matrix/0074-search-a-2d-matrix.py rename to problems/0074-search-a-2d-matrix/0074-search-a-2d-matrix.py diff --git a/0074-search-a-2d-matrix/NOTES.md b/problems/0074-search-a-2d-matrix/NOTES.md similarity index 100% rename from 0074-search-a-2d-matrix/NOTES.md rename to problems/0074-search-a-2d-matrix/NOTES.md diff --git a/problems/0074-search-a-2d-matrix/README.md b/problems/0074-search-a-2d-matrix/README.md new file mode 100644 index 000000000..176870938 --- /dev/null +++ b/problems/0074-search-a-2d-matrix/README.md @@ -0,0 +1,34 @@ +

74. Search a 2D Matrix

Medium


You are given an m x n integer matrix matrix with the following two properties:

+ +
    +
  • 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:

+ +
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
+Output: true
+
+ +

Example 2:

+ +
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • -104 <= matrix[i][j], target <= 104
  • +
+
\ No newline at end of file diff --git a/0075-sort-colors/0075-sort-colors.cpp b/problems/0075-sort-colors/0075-sort-colors.cpp similarity index 100% rename from 0075-sort-colors/0075-sort-colors.cpp rename to problems/0075-sort-colors/0075-sort-colors.cpp diff --git a/0075-sort-colors/0075-sort-colors.py b/problems/0075-sort-colors/0075-sort-colors.py similarity index 100% rename from 0075-sort-colors/0075-sort-colors.py rename to problems/0075-sort-colors/0075-sort-colors.py diff --git a/0075-sort-colors/NOTES.md b/problems/0075-sort-colors/NOTES.md similarity index 100% rename from 0075-sort-colors/NOTES.md rename to problems/0075-sort-colors/NOTES.md diff --git a/problems/0075-sort-colors/README.md b/problems/0075-sort-colors/README.md new file mode 100644 index 000000000..7ea19a67c --- /dev/null +++ b/problems/0075-sort-colors/README.md @@ -0,0 +1,31 @@ +

75. Sort Colors

Medium


Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

+ +

We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

+ +

You must solve this problem without using the library's sort function.

+ +

 

+

Example 1:

+ +
Input: nums = [2,0,2,1,1,0]
+Output: [0,0,1,1,2,2]
+
+ +

Example 2:

+ +
Input: nums = [2,0,1]
+Output: [0,1,2]
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 300
  • +
  • nums[i] is either 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 diff --git a/0076-minimum-window-substring/0076-minimum-window-substring.py b/problems/0076-minimum-window-substring/0076-minimum-window-substring.py similarity index 100% rename from 0076-minimum-window-substring/0076-minimum-window-substring.py rename to problems/0076-minimum-window-substring/0076-minimum-window-substring.py diff --git a/0076-minimum-window-substring/NOTES.md b/problems/0076-minimum-window-substring/NOTES.md similarity index 100% rename from 0076-minimum-window-substring/NOTES.md rename to problems/0076-minimum-window-substring/NOTES.md diff --git a/problems/0076-minimum-window-substring/README.md b/problems/0076-minimum-window-substring/README.md new file mode 100644 index 000000000..0f0823a6f --- /dev/null +++ b/problems/0076-minimum-window-substring/README.md @@ -0,0 +1,40 @@ +

76. Minimum Window Substring

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 "".

+ +

The testcases will be generated such that the answer is unique.

+ +

 

+

Example 1:

+ +
Input: s = "ADOBECODEBANC", t = "ABC"
+Output: "BANC"
+Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
+
+ +

Example 2:

+ +
Input: s = "a", t = "a"
+Output: "a"
+Explanation: The entire string s is the minimum window.
+
+ +

Example 3:

+ +
Input: s = "a", t = "aa"
+Output: ""
+Explanation: Both 'a's from t must be included in the window.
+Since the largest window of s only has one 'a', return empty string.
+
+ +

 

+

Constraints:

+ +
    +
  • m == s.length
  • +
  • n == t.length
  • +
  • 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 diff --git a/0077-combinations/0077-combinations.cpp b/problems/0077-combinations/0077-combinations.cpp similarity index 100% rename from 0077-combinations/0077-combinations.cpp rename to problems/0077-combinations/0077-combinations.cpp diff --git a/0077-combinations/0077-combinations.py b/problems/0077-combinations/0077-combinations.py similarity index 100% rename from 0077-combinations/0077-combinations.py rename to problems/0077-combinations/0077-combinations.py diff --git a/0077-combinations/NOTES.md b/problems/0077-combinations/NOTES.md similarity index 100% rename from 0077-combinations/NOTES.md rename to problems/0077-combinations/NOTES.md diff --git a/problems/0077-combinations/README.md b/problems/0077-combinations/README.md new file mode 100644 index 000000000..cc6d44a0c --- /dev/null +++ b/problems/0077-combinations/README.md @@ -0,0 +1,28 @@ +

77. Combinations

Medium


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.

+ +

 

+

Example 1:

+ +
Input: n = 4, k = 2
+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]]
+Explanation: There is 1 choose 1 = 1 total combination.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 20
  • +
  • 1 <= k <= n
  • +
+
\ No newline at end of file diff --git a/0078-subsets/0078-subsets.js b/problems/0078-subsets/0078-subsets.js similarity index 100% rename from 0078-subsets/0078-subsets.js rename to problems/0078-subsets/0078-subsets.js diff --git a/0078-subsets/0078-subsets.py b/problems/0078-subsets/0078-subsets.py similarity index 100% rename from 0078-subsets/0078-subsets.py rename to problems/0078-subsets/0078-subsets.py diff --git a/0078-subsets/NOTES.md b/problems/0078-subsets/NOTES.md similarity index 100% rename from 0078-subsets/NOTES.md rename to problems/0078-subsets/NOTES.md diff --git a/problems/0078-subsets/README.md b/problems/0078-subsets/README.md new file mode 100644 index 000000000..226b26bbf --- /dev/null +++ b/problems/0078-subsets/README.md @@ -0,0 +1,26 @@ +

78. Subsets

Medium


Given an integer array nums of unique elements, return all possible subsets (the power set).

+ +

The solution set must not contain duplicate subsets. Return the solution in any order.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3]
+Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
+
+ +

Example 2:

+ +
Input: nums = [0]
+Output: [[],[0]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 10
  • +
  • -10 <= nums[i] <= 10
  • +
  • All the numbers of nums are unique.
  • +
+
\ No newline at end of file diff --git a/0079-word-search/0079-word-search.py b/problems/0079-word-search/0079-word-search.py similarity index 100% rename from 0079-word-search/0079-word-search.py rename to problems/0079-word-search/0079-word-search.py diff --git a/0079-word-search/NOTES.md b/problems/0079-word-search/NOTES.md similarity index 100% rename from 0079-word-search/NOTES.md rename to problems/0079-word-search/NOTES.md diff --git a/problems/0079-word-search/README.md b/problems/0079-word-search/README.md new file mode 100644 index 000000000..1480ac27c --- /dev/null +++ b/problems/0079-word-search/README.md @@ -0,0 +1,37 @@ +

79. Word Search

Medium


Given an m x n grid of characters board and a string word, return true if word exists in the grid.

+ +

The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.

+ +

 

+

Example 1:

+ +
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
+Output: true
+
+ +

Example 2:

+ +
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
+Output: true
+
+ +

Example 3:

+ +
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • m == board.length
  • +
  • n = board[i].length
  • +
  • 1 <= m, n <= 6
  • +
  • 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 diff --git a/0081-search-in-rotated-sorted-array-ii/0081-search-in-rotated-sorted-array-ii.py b/problems/0081-search-in-rotated-sorted-array-ii/0081-search-in-rotated-sorted-array-ii.py similarity index 100% rename from 0081-search-in-rotated-sorted-array-ii/0081-search-in-rotated-sorted-array-ii.py rename to problems/0081-search-in-rotated-sorted-array-ii/0081-search-in-rotated-sorted-array-ii.py diff --git a/0081-search-in-rotated-sorted-array-ii/NOTES.md b/problems/0081-search-in-rotated-sorted-array-ii/NOTES.md similarity index 100% rename from 0081-search-in-rotated-sorted-array-ii/NOTES.md rename to problems/0081-search-in-rotated-sorted-array-ii/NOTES.md diff --git a/problems/0081-search-in-rotated-sorted-array-ii/README.md b/problems/0081-search-in-rotated-sorted-array-ii/README.md new file mode 100644 index 000000000..f0a17f29c --- /dev/null +++ b/problems/0081-search-in-rotated-sorted-array-ii/README.md @@ -0,0 +1,29 @@ +

81. Search in Rotated Sorted Array II

Medium


There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).

+ +

Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= 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,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].

+ +

Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.

+ +

You must decrease the overall operation steps as much as possible.

+ +

 

+

Example 1:

+
Input: nums = [2,5,6,0,0,1,2], target = 0
+Output: true
+

Example 2:

+
Input: nums = [2,5,6,0,0,1,2], target = 3
+Output: false
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5000
  • +
  • -104 <= nums[i] <= 104
  • +
  • nums is guaranteed to be rotated at some pivot.
  • +
  • -104 <= target <= 104
  • +
+ +

 

+

Follow up: This problem is similar to Search in Rotated Sorted Array, but nums may contain duplicates. Would this affect the runtime complexity? How and why?

+
\ No newline at end of file diff --git a/0083-remove-duplicates-from-sorted-list/0083-remove-duplicates-from-sorted-list.cpp b/problems/0083-remove-duplicates-from-sorted-list/0083-remove-duplicates-from-sorted-list.cpp similarity index 100% rename from 0083-remove-duplicates-from-sorted-list/0083-remove-duplicates-from-sorted-list.cpp rename to problems/0083-remove-duplicates-from-sorted-list/0083-remove-duplicates-from-sorted-list.cpp diff --git a/0083-remove-duplicates-from-sorted-list/NOTES.md b/problems/0083-remove-duplicates-from-sorted-list/NOTES.md similarity index 100% rename from 0083-remove-duplicates-from-sorted-list/NOTES.md rename to problems/0083-remove-duplicates-from-sorted-list/NOTES.md diff --git a/problems/0083-remove-duplicates-from-sorted-list/README.md b/problems/0083-remove-duplicates-from-sorted-list/README.md new file mode 100644 index 000000000..c6bfa5201 --- /dev/null +++ b/problems/0083-remove-duplicates-from-sorted-list/README.md @@ -0,0 +1,24 @@ +

83. Remove Duplicates from Sorted List

Easy


Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.

+ +

 

+

Example 1:

+ +
Input: head = [1,1,2]
+Output: [1,2]
+
+ +

Example 2:

+ +
Input: head = [1,1,2,3,3]
+Output: [1,2,3]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 300].
  • +
  • -100 <= Node.val <= 100
  • +
  • The list is guaranteed to be sorted in ascending order.
  • +
+
\ No newline at end of file diff --git a/0084-largest-rectangle-in-histogram/0084-largest-rectangle-in-histogram.py b/problems/0084-largest-rectangle-in-histogram/0084-largest-rectangle-in-histogram.py similarity index 100% rename from 0084-largest-rectangle-in-histogram/0084-largest-rectangle-in-histogram.py rename to problems/0084-largest-rectangle-in-histogram/0084-largest-rectangle-in-histogram.py diff --git a/0084-largest-rectangle-in-histogram/NOTES.md b/problems/0084-largest-rectangle-in-histogram/NOTES.md similarity index 100% rename from 0084-largest-rectangle-in-histogram/NOTES.md rename to problems/0084-largest-rectangle-in-histogram/NOTES.md diff --git a/problems/0084-largest-rectangle-in-histogram/README.md b/problems/0084-largest-rectangle-in-histogram/README.md new file mode 100644 index 000000000..8d5fb02f1 --- /dev/null +++ b/problems/0084-largest-rectangle-in-histogram/README.md @@ -0,0 +1,25 @@ +

84. Largest Rectangle in Histogram

Hard


Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.

+ +

 

+

Example 1:

+ +
Input: heights = [2,1,5,6,2,3]
+Output: 10
+Explanation: The above is a histogram where width of each bar is 1.
+The largest rectangle is shown in the red area, which has an area = 10 units.
+
+ +

Example 2:

+ +
Input: heights = [2,4]
+Output: 4
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= heights.length <= 105
  • +
  • 0 <= heights[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0085-maximal-rectangle/0085-maximal-rectangle.py b/problems/0085-maximal-rectangle/0085-maximal-rectangle.py similarity index 100% rename from 0085-maximal-rectangle/0085-maximal-rectangle.py rename to problems/0085-maximal-rectangle/0085-maximal-rectangle.py diff --git a/0085-maximal-rectangle/NOTES.md b/problems/0085-maximal-rectangle/NOTES.md similarity index 100% rename from 0085-maximal-rectangle/NOTES.md rename to problems/0085-maximal-rectangle/NOTES.md diff --git a/problems/0085-maximal-rectangle/README.md b/problems/0085-maximal-rectangle/README.md new file mode 100644 index 000000000..3dcfdf06d --- /dev/null +++ b/problems/0085-maximal-rectangle/README.md @@ -0,0 +1,32 @@ +

85. Maximal Rectangle

Hard


Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

+ +

 

+

Example 1:

+ +
Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
+Output: 6
+Explanation: The maximal rectangle is shown in the above picture.
+
+ +

Example 2:

+ +
Input: matrix = [["0"]]
+Output: 0
+
+ +

Example 3:

+ +
Input: matrix = [["1"]]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • rows == matrix.length
  • +
  • cols == matrix[i].length
  • +
  • 1 <= row, cols <= 200
  • +
  • matrix[i][j] is '0' or '1'.
  • +
+
\ No newline at end of file diff --git a/0086-partition-list/0086-partition-list.py b/problems/0086-partition-list/0086-partition-list.py similarity index 100% rename from 0086-partition-list/0086-partition-list.py rename to problems/0086-partition-list/0086-partition-list.py diff --git a/0086-partition-list/NOTES.md b/problems/0086-partition-list/NOTES.md similarity index 100% rename from 0086-partition-list/NOTES.md rename to problems/0086-partition-list/NOTES.md diff --git a/problems/0086-partition-list/README.md b/problems/0086-partition-list/README.md new file mode 100644 index 000000000..372a542c5 --- /dev/null +++ b/problems/0086-partition-list/README.md @@ -0,0 +1,26 @@ +

86. Partition List

Medium


Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

+ +

You should preserve the original relative order of the nodes in each of the two partitions.

+ +

 

+

Example 1:

+ +
Input: head = [1,4,3,2,5,2], x = 3
+Output: [1,2,2,4,3,5]
+
+ +

Example 2:

+ +
Input: head = [2,1], x = 2
+Output: [1,2]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 200].
  • +
  • -100 <= Node.val <= 100
  • +
  • -200 <= x <= 200
  • +
+
\ No newline at end of file diff --git a/0088-merge-sorted-array/0088-merge-sorted-array.cpp b/problems/0088-merge-sorted-array/0088-merge-sorted-array.cpp similarity index 100% rename from 0088-merge-sorted-array/0088-merge-sorted-array.cpp rename to problems/0088-merge-sorted-array/0088-merge-sorted-array.cpp diff --git a/0088-merge-sorted-array/NOTES.md b/problems/0088-merge-sorted-array/NOTES.md similarity index 100% rename from 0088-merge-sorted-array/NOTES.md rename to problems/0088-merge-sorted-array/NOTES.md diff --git a/problems/0088-merge-sorted-array/README.md b/problems/0088-merge-sorted-array/README.md new file mode 100644 index 000000000..edd52f0d6 --- /dev/null +++ b/problems/0088-merge-sorted-array/README.md @@ -0,0 +1,46 @@ +

88. Merge Sorted Array

Easy


You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.

+ +

Merge nums1 and nums2 into a single array sorted in non-decreasing order.

+ +

The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.

+ +

 

+

Example 1:

+ +
Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
+Output: [1,2,2,3,5,6]
+Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
+The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
+
+ +

Example 2:

+ +
Input: nums1 = [1], m = 1, nums2 = [], n = 0
+Output: [1]
+Explanation: The arrays we are merging are [1] and [].
+The result of the merge is [1].
+
+ +

Example 3:

+ +
Input: nums1 = [0], m = 0, nums2 = [1], n = 1
+Output: [1]
+Explanation: The arrays we are merging are [] and [1].
+The result of the merge is [1].
+Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.
+
+ +

 

+

Constraints:

+ +
    +
  • nums1.length == m + n
  • +
  • nums2.length == n
  • +
  • 0 <= m, n <= 200
  • +
  • 1 <= m + n <= 200
  • +
  • -109 <= nums1[i], nums2[j] <= 109
  • +
+ +

 

+

Follow up: Can you come up with an algorithm that runs in O(m + n) time?

+
\ No newline at end of file diff --git a/0090-subsets-ii/0090-subsets-ii.py b/problems/0090-subsets-ii/0090-subsets-ii.py similarity index 100% rename from 0090-subsets-ii/0090-subsets-ii.py rename to problems/0090-subsets-ii/0090-subsets-ii.py diff --git a/0090-subsets-ii/NOTES.md b/problems/0090-subsets-ii/NOTES.md similarity index 100% rename from 0090-subsets-ii/NOTES.md rename to problems/0090-subsets-ii/NOTES.md diff --git a/problems/0090-subsets-ii/README.md b/problems/0090-subsets-ii/README.md new file mode 100644 index 000000000..49bedbe04 --- /dev/null +++ b/problems/0090-subsets-ii/README.md @@ -0,0 +1,20 @@ +

90. Subsets II

Medium


Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

+ +

The solution set must not contain duplicate subsets. Return the solution in any order.

+ +

 

+

Example 1:

+
Input: nums = [1,2,2]
+Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
+

Example 2:

+
Input: nums = [0]
+Output: [[],[0]]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 10
  • +
  • -10 <= nums[i] <= 10
  • +
+
\ No newline at end of file diff --git a/0091-decode-ways/0091-decode-ways.py b/problems/0091-decode-ways/0091-decode-ways.py similarity index 100% rename from 0091-decode-ways/0091-decode-ways.py rename to problems/0091-decode-ways/0091-decode-ways.py diff --git a/0091-decode-ways/NOTES.md b/problems/0091-decode-ways/NOTES.md similarity index 100% rename from 0091-decode-ways/NOTES.md rename to problems/0091-decode-ways/NOTES.md diff --git a/problems/0091-decode-ways/README.md b/problems/0091-decode-ways/README.md new file mode 100644 index 000000000..84e177d9d --- /dev/null +++ b/problems/0091-decode-ways/README.md @@ -0,0 +1,51 @@ +

91. Decode Ways

Medium


A message containing letters from A-Z can be encoded into numbers using the following mapping:

+ +
'A' -> "1"
+'B' -> "2"
+...
+'Z' -> "26"
+
+ +

To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:

+ +
    +
  • "AAJF" with the grouping (1 1 10 6)
  • +
  • "KJF" with the grouping (11 10 6)
  • +
+ +

Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".

+ +

Given a string s containing only digits, return the number of ways to decode it.

+ +

The test cases are generated so that the answer fits in a 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: s = "12"
+Output: 2
+Explanation: "12" could be decoded as "AB" (1 2) or "L" (12).
+
+ +

Example 2:

+ +
Input: s = "226"
+Output: 3
+Explanation: "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
+
+ +

Example 3:

+ +
Input: s = "06"
+Output: 0
+Explanation: "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s contains only digits and may contain leading zero(s).
  • +
+
\ No newline at end of file diff --git a/0092-reverse-linked-list-ii/0092-reverse-linked-list-ii.py b/problems/0092-reverse-linked-list-ii/0092-reverse-linked-list-ii.py similarity index 100% rename from 0092-reverse-linked-list-ii/0092-reverse-linked-list-ii.py rename to problems/0092-reverse-linked-list-ii/0092-reverse-linked-list-ii.py diff --git a/0092-reverse-linked-list-ii/NOTES.md b/problems/0092-reverse-linked-list-ii/NOTES.md similarity index 100% rename from 0092-reverse-linked-list-ii/NOTES.md rename to problems/0092-reverse-linked-list-ii/NOTES.md diff --git a/problems/0092-reverse-linked-list-ii/README.md b/problems/0092-reverse-linked-list-ii/README.md new file mode 100644 index 000000000..8c76add52 --- /dev/null +++ b/problems/0092-reverse-linked-list-ii/README.md @@ -0,0 +1,27 @@ +

92. Reverse Linked List II

Medium


Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5], left = 2, right = 4
+Output: [1,4,3,2,5]
+
+ +

Example 2:

+ +
Input: head = [5], left = 1, right = 1
+Output: [5]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is n.
  • +
  • 1 <= n <= 500
  • +
  • -500 <= Node.val <= 500
  • +
  • 1 <= left <= right <= n
  • +
+ +

 

+Follow up: Could you do it in one pass?
\ No newline at end of file diff --git a/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp b/problems/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp similarity index 100% rename from 0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp rename to problems/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.cpp diff --git a/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.js b/problems/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.js similarity index 100% rename from 0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.js rename to problems/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.js diff --git a/0094-binary-tree-inorder-traversal/NOTES.md b/problems/0094-binary-tree-inorder-traversal/NOTES.md similarity index 100% rename from 0094-binary-tree-inorder-traversal/NOTES.md rename to problems/0094-binary-tree-inorder-traversal/NOTES.md diff --git a/problems/0094-binary-tree-inorder-traversal/README.md b/problems/0094-binary-tree-inorder-traversal/README.md new file mode 100644 index 000000000..ad2de4dc4 --- /dev/null +++ b/problems/0094-binary-tree-inorder-traversal/README.md @@ -0,0 +1,31 @@ +

94. Binary Tree Inorder Traversal

Easy


Given the root of a binary tree, return the inorder traversal of its nodes' values.

+ +

 

+

Example 1:

+ +
Input: root = [1,null,2,3]
+Output: [1,3,2]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

Example 3:

+ +
Input: root = [1]
+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 diff --git a/0095-unique-binary-search-trees-ii/0095-unique-binary-search-trees-ii.py b/problems/0095-unique-binary-search-trees-ii/0095-unique-binary-search-trees-ii.py similarity index 100% rename from 0095-unique-binary-search-trees-ii/0095-unique-binary-search-trees-ii.py rename to problems/0095-unique-binary-search-trees-ii/0095-unique-binary-search-trees-ii.py diff --git a/0095-unique-binary-search-trees-ii/NOTES.md b/problems/0095-unique-binary-search-trees-ii/NOTES.md similarity index 100% rename from 0095-unique-binary-search-trees-ii/NOTES.md rename to problems/0095-unique-binary-search-trees-ii/NOTES.md diff --git a/problems/0095-unique-binary-search-trees-ii/README.md b/problems/0095-unique-binary-search-trees-ii/README.md new file mode 100644 index 000000000..6aaca41a2 --- /dev/null +++ b/problems/0095-unique-binary-search-trees-ii/README.md @@ -0,0 +1,22 @@ +

95. Unique Binary Search Trees II

Medium


Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.

+ +

 

+

Example 1:

+ +
Input: n = 3
+Output: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]
+
+ +

Example 2:

+ +
Input: n = 1
+Output: [[1]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 8
  • +
+
\ No newline at end of file diff --git a/0097-interleaving-string/0097-interleaving-string.py b/problems/0097-interleaving-string/0097-interleaving-string.py similarity index 100% rename from 0097-interleaving-string/0097-interleaving-string.py rename to problems/0097-interleaving-string/0097-interleaving-string.py diff --git a/0097-interleaving-string/NOTES.md b/problems/0097-interleaving-string/NOTES.md similarity index 100% rename from 0097-interleaving-string/NOTES.md rename to problems/0097-interleaving-string/NOTES.md diff --git a/problems/0097-interleaving-string/README.md b/problems/0097-interleaving-string/README.md new file mode 100644 index 000000000..0d3ffd22e --- /dev/null +++ b/problems/0097-interleaving-string/README.md @@ -0,0 +1,49 @@ +

97. Interleaving String

Medium


Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.

+ +

An interleaving of two strings s and t is a configuration where s and t are divided into n and m substrings respectively, such that:

+ +
    +
  • s = s1 + s2 + ... + sn
  • +
  • t = t1 + t2 + ... + tm
  • +
  • |n - m| <= 1
  • +
  • The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...
  • +
+ +

Note: a + b is the concatenation of strings a and b.

+ +

 

+

Example 1:

+ +
Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
+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
+Explanation: Notice how it is impossible to interleave s2 with any other string to obtain s3.
+
+ +

Example 3:

+ +
Input: s1 = "", s2 = "", s3 = ""
+Output: true
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= s1.length, s2.length <= 100
  • +
  • 0 <= s3.length <= 200
  • +
  • s1, s2, and s3 consist of lowercase English letters.
  • +
+ +

 

+

Follow up: Could you solve it using only O(s2.length) additional memory space?

+
\ No newline at end of file diff --git a/0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp b/problems/0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp similarity index 100% rename from 0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp rename to problems/0098-validate-binary-search-tree/0098-validate-binary-search-tree.cpp diff --git a/0098-validate-binary-search-tree/0098-validate-binary-search-tree.py b/problems/0098-validate-binary-search-tree/0098-validate-binary-search-tree.py similarity index 100% rename from 0098-validate-binary-search-tree/0098-validate-binary-search-tree.py rename to problems/0098-validate-binary-search-tree/0098-validate-binary-search-tree.py diff --git a/0098-validate-binary-search-tree/NOTES.md b/problems/0098-validate-binary-search-tree/NOTES.md similarity index 100% rename from 0098-validate-binary-search-tree/NOTES.md rename to problems/0098-validate-binary-search-tree/NOTES.md diff --git a/problems/0098-validate-binary-search-tree/README.md b/problems/0098-validate-binary-search-tree/README.md new file mode 100644 index 000000000..a5ec6043b --- /dev/null +++ b/problems/0098-validate-binary-search-tree/README.md @@ -0,0 +1,32 @@ +

98. Validate Binary Search Tree

Medium


Given the root of a binary tree, determine if it is a valid binary search tree (BST).

+ +

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.
  • +
  • Both the left and right subtrees must also be binary search trees.
  • +
+ +

 

+

Example 1:

+ +
Input: root = [2,1,3]
+Output: true
+
+ +

Example 2:

+ +
Input: root = [5,1,4,null,null,3,6]
+Output: false
+Explanation: The root node's value is 5 but its right child's value is 4.
+
+ +

 

+

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 diff --git a/0100-same-tree/0100-same-tree.js b/problems/0100-same-tree/0100-same-tree.js similarity index 100% rename from 0100-same-tree/0100-same-tree.js rename to problems/0100-same-tree/0100-same-tree.js diff --git a/0100-same-tree/0100-same-tree.py b/problems/0100-same-tree/0100-same-tree.py similarity index 100% rename from 0100-same-tree/0100-same-tree.py rename to problems/0100-same-tree/0100-same-tree.py diff --git a/0100-same-tree/NOTES.md b/problems/0100-same-tree/NOTES.md similarity index 100% rename from 0100-same-tree/NOTES.md rename to problems/0100-same-tree/NOTES.md diff --git a/problems/0100-same-tree/README.md b/problems/0100-same-tree/README.md new file mode 100644 index 000000000..ac214aa88 --- /dev/null +++ b/problems/0100-same-tree/README.md @@ -0,0 +1,31 @@ +

100. Same Tree

Easy


Given the roots of two binary trees p and q, write a function to check if they are the same or not.

+ +

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

+ +

 

+

Example 1:

+ +
Input: p = [1,2,3], q = [1,2,3]
+Output: true
+
+ +

Example 2:

+ +
Input: p = [1,2], q = [1,null,2]
+Output: false
+
+ +

Example 3:

+ +
Input: p = [1,2,1], q = [1,1,2]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in both trees is in the range [0, 100].
  • +
  • -104 <= Node.val <= 104
  • +
+
\ No newline at end of file diff --git a/0101-symmetric-tree/0101-symmetric-tree.cpp b/problems/0101-symmetric-tree/0101-symmetric-tree.cpp similarity index 100% rename from 0101-symmetric-tree/0101-symmetric-tree.cpp rename to problems/0101-symmetric-tree/0101-symmetric-tree.cpp diff --git a/0101-symmetric-tree/NOTES.md b/problems/0101-symmetric-tree/NOTES.md similarity index 100% rename from 0101-symmetric-tree/NOTES.md rename to problems/0101-symmetric-tree/NOTES.md diff --git a/problems/0101-symmetric-tree/README.md b/problems/0101-symmetric-tree/README.md new file mode 100644 index 000000000..a4b74c2d8 --- /dev/null +++ b/problems/0101-symmetric-tree/README.md @@ -0,0 +1,25 @@ +

101. Symmetric Tree

Easy


Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

+ +

 

+

Example 1:

+ +
Input: root = [1,2,2,3,4,4,3]
+Output: true
+
+ +

Example 2:

+ +
Input: root = [1,2,2,null,3,null,3]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 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 diff --git a/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp b/problems/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp similarity index 100% rename from 0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp rename to problems/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.cpp diff --git a/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.py b/problems/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.py similarity index 100% rename from 0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.py rename to problems/0102-binary-tree-level-order-traversal/0102-binary-tree-level-order-traversal.py diff --git a/0102-binary-tree-level-order-traversal/NOTES.md b/problems/0102-binary-tree-level-order-traversal/NOTES.md similarity index 100% rename from 0102-binary-tree-level-order-traversal/NOTES.md rename to problems/0102-binary-tree-level-order-traversal/NOTES.md diff --git a/problems/0102-binary-tree-level-order-traversal/README.md b/problems/0102-binary-tree-level-order-traversal/README.md new file mode 100644 index 000000000..dc78860fc --- /dev/null +++ b/problems/0102-binary-tree-level-order-traversal/README.md @@ -0,0 +1,29 @@ +

102. Binary Tree Level Order Traversal

Medium


Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: [[3],[9,20],[15,7]]
+
+ +

Example 2:

+ +
Input: root = [1]
+Output: [[1]]
+
+ +

Example 3:

+ +
Input: root = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 2000].
  • +
  • -1000 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp b/problems/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp similarity index 100% rename from 0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp rename to problems/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.cpp diff --git a/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.js b/problems/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.js similarity index 100% rename from 0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.js rename to problems/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.js diff --git a/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.py b/problems/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.py similarity index 100% rename from 0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.py rename to problems/0104-maximum-depth-of-binary-tree/0104-maximum-depth-of-binary-tree.py diff --git a/0104-maximum-depth-of-binary-tree/NOTES.md b/problems/0104-maximum-depth-of-binary-tree/NOTES.md similarity index 100% rename from 0104-maximum-depth-of-binary-tree/NOTES.md rename to problems/0104-maximum-depth-of-binary-tree/NOTES.md diff --git a/problems/0104-maximum-depth-of-binary-tree/README.md b/problems/0104-maximum-depth-of-binary-tree/README.md new file mode 100644 index 000000000..e5aefdf7e --- /dev/null +++ b/problems/0104-maximum-depth-of-binary-tree/README.md @@ -0,0 +1,25 @@ +

104. Maximum Depth of Binary Tree

Easy


Given the root of a binary tree, return its maximum depth.

+ +

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: 3
+
+ +

Example 2:

+ +
Input: root = [1,null,2]
+Output: 2
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 104].
  • +
  • -100 <= Node.val <= 100
  • +
+
\ No newline at end of file diff --git a/0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.py b/problems/0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.py similarity index 100% rename from 0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.py rename to problems/0105-construct-binary-tree-from-preorder-and-inorder-traversal/0105-construct-binary-tree-from-preorder-and-inorder-traversal.py diff --git a/0105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md b/problems/0105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md similarity index 100% rename from 0105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md rename to problems/0105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md diff --git a/problems/0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md b/problems/0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md new file mode 100644 index 000000000..ad7d1dc29 --- /dev/null +++ b/problems/0105-construct-binary-tree-from-preorder-and-inorder-traversal/README.md @@ -0,0 +1,28 @@ +

105. Construct Binary Tree from Preorder and Inorder Traversal

Medium


Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.

+ +

 

+

Example 1:

+ +
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
+Output: [3,9,20,null,null,15,7]
+
+ +

Example 2:

+ +
Input: preorder = [-1], inorder = [-1]
+Output: [-1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= preorder.length <= 3000
  • +
  • inorder.length == preorder.length
  • +
  • -3000 <= preorder[i], inorder[i] <= 3000
  • +
  • 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 diff --git a/0110-balanced-binary-tree/0110-balanced-binary-tree.py b/problems/0110-balanced-binary-tree/0110-balanced-binary-tree.py similarity index 100% rename from 0110-balanced-binary-tree/0110-balanced-binary-tree.py rename to problems/0110-balanced-binary-tree/0110-balanced-binary-tree.py diff --git a/0110-balanced-binary-tree/NOTES.md b/problems/0110-balanced-binary-tree/NOTES.md similarity index 100% rename from 0110-balanced-binary-tree/NOTES.md rename to problems/0110-balanced-binary-tree/NOTES.md diff --git a/problems/0110-balanced-binary-tree/README.md b/problems/0110-balanced-binary-tree/README.md new file mode 100644 index 000000000..246a206e0 --- /dev/null +++ b/problems/0110-balanced-binary-tree/README.md @@ -0,0 +1,29 @@ +

110. Balanced Binary Tree

Easy


Given a binary tree, determine if it is height-balanced.

+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: true
+
+ +

Example 2:

+ +
Input: root = [1,2,2,3,3,null,null,4,4]
+Output: false
+
+ +

Example 3:

+ +
Input: root = []
+Output: true
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 5000].
  • +
  • -104 <= Node.val <= 104
  • +
+
\ No newline at end of file diff --git a/0112-path-sum/0112-path-sum.cpp b/problems/0112-path-sum/0112-path-sum.cpp similarity index 100% rename from 0112-path-sum/0112-path-sum.cpp rename to problems/0112-path-sum/0112-path-sum.cpp diff --git a/0112-path-sum/NOTES.md b/problems/0112-path-sum/NOTES.md similarity index 100% rename from 0112-path-sum/NOTES.md rename to problems/0112-path-sum/NOTES.md diff --git a/problems/0112-path-sum/README.md b/problems/0112-path-sum/README.md new file mode 100644 index 000000000..6939ed6b5 --- /dev/null +++ b/problems/0112-path-sum/README.md @@ -0,0 +1,38 @@ +

112. Path Sum

Easy


Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.

+ +

A leaf is a node with no children.

+ +

 

+

Example 1:

+ +
Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
+Output: true
+Explanation: The root-to-leaf path with the target sum is shown.
+
+ +

Example 2:

+ +
Input: root = [1,2,3], targetSum = 5
+Output: false
+Explanation: There 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 = [], targetSum = 0
+Output: false
+Explanation: Since the tree is empty, there are no root-to-leaf paths.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 5000].
  • +
  • -1000 <= Node.val <= 1000
  • +
  • -1000 <= targetSum <= 1000
  • +
+
\ No newline at end of file diff --git a/0116-populating-next-right-pointers-in-each-node/0116-populating-next-right-pointers-in-each-node.cpp b/problems/0116-populating-next-right-pointers-in-each-node/0116-populating-next-right-pointers-in-each-node.cpp similarity index 100% rename from 0116-populating-next-right-pointers-in-each-node/0116-populating-next-right-pointers-in-each-node.cpp rename to problems/0116-populating-next-right-pointers-in-each-node/0116-populating-next-right-pointers-in-each-node.cpp diff --git a/0116-populating-next-right-pointers-in-each-node/NOTES.md b/problems/0116-populating-next-right-pointers-in-each-node/NOTES.md similarity index 100% rename from 0116-populating-next-right-pointers-in-each-node/NOTES.md rename to problems/0116-populating-next-right-pointers-in-each-node/NOTES.md diff --git a/problems/0116-populating-next-right-pointers-in-each-node/README.md b/problems/0116-populating-next-right-pointers-in-each-node/README.md new file mode 100644 index 000000000..efc10d711 --- /dev/null +++ b/problems/0116-populating-next-right-pointers-in-each-node/README.md @@ -0,0 +1,44 @@ +

116. Populating Next Right Pointers in Each Node

Medium


You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

+ +
struct Node {
+  int val;
+  Node *left;
+  Node *right;
+  Node *next;
+}
+
+ +

Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

+ +

Initially, all next pointers are set to NULL.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,4,5,6,7]
+Output: [1,#,2,3,#,4,5,6,7,#]
+Explanation: Given the above perfect binary tree (Figure A), your function should populate each next pointer to point to its next right node, just like in Figure B. The serialized output is in level order as connected by the next pointers, with '#' signifying the end of each level.
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 212 - 1].
  • +
  • -1000 <= Node.val <= 1000
  • +
+ +

 

+

Follow-up:

+ +
    +
  • You may only use constant extra space.
  • +
  • The recursive approach is fine. You may assume implicit stack space does not count as extra space for this problem.
  • +
+
\ No newline at end of file diff --git a/0118-pascals-triangle/0118-pascals-triangle.cpp b/problems/0118-pascals-triangle/0118-pascals-triangle.cpp similarity index 100% rename from 0118-pascals-triangle/0118-pascals-triangle.cpp rename to problems/0118-pascals-triangle/0118-pascals-triangle.cpp diff --git a/0118-pascals-triangle/0118-pascals-triangle.py b/problems/0118-pascals-triangle/0118-pascals-triangle.py similarity index 100% rename from 0118-pascals-triangle/0118-pascals-triangle.py rename to problems/0118-pascals-triangle/0118-pascals-triangle.py diff --git a/0118-pascals-triangle/NOTES.md b/problems/0118-pascals-triangle/NOTES.md similarity index 100% rename from 0118-pascals-triangle/NOTES.md rename to problems/0118-pascals-triangle/NOTES.md diff --git a/problems/0118-pascals-triangle/README.md b/problems/0118-pascals-triangle/README.md new file mode 100644 index 000000000..38a795661 --- /dev/null +++ b/problems/0118-pascals-triangle/README.md @@ -0,0 +1,19 @@ +

118. Pascal's Triangle

Easy


Given an integer numRows, return the first numRows of Pascal's triangle.

+ +

In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

+ +

 

+

Example 1:

+
Input: numRows = 5
+Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
+

Example 2:

+
Input: numRows = 1
+Output: [[1]]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= numRows <= 30
  • +
+
\ No newline at end of file diff --git a/0119-pascals-triangle-ii/0119-pascals-triangle-ii.cpp b/problems/0119-pascals-triangle-ii/0119-pascals-triangle-ii.cpp similarity index 100% rename from 0119-pascals-triangle-ii/0119-pascals-triangle-ii.cpp rename to problems/0119-pascals-triangle-ii/0119-pascals-triangle-ii.cpp diff --git a/0119-pascals-triangle-ii/0119-pascals-triangle-ii.py b/problems/0119-pascals-triangle-ii/0119-pascals-triangle-ii.py similarity index 100% rename from 0119-pascals-triangle-ii/0119-pascals-triangle-ii.py rename to problems/0119-pascals-triangle-ii/0119-pascals-triangle-ii.py diff --git a/0119-pascals-triangle-ii/NOTES.md b/problems/0119-pascals-triangle-ii/NOTES.md similarity index 100% rename from 0119-pascals-triangle-ii/NOTES.md rename to problems/0119-pascals-triangle-ii/NOTES.md diff --git a/problems/0119-pascals-triangle-ii/README.md b/problems/0119-pascals-triangle-ii/README.md new file mode 100644 index 000000000..b5fb95680 --- /dev/null +++ b/problems/0119-pascals-triangle-ii/README.md @@ -0,0 +1,25 @@ +

119. Pascal's Triangle II

Easy


Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.

+ +

In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

+ +

 

+

Example 1:

+
Input: rowIndex = 3
+Output: [1,3,3,1]
+

Example 2:

+
Input: rowIndex = 0
+Output: [1]
+

Example 3:

+
Input: rowIndex = 1
+Output: [1,1]
+
+

 

+

Constraints:

+ +
    +
  • 0 <= rowIndex <= 33
  • +
+ +

 

+

Follow up: Could you optimize your algorithm to use only O(rowIndex) extra space?

+
\ No newline at end of file diff --git a/0120-triangle/0120-triangle.cpp b/problems/0120-triangle/0120-triangle.cpp similarity index 100% rename from 0120-triangle/0120-triangle.cpp rename to problems/0120-triangle/0120-triangle.cpp diff --git a/0120-triangle/NOTES.md b/problems/0120-triangle/NOTES.md similarity index 100% rename from 0120-triangle/NOTES.md rename to problems/0120-triangle/NOTES.md diff --git a/problems/0120-triangle/README.md b/problems/0120-triangle/README.md new file mode 100644 index 000000000..e35f27bc6 --- /dev/null +++ b/problems/0120-triangle/README.md @@ -0,0 +1,35 @@ +

120. Triangle

Medium


Given a triangle array, return the minimum path sum from top to bottom.

+ +

For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.

+ +

 

+

Example 1:

+ +
Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
+Output: 11
+Explanation: The triangle looks like:
+   2
+  3 4
+ 6 5 7
+4 1 8 3
+The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
+
+ +

Example 2:

+ +
Input: triangle = [[-10]]
+Output: -10
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= triangle.length <= 200
  • +
  • triangle[0].length == 1
  • +
  • triangle[i].length == triangle[i - 1].length + 1
  • +
  • -104 <= triangle[i][j] <= 104
  • +
+ +

 

+Follow up: Could you do this using only O(n) extra space, where n is the total number of rows in the triangle?
\ No newline at end of file diff --git a/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.cpp b/problems/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.cpp similarity index 100% rename from 0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.cpp rename to problems/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.cpp diff --git a/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.js b/problems/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.js similarity index 100% rename from 0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.js rename to problems/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.js diff --git a/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.py b/problems/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.py similarity index 100% rename from 0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.py rename to problems/0121-best-time-to-buy-and-sell-stock/0121-best-time-to-buy-and-sell-stock.py diff --git a/0121-best-time-to-buy-and-sell-stock/NOTES.md b/problems/0121-best-time-to-buy-and-sell-stock/NOTES.md similarity index 100% rename from 0121-best-time-to-buy-and-sell-stock/NOTES.md rename to problems/0121-best-time-to-buy-and-sell-stock/NOTES.md diff --git a/problems/0121-best-time-to-buy-and-sell-stock/README.md b/problems/0121-best-time-to-buy-and-sell-stock/README.md new file mode 100644 index 000000000..9453c7e09 --- /dev/null +++ b/problems/0121-best-time-to-buy-and-sell-stock/README.md @@ -0,0 +1,30 @@ +

121. Best Time to Buy and Sell Stock

Easy


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.

+ +

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

+ +

 

+

Example 1:

+ +
Input: prices = [7,1,5,3,6,4]
+Output: 5
+Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
+Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
+
+ +

Example 2:

+ +
Input: prices = [7,6,4,3,1]
+Output: 0
+Explanation: In this case, no transactions are done and the max profit = 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= prices.length <= 105
  • +
  • 0 <= prices[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0125-valid-palindrome/0125-valid-palindrome.py b/problems/0125-valid-palindrome/0125-valid-palindrome.py similarity index 100% rename from 0125-valid-palindrome/0125-valid-palindrome.py rename to problems/0125-valid-palindrome/0125-valid-palindrome.py diff --git a/0125-valid-palindrome/NOTES.md b/problems/0125-valid-palindrome/NOTES.md similarity index 100% rename from 0125-valid-palindrome/NOTES.md rename to problems/0125-valid-palindrome/NOTES.md diff --git a/problems/0125-valid-palindrome/README.md b/problems/0125-valid-palindrome/README.md new file mode 100644 index 000000000..b2217a0d3 --- /dev/null +++ b/problems/0125-valid-palindrome/README.md @@ -0,0 +1,35 @@ +

125. Valid Palindrome

Easy


A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.

+ +

Given a string s, return true if it is a palindrome, or false otherwise.

+ +

 

+

Example 1:

+ +
Input: s = "A man, a plan, a canal: Panama"
+Output: true
+Explanation: "amanaplanacanalpanama" is a palindrome.
+
+ +

Example 2:

+ +
Input: s = "race a car"
+Output: false
+Explanation: "raceacar" is not a palindrome.
+
+ +

Example 3:

+ +
Input: s = " "
+Output: true
+Explanation: s is an empty string "" after removing non-alphanumeric characters.
+Since an empty string reads the same forward and backward, it is a palindrome.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 2 * 105
  • +
  • s consists only of printable ASCII characters.
  • +
+
\ No newline at end of file diff --git a/0127-word-ladder/0127-word-ladder.py b/problems/0127-word-ladder/0127-word-ladder.py similarity index 100% rename from 0127-word-ladder/0127-word-ladder.py rename to problems/0127-word-ladder/0127-word-ladder.py diff --git a/0127-word-ladder/NOTES.md b/problems/0127-word-ladder/NOTES.md similarity index 100% rename from 0127-word-ladder/NOTES.md rename to problems/0127-word-ladder/NOTES.md diff --git a/problems/0127-word-ladder/README.md b/problems/0127-word-ladder/README.md new file mode 100644 index 000000000..5117a3fed --- /dev/null +++ b/problems/0127-word-ladder/README.md @@ -0,0 +1,38 @@ +

127. Word Ladder

Hard


A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:

+ +
    +
  • Every adjacent pair of words differs by a single letter.
  • +
  • Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.
  • +
  • sk == endWord
  • +
+ +

Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.

+ +

 

+

Example 1:

+ +
Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
+Output: 5
+Explanation: One shortest transformation sequence is "hit" -> "hot" -> "dot" -> "dog" -> cog", which is 5 words long.
+
+ +

Example 2:

+ +
Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
+Output: 0
+Explanation: The endWord "cog" is not in wordList, therefore there is no valid transformation sequence.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= beginWord.length <= 10
  • +
  • endWord.length == beginWord.length
  • +
  • 1 <= wordList.length <= 5000
  • +
  • wordList[i].length == beginWord.length
  • +
  • beginWord, endWord, and wordList[i] consist of lowercase English letters.
  • +
  • beginWord != endWord
  • +
  • All the words in wordList are unique.
  • +
+
\ No newline at end of file diff --git a/0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.py b/problems/0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.py similarity index 100% rename from 0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.py rename to problems/0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.py diff --git a/0128-longest-consecutive-sequence/NOTES.md b/problems/0128-longest-consecutive-sequence/NOTES.md similarity index 100% rename from 0128-longest-consecutive-sequence/NOTES.md rename to problems/0128-longest-consecutive-sequence/NOTES.md diff --git a/problems/0128-longest-consecutive-sequence/README.md b/problems/0128-longest-consecutive-sequence/README.md new file mode 100644 index 000000000..2938c99d7 --- /dev/null +++ b/problems/0128-longest-consecutive-sequence/README.md @@ -0,0 +1,26 @@ +

128. Longest Consecutive Sequence

Medium


Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

+ +

You must write an algorithm that runs in O(n) time.

+ +

 

+

Example 1:

+ +
Input: nums = [100,4,200,1,3,2]
+Output: 4
+Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
+
+ +

Example 2:

+ +
Input: nums = [0,3,7,2,5,8,4,6,0,1]
+Output: 9
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/0129-sum-root-to-leaf-numbers/0129-sum-root-to-leaf-numbers.py b/problems/0129-sum-root-to-leaf-numbers/0129-sum-root-to-leaf-numbers.py similarity index 100% rename from 0129-sum-root-to-leaf-numbers/0129-sum-root-to-leaf-numbers.py rename to problems/0129-sum-root-to-leaf-numbers/0129-sum-root-to-leaf-numbers.py diff --git a/0129-sum-root-to-leaf-numbers/NOTES.md b/problems/0129-sum-root-to-leaf-numbers/NOTES.md similarity index 100% rename from 0129-sum-root-to-leaf-numbers/NOTES.md rename to problems/0129-sum-root-to-leaf-numbers/NOTES.md diff --git a/problems/0129-sum-root-to-leaf-numbers/README.md b/problems/0129-sum-root-to-leaf-numbers/README.md new file mode 100644 index 000000000..abefe7fbe --- /dev/null +++ b/problems/0129-sum-root-to-leaf-numbers/README.md @@ -0,0 +1,43 @@ +

129. Sum Root to Leaf Numbers

Medium


You are given the root of a binary tree containing digits from 0 to 9 only.

+ +

Each root-to-leaf path in the tree represents a number.

+ +
    +
  • For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.
  • +
+ +

Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer.

+ +

A leaf node is a node with no children.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3]
+Output: 25
+Explanation:
+The root-to-leaf path 1->2 represents the number 12.
+The root-to-leaf path 1->3 represents the number 13.
+Therefore, sum = 12 + 13 = 25.
+
+ +

Example 2:

+ +
Input: root = [4,9,0,5,1]
+Output: 1026
+Explanation:
+The root-to-leaf path 4->9->5 represents the number 495.
+The root-to-leaf path 4->9->1 represents the number 491.
+The root-to-leaf path 4->0 represents the number 40.
+Therefore, sum = 495 + 491 + 40 = 1026.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 1000].
  • +
  • 0 <= Node.val <= 9
  • +
  • The depth of the tree will not exceed 10.
  • +
+
\ No newline at end of file diff --git a/0131-palindrome-partitioning/0131-palindrome-partitioning.py b/problems/0131-palindrome-partitioning/0131-palindrome-partitioning.py similarity index 100% rename from 0131-palindrome-partitioning/0131-palindrome-partitioning.py rename to problems/0131-palindrome-partitioning/0131-palindrome-partitioning.py diff --git a/0131-palindrome-partitioning/NOTES.md b/problems/0131-palindrome-partitioning/NOTES.md similarity index 100% rename from 0131-palindrome-partitioning/NOTES.md rename to problems/0131-palindrome-partitioning/NOTES.md diff --git a/problems/0131-palindrome-partitioning/README.md b/problems/0131-palindrome-partitioning/README.md new file mode 100644 index 000000000..934742248 --- /dev/null +++ b/problems/0131-palindrome-partitioning/README.md @@ -0,0 +1,18 @@ +

131. Palindrome Partitioning

Medium


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:

+
Input: s = "aab"
+Output: [["a","a","b"],["aa","b"]]
+

Example 2:

+
Input: s = "a"
+Output: [["a"]]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 16
  • +
  • s contains only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0133-clone-graph/0133-clone-graph.py b/problems/0133-clone-graph/0133-clone-graph.py similarity index 100% rename from 0133-clone-graph/0133-clone-graph.py rename to problems/0133-clone-graph/0133-clone-graph.py diff --git a/0133-clone-graph/NOTES.md b/problems/0133-clone-graph/NOTES.md similarity index 100% rename from 0133-clone-graph/NOTES.md rename to problems/0133-clone-graph/NOTES.md diff --git a/problems/0133-clone-graph/README.md b/problems/0133-clone-graph/README.md new file mode 100644 index 000000000..8bfc46895 --- /dev/null +++ b/problems/0133-clone-graph/README.md @@ -0,0 +1,59 @@ +

133. Clone Graph

Medium


Given a reference of a node in a connected undirected graph.

+ +

Return a deep copy (clone) of the graph.

+ +

Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors.

+ +
class Node {
+    public int val;
+    public List<Node> neighbors;
+}
+
+ +

 

+ +

Test case format:

+ +

For simplicity, each node's value is the same as the node's index (1-indexed). For example, the first node with val == 1, the second node with val == 2, and so on. The graph is represented in the test case using an adjacency list.

+ +

An adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.

+ +

The given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.

+ +

 

+

Example 1:

+ +
Input: adjList = [[2,4],[1,3],[2,4],[1,3]]
+Output: [[2,4],[1,3],[2,4],[1,3]]
+Explanation: There are 4 nodes in the graph.
+1st node (val = 1)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).
+2nd node (val = 2)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).
+3rd node (val = 3)'s neighbors are 2nd node (val = 2) and 4th node (val = 4).
+4th node (val = 4)'s neighbors are 1st node (val = 1) and 3rd node (val = 3).
+
+ +

Example 2:

+ +
Input: adjList = [[]]
+Output: [[]]
+Explanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors.
+
+ +

Example 3:

+ +
Input: adjList = []
+Output: []
+Explanation: This an empty graph, it does not have any nodes.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the graph is in the range [0, 100].
  • +
  • 1 <= Node.val <= 100
  • +
  • Node.val is unique for each node.
  • +
  • There are no repeated edges and no self-loops in the graph.
  • +
  • The Graph is connected and all nodes can be visited starting from the given node.
  • +
+
\ No newline at end of file diff --git a/0135-candy/0135-candy.py b/problems/0135-candy/0135-candy.py similarity index 100% rename from 0135-candy/0135-candy.py rename to problems/0135-candy/0135-candy.py diff --git a/0135-candy/NOTES.md b/problems/0135-candy/NOTES.md similarity index 100% rename from 0135-candy/NOTES.md rename to problems/0135-candy/NOTES.md diff --git a/problems/0135-candy/README.md b/problems/0135-candy/README.md new file mode 100644 index 000000000..4d83f6688 --- /dev/null +++ b/problems/0135-candy/README.md @@ -0,0 +1,36 @@ +

135. Candy

Hard


There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.

+ +

You are giving candies to these children subjected to the following requirements:

+ +
    +
  • Each child must have at least one candy.
  • +
  • Children with a higher rating get more candies than their neighbors.
  • +
+ +

Return the minimum number of candies you need to have to distribute the candies to the children.

+ +

 

+

Example 1:

+ +
Input: ratings = [1,0,2]
+Output: 5
+Explanation: You can allocate to the first, second and third child with 2, 1, 2 candies respectively.
+
+ +

Example 2:

+ +
Input: ratings = [1,2,2]
+Output: 4
+Explanation: You can allocate to the first, second and third child with 1, 2, 1 candies respectively.
+The third child gets 1 candy because it satisfies the above two conditions.
+
+ +

 

+

Constraints:

+ +
    +
  • n == ratings.length
  • +
  • 1 <= n <= 2 * 104
  • +
  • 0 <= ratings[i] <= 2 * 104
  • +
+
\ No newline at end of file diff --git a/0136-single-number/0136-single-number.cpp b/problems/0136-single-number/0136-single-number.cpp similarity index 100% rename from 0136-single-number/0136-single-number.cpp rename to problems/0136-single-number/0136-single-number.cpp diff --git a/0136-single-number/0136-single-number.py b/problems/0136-single-number/0136-single-number.py similarity index 100% rename from 0136-single-number/0136-single-number.py rename to problems/0136-single-number/0136-single-number.py diff --git a/0136-single-number/NOTES.md b/problems/0136-single-number/NOTES.md similarity index 100% rename from 0136-single-number/NOTES.md rename to problems/0136-single-number/NOTES.md diff --git a/problems/0136-single-number/README.md b/problems/0136-single-number/README.md new file mode 100644 index 000000000..48ccd04d2 --- /dev/null +++ b/problems/0136-single-number/README.md @@ -0,0 +1,24 @@ +

136. Single Number

Easy


Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

+ +

You must implement a solution with a linear runtime complexity and use only constant extra space.

+ +

 

+

Example 1:

+
Input: nums = [2,2,1]
+Output: 1
+

Example 2:

+
Input: nums = [4,1,2,1,2]
+Output: 4
+

Example 3:

+
Input: nums = [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 diff --git a/0137-single-number-ii/0137-single-number-ii.py b/problems/0137-single-number-ii/0137-single-number-ii.py similarity index 100% rename from 0137-single-number-ii/0137-single-number-ii.py rename to problems/0137-single-number-ii/0137-single-number-ii.py diff --git a/0137-single-number-ii/NOTES.md b/problems/0137-single-number-ii/NOTES.md similarity index 100% rename from 0137-single-number-ii/NOTES.md rename to problems/0137-single-number-ii/NOTES.md diff --git a/problems/0137-single-number-ii/README.md b/problems/0137-single-number-ii/README.md new file mode 100644 index 000000000..72a3e4fe5 --- /dev/null +++ b/problems/0137-single-number-ii/README.md @@ -0,0 +1,21 @@ +

137. Single Number II

Medium


Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.

+ +

You must implement a solution with a linear runtime complexity and use only constant extra space.

+ +

 

+

Example 1:

+
Input: nums = [2,2,3,2]
+Output: 3
+

Example 2:

+
Input: nums = [0,1,0,1,0,1,99]
+Output: 99
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • Each element in nums appears exactly three times except for one element which appears once.
  • +
+
\ No newline at end of file diff --git a/0138-copy-list-with-random-pointer/0138-copy-list-with-random-pointer.py b/problems/0138-copy-list-with-random-pointer/0138-copy-list-with-random-pointer.py similarity index 100% rename from 0138-copy-list-with-random-pointer/0138-copy-list-with-random-pointer.py rename to problems/0138-copy-list-with-random-pointer/0138-copy-list-with-random-pointer.py diff --git a/0138-copy-list-with-random-pointer/NOTES.md b/problems/0138-copy-list-with-random-pointer/NOTES.md similarity index 100% rename from 0138-copy-list-with-random-pointer/NOTES.md rename to problems/0138-copy-list-with-random-pointer/NOTES.md diff --git a/problems/0138-copy-list-with-random-pointer/README.md b/problems/0138-copy-list-with-random-pointer/README.md new file mode 100644 index 000000000..687b9dabd --- /dev/null +++ b/problems/0138-copy-list-with-random-pointer/README.md @@ -0,0 +1,47 @@ +

138. Copy List with Random Pointer

Medium


A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null.

+ +

Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. None of the pointers in the new list should point to nodes in the original list.

+ +

For example, if there are two nodes X and Y in the original list, where X.random --> Y, then for the corresponding two nodes x and y in the copied list, x.random --> y.

+ +

Return the head of the copied linked list.

+ +

The linked list is represented in the input/output as a list of n nodes. Each node is represented as a pair of [val, random_index] where:

+ +
    +
  • val: an integer representing Node.val
  • +
  • random_index: the index of the node (range from 0 to n-1) that the random pointer points to, or null if it does not point to any node.
  • +
+ +

Your code will only be given the head of the original linked list.

+ +

 

+

Example 1:

+ +
Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
+Output: [[7,null],[13,0],[11,4],[10,2],[1,0]]
+
+ +

Example 2:

+ +
Input: head = [[1,1],[2,1]]
+Output: [[1,1],[2,1]]
+
+ +

Example 3:

+ +

+ +
Input: head = [[3,null],[3,0],[3,null]]
+Output: [[3,null],[3,0],[3,null]]
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= n <= 1000
  • +
  • -104 <= Node.val <= 104
  • +
  • Node.random is null or is pointing to some node in the linked list.
  • +
+
\ No newline at end of file diff --git a/0139-word-break/0139-word-break.py b/problems/0139-word-break/0139-word-break.py similarity index 100% rename from 0139-word-break/0139-word-break.py rename to problems/0139-word-break/0139-word-break.py diff --git a/0139-word-break/NOTES.md b/problems/0139-word-break/NOTES.md similarity index 100% rename from 0139-word-break/NOTES.md rename to problems/0139-word-break/NOTES.md diff --git a/problems/0139-word-break/README.md b/problems/0139-word-break/README.md new file mode 100644 index 000000000..14dbb3f6e --- /dev/null +++ b/problems/0139-word-break/README.md @@ -0,0 +1,37 @@ +

139. Word Break

Medium


Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

+ +

Note that the same word in the dictionary may be reused multiple times in the segmentation.

+ +

 

+

Example 1:

+ +
Input: s = "leetcode", wordDict = ["leet","code"]
+Output: true
+Explanation: Return true because "leetcode" can be segmented as "leet code".
+
+ +

Example 2:

+ +
Input: s = "applepenapple", wordDict = ["apple","pen"]
+Output: true
+Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
+Note that you are allowed to reuse a dictionary word.
+
+ +

Example 3:

+ +
Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 300
  • +
  • 1 <= wordDict.length <= 1000
  • +
  • 1 <= wordDict[i].length <= 20
  • +
  • s and wordDict[i] consist of only lowercase English letters.
  • +
  • All the strings of wordDict are unique.
  • +
+
\ No newline at end of file diff --git a/0140-word-break-ii/0140-word-break-ii.py b/problems/0140-word-break-ii/0140-word-break-ii.py similarity index 100% rename from 0140-word-break-ii/0140-word-break-ii.py rename to problems/0140-word-break-ii/0140-word-break-ii.py diff --git a/0140-word-break-ii/NOTES.md b/problems/0140-word-break-ii/NOTES.md similarity index 100% rename from 0140-word-break-ii/NOTES.md rename to problems/0140-word-break-ii/NOTES.md diff --git a/problems/0140-word-break-ii/README.md b/problems/0140-word-break-ii/README.md new file mode 100644 index 000000000..0e8546870 --- /dev/null +++ b/problems/0140-word-break-ii/README.md @@ -0,0 +1,36 @@ +

140. Word Break II

Hard


Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order.

+ +

Note that the same word in the dictionary may be reused multiple times in the segmentation.

+ +

 

+

Example 1:

+ +
Input: s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"]
+Output: ["cats and dog","cat sand dog"]
+
+ +

Example 2:

+ +
Input: s = "pineapplepenapple", wordDict = ["apple","pen","applepen","pine","pineapple"]
+Output: ["pine apple pen apple","pineapple pen apple","pine applepen apple"]
+Explanation: Note that you are allowed to reuse a dictionary word.
+
+ +

Example 3:

+ +
Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 20
  • +
  • 1 <= wordDict.length <= 1000
  • +
  • 1 <= wordDict[i].length <= 10
  • +
  • s and wordDict[i] consist of only lowercase English letters.
  • +
  • All the strings of wordDict are unique.
  • +
  • Input is generated in a way that the length of the answer doesn't exceed 105.
  • +
+
\ No newline at end of file diff --git a/0141-linked-list-cycle/0141-linked-list-cycle.cpp b/problems/0141-linked-list-cycle/0141-linked-list-cycle.cpp similarity index 100% rename from 0141-linked-list-cycle/0141-linked-list-cycle.cpp rename to problems/0141-linked-list-cycle/0141-linked-list-cycle.cpp diff --git a/0141-linked-list-cycle/0141-linked-list-cycle.js b/problems/0141-linked-list-cycle/0141-linked-list-cycle.js similarity index 100% rename from 0141-linked-list-cycle/0141-linked-list-cycle.js rename to problems/0141-linked-list-cycle/0141-linked-list-cycle.js diff --git a/0141-linked-list-cycle/0141-linked-list-cycle.py b/problems/0141-linked-list-cycle/0141-linked-list-cycle.py similarity index 100% rename from 0141-linked-list-cycle/0141-linked-list-cycle.py rename to problems/0141-linked-list-cycle/0141-linked-list-cycle.py diff --git a/0141-linked-list-cycle/NOTES.md b/problems/0141-linked-list-cycle/NOTES.md similarity index 100% rename from 0141-linked-list-cycle/NOTES.md rename to problems/0141-linked-list-cycle/NOTES.md diff --git a/problems/0141-linked-list-cycle/README.md b/problems/0141-linked-list-cycle/README.md new file mode 100644 index 000000000..2621bdae2 --- /dev/null +++ b/problems/0141-linked-list-cycle/README.md @@ -0,0 +1,40 @@ +

141. Linked List Cycle

Easy


Given head, the head of a linked list, determine if the linked list has a cycle in it.

+ +

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.

+ +

Return true if there is a cycle in the linked list. Otherwise, return false.

+ +

 

+

Example 1:

+ +
Input: head = [3,2,0,-4], pos = 1
+Output: true
+Explanation: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed).
+
+ +

Example 2:

+ +
Input: head = [1,2], pos = 0
+Output: true
+Explanation: There is a cycle in the linked list, where the tail connects to the 0th node.
+
+ +

Example 3:

+ +
Input: head = [1], pos = -1
+Output: false
+Explanation: There is no cycle in the linked list.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of the nodes in the list is in the range [0, 104].
  • +
  • -105 <= Node.val <= 105
  • +
  • pos is -1 or a valid index in the linked-list.
  • +
+ +

 

+

Follow up: Can you solve it using O(1) (i.e. constant) memory?

+
\ No newline at end of file diff --git a/0143-reorder-list/0143-reorder-list.py b/problems/0143-reorder-list/0143-reorder-list.py similarity index 100% rename from 0143-reorder-list/0143-reorder-list.py rename to problems/0143-reorder-list/0143-reorder-list.py diff --git a/0143-reorder-list/NOTES.md b/problems/0143-reorder-list/NOTES.md similarity index 100% rename from 0143-reorder-list/NOTES.md rename to problems/0143-reorder-list/NOTES.md diff --git a/problems/0143-reorder-list/README.md b/problems/0143-reorder-list/README.md new file mode 100644 index 000000000..fa1bf802a --- /dev/null +++ b/problems/0143-reorder-list/README.md @@ -0,0 +1,33 @@ +

143. Reorder List

Medium


You are given the head of a singly linked-list. The list can be represented as:

+ +
L0 → L1 → … → Ln - 1 → Ln
+
+ +

Reorder the list to be on the following form:

+ +
L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …
+
+ +

You may not modify the values in the list's nodes. Only nodes themselves may be changed.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4]
+Output: [1,4,2,3]
+
+ +

Example 2:

+ +
Input: head = [1,2,3,4,5]
+Output: [1,5,2,4,3]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 5 * 104].
  • +
  • 1 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.cpp b/problems/0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.cpp similarity index 100% rename from 0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.cpp rename to problems/0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.cpp diff --git a/0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.js b/problems/0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.js similarity index 100% rename from 0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.js rename to problems/0144-binary-tree-preorder-traversal/0144-binary-tree-preorder-traversal.js diff --git a/0144-binary-tree-preorder-traversal/NOTES.md b/problems/0144-binary-tree-preorder-traversal/NOTES.md similarity index 100% rename from 0144-binary-tree-preorder-traversal/NOTES.md rename to problems/0144-binary-tree-preorder-traversal/NOTES.md diff --git a/problems/0144-binary-tree-preorder-traversal/README.md b/problems/0144-binary-tree-preorder-traversal/README.md new file mode 100644 index 000000000..320ded4b9 --- /dev/null +++ b/problems/0144-binary-tree-preorder-traversal/README.md @@ -0,0 +1,32 @@ +

144. Binary Tree Preorder Traversal

Easy


Given the root of a binary tree, return the preorder traversal of its nodes' values.

+ +

 

+

Example 1:

+ +
Input: root = [1,null,2,3]
+Output: [1,2,3]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

Example 3:

+ +
Input: root = [1]
+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 diff --git a/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp b/problems/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp similarity index 100% rename from 0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp rename to problems/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.cpp diff --git a/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.js b/problems/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.js similarity index 100% rename from 0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.js rename to problems/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.js diff --git a/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.py b/problems/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.py similarity index 100% rename from 0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.py rename to problems/0145-binary-tree-postorder-traversal/0145-binary-tree-postorder-traversal.py diff --git a/0145-binary-tree-postorder-traversal/NOTES.md b/problems/0145-binary-tree-postorder-traversal/NOTES.md similarity index 100% rename from 0145-binary-tree-postorder-traversal/NOTES.md rename to problems/0145-binary-tree-postorder-traversal/NOTES.md diff --git a/problems/0145-binary-tree-postorder-traversal/README.md b/problems/0145-binary-tree-postorder-traversal/README.md new file mode 100644 index 000000000..ed52ab888 --- /dev/null +++ b/problems/0145-binary-tree-postorder-traversal/README.md @@ -0,0 +1,31 @@ +

145. Binary Tree Postorder Traversal

Easy


Given the root of a binary tree, return the postorder traversal of its nodes' values.

+ +

 

+

Example 1:

+ +
Input: root = [1,null,2,3]
+Output: [3,2,1]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

Example 3:

+ +
Input: root = [1]
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of the 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 diff --git a/0146-lru-cache/0146-lru-cache.py b/problems/0146-lru-cache/0146-lru-cache.py similarity index 100% rename from 0146-lru-cache/0146-lru-cache.py rename to problems/0146-lru-cache/0146-lru-cache.py diff --git a/0146-lru-cache/NOTES.md b/problems/0146-lru-cache/NOTES.md similarity index 100% rename from 0146-lru-cache/NOTES.md rename to problems/0146-lru-cache/NOTES.md diff --git a/problems/0146-lru-cache/README.md b/problems/0146-lru-cache/README.md new file mode 100644 index 000000000..ae892bc08 --- /dev/null +++ b/problems/0146-lru-cache/README.md @@ -0,0 +1,44 @@ +

146. LRU Cache

Medium


Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

+ +

Implement the LRUCache class:

+ +
    +
  • LRUCache(int capacity) Initialize the LRU cache with positive size capacity.
  • +
  • int get(int key) Return the value of the key if the key exists, otherwise return -1.
  • +
  • void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.
  • +
+ +

The functions get and put must each run in O(1) average time complexity.

+ +

 

+

Example 1:

+ +
Input
+["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
+Output
+[null, null, null, 1, null, -1, null, -1, 3, 4]
+
+Explanation
+LRUCache lRUCache = new LRUCache(2);
+lRUCache.put(1, 1); // cache is {1=1}
+lRUCache.put(2, 2); // cache is {1=1, 2=2}
+lRUCache.get(1);    // return 1
+lRUCache.put(3, 3); // LRU key was 2, evicts key 2, cache is {1=1, 3=3}
+lRUCache.get(2);    // returns -1 (not found)
+lRUCache.put(4, 4); // LRU key was 1, evicts key 1, cache is {4=4, 3=3}
+lRUCache.get(1);    // return -1 (not found)
+lRUCache.get(3);    // return 3
+lRUCache.get(4);    // return 4
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= capacity <= 3000
  • +
  • 0 <= key <= 104
  • +
  • 0 <= value <= 105
  • +
  • At most 2 * 105 calls will be made to get and put.
  • +
+
\ No newline at end of file diff --git a/0148-sort-list/0148-sort-list.py b/problems/0148-sort-list/0148-sort-list.py similarity index 100% rename from 0148-sort-list/0148-sort-list.py rename to problems/0148-sort-list/0148-sort-list.py diff --git a/0148-sort-list/NOTES.md b/problems/0148-sort-list/NOTES.md similarity index 100% rename from 0148-sort-list/NOTES.md rename to problems/0148-sort-list/NOTES.md diff --git a/problems/0148-sort-list/README.md b/problems/0148-sort-list/README.md new file mode 100644 index 000000000..e56bc9c9f --- /dev/null +++ b/problems/0148-sort-list/README.md @@ -0,0 +1,32 @@ +

148. Sort List

Medium


Given the head of a linked list, return the list after sorting it in ascending order.

+ +

 

+

Example 1:

+ +
Input: head = [4,2,1,3]
+Output: [1,2,3,4]
+
+ +

Example 2:

+ +
Input: head = [-1,5,3,4,0]
+Output: [-1,0,3,4,5]
+
+ +

Example 3:

+ +
Input: head = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 5 * 104].
  • +
  • -105 <= Node.val <= 105
  • +
+ +

 

+

Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?

+
\ No newline at end of file diff --git a/0150-evaluate-reverse-polish-notation/0150-evaluate-reverse-polish-notation.py b/problems/0150-evaluate-reverse-polish-notation/0150-evaluate-reverse-polish-notation.py similarity index 100% rename from 0150-evaluate-reverse-polish-notation/0150-evaluate-reverse-polish-notation.py rename to problems/0150-evaluate-reverse-polish-notation/0150-evaluate-reverse-polish-notation.py diff --git a/0150-evaluate-reverse-polish-notation/NOTES.md b/problems/0150-evaluate-reverse-polish-notation/NOTES.md similarity index 100% rename from 0150-evaluate-reverse-polish-notation/NOTES.md rename to problems/0150-evaluate-reverse-polish-notation/NOTES.md diff --git a/problems/0150-evaluate-reverse-polish-notation/README.md b/problems/0150-evaluate-reverse-polish-notation/README.md new file mode 100644 index 000000000..4a26fcc43 --- /dev/null +++ b/problems/0150-evaluate-reverse-polish-notation/README.md @@ -0,0 +1,51 @@ +

150. Evaluate Reverse Polish Notation

Medium


You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.

+ +

Evaluate the expression. Return an integer that represents the value of the expression.

+ +

Note that:

+ +
    +
  • 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:

+ +
Input: tokens = ["2","1","+","3","*"]
+Output: 9
+Explanation: ((2 + 1) * 3) = 9
+
+ +

Example 2:

+ +
Input: tokens = ["4","13","5","/","+"]
+Output: 6
+Explanation: (4 + (13 / 5)) = 6
+
+ +

Example 3:

+ +
Input: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
+Output: 22
+Explanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
+= ((10 * (6 / (12 * -11))) + 17) + 5
+= ((10 * (6 / -132)) + 17) + 5
+= ((10 * 0) + 17) + 5
+= (0 + 17) + 5
+= 17 + 5
+= 22
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= tokens.length <= 104
  • +
  • tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].
  • +
+
\ No newline at end of file diff --git a/0153-find-minimum-in-rotated-sorted-array/0153-find-minimum-in-rotated-sorted-array.py b/problems/0153-find-minimum-in-rotated-sorted-array/0153-find-minimum-in-rotated-sorted-array.py similarity index 100% rename from 0153-find-minimum-in-rotated-sorted-array/0153-find-minimum-in-rotated-sorted-array.py rename to problems/0153-find-minimum-in-rotated-sorted-array/0153-find-minimum-in-rotated-sorted-array.py diff --git a/0153-find-minimum-in-rotated-sorted-array/NOTES.md b/problems/0153-find-minimum-in-rotated-sorted-array/NOTES.md similarity index 100% rename from 0153-find-minimum-in-rotated-sorted-array/NOTES.md rename to problems/0153-find-minimum-in-rotated-sorted-array/NOTES.md diff --git a/problems/0153-find-minimum-in-rotated-sorted-array/README.md b/problems/0153-find-minimum-in-rotated-sorted-array/README.md new file mode 100644 index 000000000..ddea742eb --- /dev/null +++ b/problems/0153-find-minimum-in-rotated-sorted-array/README.md @@ -0,0 +1,46 @@ +

153. Find Minimum in Rotated Sorted Array

Medium


Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:

+ +
    +
  • [4,5,6,7,0,1,2] if it was rotated 4 times.
  • +
  • [0,1,2,4,5,6,7] if it was rotated 7 times.
  • +
+ +

Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

+ +

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.

+ +

 

+

Example 1:

+ +
Input: nums = [3,4,5,1,2]
+Output: 1
+Explanation: The original array was [1,2,3,4,5] rotated 3 times.
+
+ +

Example 2:

+ +
Input: nums = [4,5,6,7,0,1,2]
+Output: 0
+Explanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.
+
+ +

Example 3:

+ +
Input: nums = [11,13,15,17]
+Output: 11
+Explanation: The original array was [11,13,15,17] and it was rotated 4 times. 
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 5000
  • +
  • -5000 <= nums[i] <= 5000
  • +
  • All the integers of nums are unique.
  • +
  • nums is sorted and rotated between 1 and n times.
  • +
+
\ No newline at end of file diff --git a/0155-min-stack/0155-min-stack.py b/problems/0155-min-stack/0155-min-stack.py similarity index 100% rename from 0155-min-stack/0155-min-stack.py rename to problems/0155-min-stack/0155-min-stack.py diff --git a/0155-min-stack/NOTES.md b/problems/0155-min-stack/NOTES.md similarity index 100% rename from 0155-min-stack/NOTES.md rename to problems/0155-min-stack/NOTES.md diff --git a/problems/0155-min-stack/README.md b/problems/0155-min-stack/README.md new file mode 100644 index 000000000..61b1b9a32 --- /dev/null +++ b/problems/0155-min-stack/README.md @@ -0,0 +1,44 @@ +

155. Min Stack

Medium


Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

+ +

Implement the MinStack class:

+ +
    +
  • MinStack() initializes the stack object.
  • +
  • void push(int val) pushes the element val onto the stack.
  • +
  • void pop() removes the element on the top of the stack.
  • +
  • int top() gets the top element of the stack.
  • +
  • int getMin() retrieves the minimum element in the stack.
  • +
+ +

You must implement a solution with O(1) time complexity for each function.

+ +

 

+

Example 1:

+ +
Input
+["MinStack","push","push","push","getMin","pop","top","getMin"]
+[[],[-2],[0],[-3],[],[],[],[]]
+
+Output
+[null,null,null,null,-3,null,0,-2]
+
+Explanation
+MinStack minStack = new MinStack();
+minStack.push(-2);
+minStack.push(0);
+minStack.push(-3);
+minStack.getMin(); // return -3
+minStack.pop();
+minStack.top();    // return 0
+minStack.getMin(); // return -2
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= val <= 231 - 1
  • +
  • Methods pop, top and getMin operations will always be called on non-empty stacks.
  • +
  • At most 3 * 104 calls will be made to push, pop, top, and getMin.
  • +
+
\ No newline at end of file diff --git a/0159-longest-substring-with-at-most-two-distinct-characters/0159-longest-substring-with-at-most-two-distinct-characters.py b/problems/0159-longest-substring-with-at-most-two-distinct-characters/0159-longest-substring-with-at-most-two-distinct-characters.py similarity index 100% rename from 0159-longest-substring-with-at-most-two-distinct-characters/0159-longest-substring-with-at-most-two-distinct-characters.py rename to problems/0159-longest-substring-with-at-most-two-distinct-characters/0159-longest-substring-with-at-most-two-distinct-characters.py diff --git a/0159-longest-substring-with-at-most-two-distinct-characters/NOTES.md b/problems/0159-longest-substring-with-at-most-two-distinct-characters/NOTES.md similarity index 100% rename from 0159-longest-substring-with-at-most-two-distinct-characters/NOTES.md rename to problems/0159-longest-substring-with-at-most-two-distinct-characters/NOTES.md diff --git a/problems/0159-longest-substring-with-at-most-two-distinct-characters/README.md b/problems/0159-longest-substring-with-at-most-two-distinct-characters/README.md new file mode 100644 index 000000000..ef8e8b741 --- /dev/null +++ b/problems/0159-longest-substring-with-at-most-two-distinct-characters/README.md @@ -0,0 +1,25 @@ +

159. Longest Substring with At Most Two Distinct Characters

Medium


Given a string s, return the length of the longest substring that contains at most two distinct characters.

+ +

 

+

Example 1:

+ +
Input: s = "eceba"
+Output: 3
+Explanation: The substring is "ece" which its length is 3.
+
+ +

Example 2:

+ +
Input: s = "ccaabbb"
+Output: 5
+Explanation: The substring is "aabbb" which its length is 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s consists of English letters.
  • +
+
\ No newline at end of file diff --git a/0162-find-peak-element/0162-find-peak-element.py b/problems/0162-find-peak-element/0162-find-peak-element.py similarity index 100% rename from 0162-find-peak-element/0162-find-peak-element.py rename to problems/0162-find-peak-element/0162-find-peak-element.py diff --git a/0162-find-peak-element/NOTES.md b/problems/0162-find-peak-element/NOTES.md similarity index 100% rename from 0162-find-peak-element/NOTES.md rename to problems/0162-find-peak-element/NOTES.md diff --git a/problems/0162-find-peak-element/README.md b/problems/0162-find-peak-element/README.md new file mode 100644 index 000000000..96c32bd28 --- /dev/null +++ b/problems/0162-find-peak-element/README.md @@ -0,0 +1,30 @@ +

162. Find Peak Element

Medium


A peak element is an element that is strictly greater than its neighbors.

+ +

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] = -∞. 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.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1]
+Output: 2
+Explanation: 3 is a peak element and your function should return the index number 2.
+ +

Example 2:

+ +
Input: nums = [1,2,1,3,5,6,4]
+Output: 5
+Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • nums[i] != nums[i + 1] for all valid i.
  • +
+
\ No newline at end of file diff --git a/0165-compare-version-numbers/0165-compare-version-numbers.py b/problems/0165-compare-version-numbers/0165-compare-version-numbers.py similarity index 100% rename from 0165-compare-version-numbers/0165-compare-version-numbers.py rename to problems/0165-compare-version-numbers/0165-compare-version-numbers.py diff --git a/0165-compare-version-numbers/NOTES.md b/problems/0165-compare-version-numbers/NOTES.md similarity index 100% rename from 0165-compare-version-numbers/NOTES.md rename to problems/0165-compare-version-numbers/NOTES.md diff --git a/0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.cpp b/problems/0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.cpp similarity index 100% rename from 0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.cpp rename to problems/0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.cpp diff --git a/0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.py b/problems/0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.py similarity index 100% rename from 0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.py rename to problems/0167-two-sum-ii-input-array-is-sorted/0167-two-sum-ii-input-array-is-sorted.py diff --git a/0167-two-sum-ii-input-array-is-sorted/NOTES.md b/problems/0167-two-sum-ii-input-array-is-sorted/NOTES.md similarity index 100% rename from 0167-two-sum-ii-input-array-is-sorted/NOTES.md rename to problems/0167-two-sum-ii-input-array-is-sorted/NOTES.md diff --git a/problems/0167-two-sum-ii-input-array-is-sorted/README.md b/problems/0167-two-sum-ii-input-array-is-sorted/README.md new file mode 100644 index 000000000..53383a197 --- /dev/null +++ b/problems/0167-two-sum-ii-input-array-is-sorted/README.md @@ -0,0 +1,41 @@ +

167. Two Sum II - Input Array Is Sorted

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.

+ +

Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2.

+ +

The tests are generated such that there is exactly one solution. You may not use the same element twice.

+ +

Your solution must use only constant extra space.

+ +

 

+

Example 1:

+ +
Input: numbers = [2,7,11,15], target = 9
+Output: [1,2]
+Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].
+
+ +

Example 2:

+ +
Input: numbers = [2,3,4], target = 6
+Output: [1,3]
+Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3].
+
+ +

Example 3:

+ +
Input: numbers = [-1,0], target = -1
+Output: [1,2]
+Explanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2].
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= numbers.length <= 3 * 104
  • +
  • -1000 <= numbers[i] <= 1000
  • +
  • numbers is sorted in non-decreasing order.
  • +
  • -1000 <= target <= 1000
  • +
  • The tests are generated such that there is exactly one solution.
  • +
+
\ No newline at end of file diff --git a/0168-excel-sheet-column-title/0168-excel-sheet-column-title.py b/problems/0168-excel-sheet-column-title/0168-excel-sheet-column-title.py similarity index 100% rename from 0168-excel-sheet-column-title/0168-excel-sheet-column-title.py rename to problems/0168-excel-sheet-column-title/0168-excel-sheet-column-title.py diff --git a/0168-excel-sheet-column-title/NOTES.md b/problems/0168-excel-sheet-column-title/NOTES.md similarity index 100% rename from 0168-excel-sheet-column-title/NOTES.md rename to problems/0168-excel-sheet-column-title/NOTES.md diff --git a/problems/0168-excel-sheet-column-title/README.md b/problems/0168-excel-sheet-column-title/README.md new file mode 100644 index 000000000..1f3e94ce1 --- /dev/null +++ b/problems/0168-excel-sheet-column-title/README.md @@ -0,0 +1,40 @@ +

168. Excel Sheet Column Title

Easy


Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.

+ +

For example:

+ +
A -> 1
+B -> 2
+C -> 3
+...
+Z -> 26
+AA -> 27
+AB -> 28 
+...
+
+ +

 

+

Example 1:

+ +
Input: columnNumber = 1
+Output: "A"
+
+ +

Example 2:

+ +
Input: columnNumber = 28
+Output: "AB"
+
+ +

Example 3:

+ +
Input: columnNumber = 701
+Output: "ZY"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= columnNumber <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0169-majority-element/0169-majority-element.cpp b/problems/0169-majority-element/0169-majority-element.cpp similarity index 100% rename from 0169-majority-element/0169-majority-element.cpp rename to problems/0169-majority-element/0169-majority-element.cpp diff --git a/0169-majority-element/0169-majority-element.py b/problems/0169-majority-element/0169-majority-element.py similarity index 100% rename from 0169-majority-element/0169-majority-element.py rename to problems/0169-majority-element/0169-majority-element.py diff --git a/0169-majority-element/NOTES.md b/problems/0169-majority-element/NOTES.md similarity index 100% rename from 0169-majority-element/NOTES.md rename to problems/0169-majority-element/NOTES.md diff --git a/problems/0169-majority-element/README.md b/problems/0169-majority-element/README.md new file mode 100644 index 000000000..0159f3e88 --- /dev/null +++ b/problems/0169-majority-element/README.md @@ -0,0 +1,23 @@ +

169. Majority Element

Easy


Given an array nums of size n, return the majority element.

+ +

The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.

+ +

 

+

Example 1:

+
Input: nums = [3,2,3]
+Output: 3
+

Example 2:

+
Input: nums = [2,2,1,1,1,2,2]
+Output: 2
+
+

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 5 * 104
  • +
  • -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/0189-rotate-array/0189-rotate-array.cpp b/problems/0189-rotate-array/0189-rotate-array.cpp similarity index 100% rename from 0189-rotate-array/0189-rotate-array.cpp rename to problems/0189-rotate-array/0189-rotate-array.cpp diff --git a/0189-rotate-array/NOTES.md b/problems/0189-rotate-array/NOTES.md similarity index 100% rename from 0189-rotate-array/NOTES.md rename to problems/0189-rotate-array/NOTES.md diff --git a/problems/0189-rotate-array/README.md b/problems/0189-rotate-array/README.md new file mode 100644 index 000000000..0f1538df6 --- /dev/null +++ b/problems/0189-rotate-array/README.md @@ -0,0 +1,39 @@ +

189. Rotate Array

Medium


Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4,5,6,7], k = 3
+Output: [5,6,7,1,2,3,4]
+Explanation:
+rotate 1 steps to the right: [7,1,2,3,4,5,6]
+rotate 2 steps to the right: [6,7,1,2,3,4,5]
+rotate 3 steps to the right: [5,6,7,1,2,3,4]
+
+ +

Example 2:

+ +
Input: nums = [-1,-100,3,99], k = 2
+Output: [3,99,-1,-100]
+Explanation: 
+rotate 1 steps to the right: [99,-1,-100,3]
+rotate 2 steps to the right: [3,99,-1,-100]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • 0 <= k <= 105
  • +
+ +

 

+

Follow up:

+ +
    +
  • Try to come up with as many solutions as you can. There are at least three different ways to solve this problem.
  • +
  • Could you do it in-place with O(1) extra space?
  • +
+
\ No newline at end of file diff --git a/0190-reverse-bits/0190-reverse-bits.cpp b/problems/0190-reverse-bits/0190-reverse-bits.cpp similarity index 100% rename from 0190-reverse-bits/0190-reverse-bits.cpp rename to problems/0190-reverse-bits/0190-reverse-bits.cpp diff --git a/0190-reverse-bits/NOTES.md b/problems/0190-reverse-bits/NOTES.md similarity index 100% rename from 0190-reverse-bits/NOTES.md rename to problems/0190-reverse-bits/NOTES.md diff --git a/problems/0190-reverse-bits/README.md b/problems/0190-reverse-bits/README.md new file mode 100644 index 000000000..4fd8ca434 --- /dev/null +++ b/problems/0190-reverse-bits/README.md @@ -0,0 +1,34 @@ +

190. Reverse Bits

Easy


Reverse bits of a given 32 bits unsigned integer.

+ +

Note:

+ +
    +
  • Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
  • +
  • In Java, the compiler represents the signed integers using 2's complement notation. Therefore, in Example 2 above, the input represents the signed integer -3 and the output represents the signed integer -1073741825.
  • +
+ +

 

+

Example 1:

+ +
Input: n = 00000010100101000001111010011100
+Output:    964176192 (00111001011110000010100101000000)
+Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
+
+ +

Example 2:

+ +
Input: n = 11111111111111111111111111111101
+Output:   3221225471 (10111111111111111111111111111111)
+Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.
+
+ +

 

+

Constraints:

+ +
    +
  • The input must be a binary string of length 32
  • +
+ +

 

+

Follow up: If this function is called many times, how would you optimize it?

+
\ No newline at end of file diff --git a/0191-number-of-1-bits/0191-number-of-1-bits.cpp b/problems/0191-number-of-1-bits/0191-number-of-1-bits.cpp similarity index 100% rename from 0191-number-of-1-bits/0191-number-of-1-bits.cpp rename to problems/0191-number-of-1-bits/0191-number-of-1-bits.cpp diff --git a/0191-number-of-1-bits/NOTES.md b/problems/0191-number-of-1-bits/NOTES.md similarity index 100% rename from 0191-number-of-1-bits/NOTES.md rename to problems/0191-number-of-1-bits/NOTES.md diff --git a/problems/0191-number-of-1-bits/README.md b/problems/0191-number-of-1-bits/README.md new file mode 100644 index 000000000..6fcc787b2 --- /dev/null +++ b/problems/0191-number-of-1-bits/README.md @@ -0,0 +1,40 @@ +

191. Number of 1 Bits

Easy


Write a function that takes the binary representation of an unsigned integer and returns the number of '1' bits it has (also known as the 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. Therefore, in Example 3, the input represents the signed integer. -3.
  • +
+ +

 

+

Example 1:

+ +
Input: n = 00000000000000000000000000001011
+Output: 3
+Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.
+
+ +

Example 2:

+ +
Input: n = 00000000000000000000000010000000
+Output: 1
+Explanation: The input binary string 00000000000000000000000010000000 has a total of one '1' bit.
+
+ +

Example 3:

+ +
Input: n = 11111111111111111111111111111101
+Output: 31
+Explanation: The input binary string 11111111111111111111111111111101 has a total of thirty one '1' bits.
+
+ +

 

+

Constraints:

+ +
    +
  • The input must be a binary string of length 32.
  • +
+ +

 

+Follow up: If this function is called many times, how would you optimize it?
\ No newline at end of file diff --git a/0197-rising-temperature/0197-rising-temperature.sql b/problems/0197-rising-temperature/0197-rising-temperature.sql similarity index 100% rename from 0197-rising-temperature/0197-rising-temperature.sql rename to problems/0197-rising-temperature/0197-rising-temperature.sql diff --git a/0197-rising-temperature/NOTES.md b/problems/0197-rising-temperature/NOTES.md similarity index 100% rename from 0197-rising-temperature/NOTES.md rename to problems/0197-rising-temperature/NOTES.md diff --git a/problems/0197-rising-temperature/README.md b/problems/0197-rising-temperature/README.md new file mode 100644 index 000000000..0a1bc83ad --- /dev/null +++ b/problems/0197-rising-temperature/README.md @@ -0,0 +1,46 @@ +

197. Rising Temperature

Easy


Table: Weather

+ +
+---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| id            | int     |
+| recordDate    | date    |
+| temperature   | int     |
++---------------+---------+
+id is the column with unique values for this table.
+This table contains information about the temperature on a certain day.
+
+ +

 

+ +

Write a solution to find all dates' Id with higher temperatures compared to its previous dates (yesterday).

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
Input: 
+Weather table:
++----+------------+-------------+
+| id | recordDate | temperature |
++----+------------+-------------+
+| 1  | 2015-01-01 | 10          |
+| 2  | 2015-01-02 | 25          |
+| 3  | 2015-01-03 | 20          |
+| 4  | 2015-01-04 | 30          |
++----+------------+-------------+
+Output: 
++----+
+| id |
++----+
+| 2  |
+| 4  |
++----+
+Explanation: 
+In 2015-01-02, the temperature was higher than the previous day (10 -> 25).
+In 2015-01-04, the temperature was higher than the previous day (20 -> 30).
+
+
\ No newline at end of file diff --git a/0198-house-robber/0198-house-robber.cpp b/problems/0198-house-robber/0198-house-robber.cpp similarity index 100% rename from 0198-house-robber/0198-house-robber.cpp rename to problems/0198-house-robber/0198-house-robber.cpp diff --git a/0198-house-robber/0198-house-robber.py b/problems/0198-house-robber/0198-house-robber.py similarity index 100% rename from 0198-house-robber/0198-house-robber.py rename to problems/0198-house-robber/0198-house-robber.py diff --git a/0198-house-robber/NOTES.md b/problems/0198-house-robber/NOTES.md similarity index 100% rename from 0198-house-robber/NOTES.md rename to problems/0198-house-robber/NOTES.md diff --git a/problems/0198-house-robber/README.md b/problems/0198-house-robber/README.md new file mode 100644 index 000000000..4784d722b --- /dev/null +++ b/problems/0198-house-robber/README.md @@ -0,0 +1,29 @@ +

198. House Robber

Medium


You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

+ +

Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1]
+Output: 4
+Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
+Total amount you can rob = 1 + 3 = 4.
+
+ +

Example 2:

+ +
Input: nums = [2,7,9,3,1]
+Output: 12
+Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
+Total amount you can rob = 2 + 9 + 1 = 12.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 400
  • +
+
\ No newline at end of file diff --git a/0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.py b/problems/0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.py similarity index 100% rename from 0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.py rename to problems/0199-binary-tree-right-side-view/0199-binary-tree-right-side-view.py diff --git a/0199-binary-tree-right-side-view/NOTES.md b/problems/0199-binary-tree-right-side-view/NOTES.md similarity index 100% rename from 0199-binary-tree-right-side-view/NOTES.md rename to problems/0199-binary-tree-right-side-view/NOTES.md diff --git a/0200-number-of-islands/0200-number-of-islands.py b/problems/0200-number-of-islands/0200-number-of-islands.py similarity index 100% rename from 0200-number-of-islands/0200-number-of-islands.py rename to problems/0200-number-of-islands/0200-number-of-islands.py diff --git a/0200-number-of-islands/NOTES.md b/problems/0200-number-of-islands/NOTES.md similarity index 100% rename from 0200-number-of-islands/NOTES.md rename to problems/0200-number-of-islands/NOTES.md diff --git a/problems/0200-number-of-islands/README.md b/problems/0200-number-of-islands/README.md new file mode 100644 index 000000000..f0398d0fc --- /dev/null +++ b/problems/0200-number-of-islands/README.md @@ -0,0 +1,37 @@ +

200. Number of Islands

Medium


Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.

+ +

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

+ +

 

+

Example 1:

+ +
Input: grid = [
+  ["1","1","1","1","0"],
+  ["1","1","0","1","0"],
+  ["1","1","0","0","0"],
+  ["0","0","0","0","0"]
+]
+Output: 1
+
+ +

Example 2:

+ +
Input: grid = [
+  ["1","1","0","0","0"],
+  ["1","1","0","0","0"],
+  ["0","0","1","0","0"],
+  ["0","0","0","1","1"]
+]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 300
  • +
  • grid[i][j] is '0' or '1'.
  • +
+
\ No newline at end of file diff --git a/0201-bitwise-and-of-numbers-range/0201-bitwise-and-of-numbers-range.py b/problems/0201-bitwise-and-of-numbers-range/0201-bitwise-and-of-numbers-range.py similarity index 100% rename from 0201-bitwise-and-of-numbers-range/0201-bitwise-and-of-numbers-range.py rename to problems/0201-bitwise-and-of-numbers-range/0201-bitwise-and-of-numbers-range.py diff --git a/0201-bitwise-and-of-numbers-range/NOTES.md b/problems/0201-bitwise-and-of-numbers-range/NOTES.md similarity index 100% rename from 0201-bitwise-and-of-numbers-range/NOTES.md rename to problems/0201-bitwise-and-of-numbers-range/NOTES.md diff --git a/problems/0201-bitwise-and-of-numbers-range/README.md b/problems/0201-bitwise-and-of-numbers-range/README.md new file mode 100644 index 000000000..5a34dffcb --- /dev/null +++ b/problems/0201-bitwise-and-of-numbers-range/README.md @@ -0,0 +1,28 @@ +

201. Bitwise AND of Numbers Range

Medium


Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.

+ +

 

+

Example 1:

+ +
Input: left = 5, right = 7
+Output: 4
+
+ +

Example 2:

+ +
Input: left = 0, right = 0
+Output: 0
+
+ +

Example 3:

+ +
Input: left = 1, right = 2147483647
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= left <= right <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0202-happy-number/0202-happy-number.py b/problems/0202-happy-number/0202-happy-number.py similarity index 100% rename from 0202-happy-number/0202-happy-number.py rename to problems/0202-happy-number/0202-happy-number.py diff --git a/0202-happy-number/NOTES.md b/problems/0202-happy-number/NOTES.md similarity index 100% rename from 0202-happy-number/NOTES.md rename to problems/0202-happy-number/NOTES.md diff --git a/problems/0202-happy-number/README.md b/problems/0202-happy-number/README.md new file mode 100644 index 000000000..ae7513484 --- /dev/null +++ b/problems/0202-happy-number/README.md @@ -0,0 +1,37 @@ +

202. Happy Number

Easy


Write an algorithm to determine if a number n is happy.

+ +

A happy number is a number defined by the following process:

+ +
    +
  • Starting with any positive integer, replace the number by the sum of the squares of its digits.
  • +
  • Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.
  • +
  • Those numbers for which this process ends in 1 are happy.
  • +
+ +

Return true if n is a happy number, and false if not.

+ +

 

+

Example 1:

+ +
Input: n = 19
+Output: true
+Explanation:
+12 + 92 = 82
+82 + 22 = 68
+62 + 82 = 100
+12 + 02 + 02 = 1
+
+ +

Example 2:

+ +
Input: n = 2
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0203-remove-linked-list-elements/0203-remove-linked-list-elements.cpp b/problems/0203-remove-linked-list-elements/0203-remove-linked-list-elements.cpp similarity index 100% rename from 0203-remove-linked-list-elements/0203-remove-linked-list-elements.cpp rename to problems/0203-remove-linked-list-elements/0203-remove-linked-list-elements.cpp diff --git a/0203-remove-linked-list-elements/NOTES.md b/problems/0203-remove-linked-list-elements/NOTES.md similarity index 100% rename from 0203-remove-linked-list-elements/NOTES.md rename to problems/0203-remove-linked-list-elements/NOTES.md diff --git a/problems/0203-remove-linked-list-elements/README.md b/problems/0203-remove-linked-list-elements/README.md new file mode 100644 index 000000000..eeb2fbd60 --- /dev/null +++ b/problems/0203-remove-linked-list-elements/README.md @@ -0,0 +1,30 @@ +

203. Remove Linked List Elements

Easy


Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,6,3,4,5,6], val = 6
+Output: [1,2,3,4,5]
+
+ +

Example 2:

+ +
Input: head = [], val = 1
+Output: []
+
+ +

Example 3:

+ +
Input: head = [7,7,7,7], val = 7
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 104].
  • +
  • 1 <= Node.val <= 50
  • +
  • 0 <= val <= 50
  • +
+
\ No newline at end of file diff --git a/0205-isomorphic-strings/0205-isomorphic-strings.py b/problems/0205-isomorphic-strings/0205-isomorphic-strings.py similarity index 100% rename from 0205-isomorphic-strings/0205-isomorphic-strings.py rename to problems/0205-isomorphic-strings/0205-isomorphic-strings.py diff --git a/0205-isomorphic-strings/NOTES.md b/problems/0205-isomorphic-strings/NOTES.md similarity index 100% rename from 0205-isomorphic-strings/NOTES.md rename to problems/0205-isomorphic-strings/NOTES.md diff --git a/problems/0205-isomorphic-strings/README.md b/problems/0205-isomorphic-strings/README.md new file mode 100644 index 000000000..c7d544ca5 --- /dev/null +++ b/problems/0205-isomorphic-strings/README.md @@ -0,0 +1,26 @@ +

205. Isomorphic Strings

Easy


Given two strings s and t, determine if they are isomorphic.

+ +

Two strings s and t are isomorphic if the characters in s can be replaced to get t.

+ +

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.

+ +

 

+

Example 1:

+
Input: s = "egg", t = "add"
+Output: true
+

Example 2:

+
Input: s = "foo", t = "bar"
+Output: false
+

Example 3:

+
Input: s = "paper", t = "title"
+Output: true
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 5 * 104
  • +
  • t.length == s.length
  • +
  • s and t consist of any valid ascii character.
  • +
+
\ No newline at end of file diff --git a/0206-reverse-linked-list/0206-reverse-linked-list.cpp b/problems/0206-reverse-linked-list/0206-reverse-linked-list.cpp similarity index 100% rename from 0206-reverse-linked-list/0206-reverse-linked-list.cpp rename to problems/0206-reverse-linked-list/0206-reverse-linked-list.cpp diff --git a/0206-reverse-linked-list/0206-reverse-linked-list.js b/problems/0206-reverse-linked-list/0206-reverse-linked-list.js similarity index 100% rename from 0206-reverse-linked-list/0206-reverse-linked-list.js rename to problems/0206-reverse-linked-list/0206-reverse-linked-list.js diff --git a/0206-reverse-linked-list/0206-reverse-linked-list.py b/problems/0206-reverse-linked-list/0206-reverse-linked-list.py similarity index 100% rename from 0206-reverse-linked-list/0206-reverse-linked-list.py rename to problems/0206-reverse-linked-list/0206-reverse-linked-list.py diff --git a/0206-reverse-linked-list/NOTES.md b/problems/0206-reverse-linked-list/NOTES.md similarity index 100% rename from 0206-reverse-linked-list/NOTES.md rename to problems/0206-reverse-linked-list/NOTES.md diff --git a/problems/0206-reverse-linked-list/README.md b/problems/0206-reverse-linked-list/README.md new file mode 100644 index 000000000..bb5408722 --- /dev/null +++ b/problems/0206-reverse-linked-list/README.md @@ -0,0 +1,32 @@ +

206. Reverse Linked List

Easy


Given the head of a singly linked list, reverse the list, and return the reversed list.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5]
+Output: [5,4,3,2,1]
+
+ +

Example 2:

+ +
Input: head = [1,2]
+Output: [2,1]
+
+ +

Example 3:

+ +
Input: head = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is the range [0, 5000].
  • +
  • -5000 <= Node.val <= 5000
  • +
+ +

 

+

Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?

+
\ No newline at end of file diff --git a/0207-course-schedule/0207-course-schedule.py b/problems/0207-course-schedule/0207-course-schedule.py similarity index 100% rename from 0207-course-schedule/0207-course-schedule.py rename to problems/0207-course-schedule/0207-course-schedule.py diff --git a/0207-course-schedule/NOTES.md b/problems/0207-course-schedule/NOTES.md similarity index 100% rename from 0207-course-schedule/NOTES.md rename to problems/0207-course-schedule/NOTES.md diff --git a/problems/0207-course-schedule/README.md b/problems/0207-course-schedule/README.md new file mode 100644 index 000000000..c9f7b97e2 --- /dev/null +++ b/problems/0207-course-schedule/README.md @@ -0,0 +1,36 @@ +

207. Course Schedule

Medium


There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

+ +
    +
  • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
  • +
+ +

Return true if you can finish all courses. Otherwise, return false.

+ +

 

+

Example 1:

+ +
Input: numCourses = 2, prerequisites = [[1,0]]
+Output: true
+Explanation: There are a total of 2 courses to take. 
+To take course 1 you should have finished course 0. So it is possible.
+
+ +

Example 2:

+ +
Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
+Output: false
+Explanation: There are a total of 2 courses to take. 
+To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= numCourses <= 2000
  • +
  • 0 <= prerequisites.length <= 5000
  • +
  • prerequisites[i].length == 2
  • +
  • 0 <= ai, bi < numCourses
  • +
  • All the pairs prerequisites[i] are unique.
  • +
+
\ No newline at end of file diff --git a/0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.py b/problems/0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.py similarity index 100% rename from 0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.py rename to problems/0208-implement-trie-prefix-tree/0208-implement-trie-prefix-tree.py diff --git a/0208-implement-trie-prefix-tree/NOTES.md b/problems/0208-implement-trie-prefix-tree/NOTES.md similarity index 100% rename from 0208-implement-trie-prefix-tree/NOTES.md rename to problems/0208-implement-trie-prefix-tree/NOTES.md diff --git a/problems/0208-implement-trie-prefix-tree/README.md b/problems/0208-implement-trie-prefix-tree/README.md new file mode 100644 index 000000000..4e589427c --- /dev/null +++ b/problems/0208-implement-trie-prefix-tree/README.md @@ -0,0 +1,39 @@ +

208. Implement Trie (Prefix Tree)

Medium


A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

+ +

Implement the Trie class:

+ +
    +
  • Trie() Initializes the trie object.
  • +
  • void insert(String word) Inserts the string word into the trie.
  • +
  • boolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.
  • +
  • boolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.
  • +
+ +

 

+

Example 1:

+ +
Input
+["Trie", "insert", "search", "search", "startsWith", "insert", "search"]
+[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]
+Output
+[null, null, true, false, true, null, true]
+
+Explanation
+Trie trie = new Trie();
+trie.insert("apple");
+trie.search("apple");   // return True
+trie.search("app");     // return False
+trie.startsWith("app"); // return True
+trie.insert("app");
+trie.search("app");     // return True
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word.length, prefix.length <= 2000
  • +
  • word and prefix consist only of lowercase English letters.
  • +
  • At most 3 * 104 calls in total will be made to insert, search, and startsWith.
  • +
+
\ No newline at end of file diff --git a/0213-house-robber-ii/0213-house-robber-ii.cpp b/problems/0213-house-robber-ii/0213-house-robber-ii.cpp similarity index 100% rename from 0213-house-robber-ii/0213-house-robber-ii.cpp rename to problems/0213-house-robber-ii/0213-house-robber-ii.cpp diff --git a/0213-house-robber-ii/NOTES.md b/problems/0213-house-robber-ii/NOTES.md similarity index 100% rename from 0213-house-robber-ii/NOTES.md rename to problems/0213-house-robber-ii/NOTES.md diff --git a/problems/0213-house-robber-ii/README.md b/problems/0213-house-robber-ii/README.md new file mode 100644 index 000000000..b41b70d35 --- /dev/null +++ b/problems/0213-house-robber-ii/README.md @@ -0,0 +1,34 @@ +

213. House Robber II

Medium


You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.

+ +

Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,2]
+Output: 3
+Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,1]
+Output: 4
+Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
+Total amount you can rob = 1 + 3 = 4.
+
+ +

Example 3:

+ +
Input: nums = [1,2,3]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/0215-kth-largest-element-in-an-array/0215-kth-largest-element-in-an-array.py b/problems/0215-kth-largest-element-in-an-array/0215-kth-largest-element-in-an-array.py similarity index 100% rename from 0215-kth-largest-element-in-an-array/0215-kth-largest-element-in-an-array.py rename to problems/0215-kth-largest-element-in-an-array/0215-kth-largest-element-in-an-array.py diff --git a/0215-kth-largest-element-in-an-array/NOTES.md b/problems/0215-kth-largest-element-in-an-array/NOTES.md similarity index 100% rename from 0215-kth-largest-element-in-an-array/NOTES.md rename to problems/0215-kth-largest-element-in-an-array/NOTES.md diff --git a/problems/0215-kth-largest-element-in-an-array/README.md b/problems/0215-kth-largest-element-in-an-array/README.md new file mode 100644 index 000000000..1735cc58c --- /dev/null +++ b/problems/0215-kth-largest-element-in-an-array/README.md @@ -0,0 +1,22 @@ +

215. Kth Largest Element in an Array

Medium


Given an integer array nums and an integer k, return the kth largest element in the array.

+ +

Note that it is the kth largest element in the sorted order, not the kth distinct element.

+ +

Can you solve it without sorting?

+ +

 

+

Example 1:

+
Input: nums = [3,2,1,5,6,4], k = 2
+Output: 5
+

Example 2:

+
Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
+Output: 4
+
+

 

+

Constraints:

+ +
    +
  • 1 <= k <= nums.length <= 105
  • +
  • -104 <= nums[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0217-contains-duplicate/0217-contains-duplicate.cpp b/problems/0217-contains-duplicate/0217-contains-duplicate.cpp similarity index 100% rename from 0217-contains-duplicate/0217-contains-duplicate.cpp rename to problems/0217-contains-duplicate/0217-contains-duplicate.cpp diff --git a/0217-contains-duplicate/0217-contains-duplicate.js b/problems/0217-contains-duplicate/0217-contains-duplicate.js similarity index 100% rename from 0217-contains-duplicate/0217-contains-duplicate.js rename to problems/0217-contains-duplicate/0217-contains-duplicate.js diff --git a/0217-contains-duplicate/0217-contains-duplicate.py b/problems/0217-contains-duplicate/0217-contains-duplicate.py similarity index 100% rename from 0217-contains-duplicate/0217-contains-duplicate.py rename to problems/0217-contains-duplicate/0217-contains-duplicate.py diff --git a/0217-contains-duplicate/NOTES.md b/problems/0217-contains-duplicate/NOTES.md similarity index 100% rename from 0217-contains-duplicate/NOTES.md rename to problems/0217-contains-duplicate/NOTES.md diff --git a/problems/0217-contains-duplicate/README.md b/problems/0217-contains-duplicate/README.md new file mode 100644 index 000000000..59c6818b3 --- /dev/null +++ b/problems/0217-contains-duplicate/README.md @@ -0,0 +1,21 @@ +

217. Contains Duplicate

Easy


Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

+ +

 

+

Example 1:

+
Input: nums = [1,2,3,1]
+Output: true
+

Example 2:

+
Input: nums = [1,2,3,4]
+Output: false
+

Example 3:

+
Input: nums = [1,1,1,3,3,4,3,2,4,2]
+Output: true
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/0219-contains-duplicate-ii/0219-contains-duplicate-ii.py b/problems/0219-contains-duplicate-ii/0219-contains-duplicate-ii.py similarity index 100% rename from 0219-contains-duplicate-ii/0219-contains-duplicate-ii.py rename to problems/0219-contains-duplicate-ii/0219-contains-duplicate-ii.py diff --git a/0219-contains-duplicate-ii/NOTES.md b/problems/0219-contains-duplicate-ii/NOTES.md similarity index 100% rename from 0219-contains-duplicate-ii/NOTES.md rename to problems/0219-contains-duplicate-ii/NOTES.md diff --git a/problems/0219-contains-duplicate-ii/README.md b/problems/0219-contains-duplicate-ii/README.md new file mode 100644 index 000000000..3429689bb --- /dev/null +++ b/problems/0219-contains-duplicate-ii/README.md @@ -0,0 +1,30 @@ +

219. Contains Duplicate II

Easy


Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1], k = 3
+Output: true
+
+ +

Example 2:

+ +
Input: nums = [1,0,1,1], k = 1
+Output: true
+
+ +

Example 3:

+ +
Input: nums = [1,2,3,1,2,3], k = 2
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
  • 0 <= k <= 105
  • +
+
\ No newline at end of file diff --git a/0224-basic-calculator/0224-basic-calculator.py b/problems/0224-basic-calculator/0224-basic-calculator.py similarity index 100% rename from 0224-basic-calculator/0224-basic-calculator.py rename to problems/0224-basic-calculator/0224-basic-calculator.py diff --git a/0224-basic-calculator/NOTES.md b/problems/0224-basic-calculator/NOTES.md similarity index 100% rename from 0224-basic-calculator/NOTES.md rename to problems/0224-basic-calculator/NOTES.md diff --git a/problems/0224-basic-calculator/README.md b/problems/0224-basic-calculator/README.md new file mode 100644 index 000000000..758c9ceed --- /dev/null +++ b/problems/0224-basic-calculator/README.md @@ -0,0 +1,36 @@ +

224. Basic Calculator

Hard


Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.

+ +

Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

+ +

 

+

Example 1:

+ +
Input: s = "1 + 1"
+Output: 2
+
+ +

Example 2:

+ +
Input: s = " 2-1 + 2 "
+Output: 3
+
+ +

Example 3:

+ +
Input: s = "(1+(4+5+2)-3)+(6+8)"
+Output: 23
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 3 * 105
  • +
  • s consists of digits, '+', '-', '(', ')', and ' '.
  • +
  • s represents a valid expression.
  • +
  • '+' is not used as a unary operation (i.e., "+1" and "+(2 + 3)" is invalid).
  • +
  • '-' could be used as a unary operation (i.e., "-1" and "-(2 + 3)" is valid).
  • +
  • There will be no two consecutive operators in the input.
  • +
  • Every number and running calculation will fit in a signed 32-bit integer.
  • +
+
\ No newline at end of file diff --git a/0225-implement-stack-using-queues/0225-implement-stack-using-queues.py b/problems/0225-implement-stack-using-queues/0225-implement-stack-using-queues.py similarity index 100% rename from 0225-implement-stack-using-queues/0225-implement-stack-using-queues.py rename to problems/0225-implement-stack-using-queues/0225-implement-stack-using-queues.py diff --git a/0225-implement-stack-using-queues/NOTES.md b/problems/0225-implement-stack-using-queues/NOTES.md similarity index 100% rename from 0225-implement-stack-using-queues/NOTES.md rename to problems/0225-implement-stack-using-queues/NOTES.md diff --git a/problems/0225-implement-stack-using-queues/README.md b/problems/0225-implement-stack-using-queues/README.md new file mode 100644 index 000000000..271ce4508 --- /dev/null +++ b/problems/0225-implement-stack-using-queues/README.md @@ -0,0 +1,48 @@ +

225. Implement Stack using Queues

Easy


Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty).

+ +

Implement the MyStack class:

+ +
    +
  • void push(int x) Pushes element x to the top of the stack.
  • +
  • int pop() Removes the element on the top of the stack and returns it.
  • +
  • int top() Returns the element on the top of the stack.
  • +
  • boolean empty() Returns true if the stack is empty, false otherwise.
  • +
+ +

Notes:

+ +
    +
  • You must use only standard operations of a queue, which means that only push to back, peek/pop from front, size and is empty operations are valid.
  • +
  • Depending on your language, the queue may not be supported natively. You may simulate a queue using a list or deque (double-ended queue) as long as you use only a queue's standard operations.
  • +
+ +

 

+

Example 1:

+ +
Input
+["MyStack", "push", "push", "top", "pop", "empty"]
+[[], [1], [2], [], [], []]
+Output
+[null, null, null, 2, 2, false]
+
+Explanation
+MyStack myStack = new MyStack();
+myStack.push(1);
+myStack.push(2);
+myStack.top(); // return 2
+myStack.pop(); // return 2
+myStack.empty(); // return False
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= x <= 9
  • +
  • At most 100 calls will be made to push, pop, top, and empty.
  • +
  • All the calls to pop and top are valid.
  • +
+ +

 

+

Follow-up: Can you implement the stack using only one queue?

+
\ No newline at end of file diff --git a/0226-invert-binary-tree/0226-invert-binary-tree.js b/problems/0226-invert-binary-tree/0226-invert-binary-tree.js similarity index 100% rename from 0226-invert-binary-tree/0226-invert-binary-tree.js rename to problems/0226-invert-binary-tree/0226-invert-binary-tree.js diff --git a/0226-invert-binary-tree/0226-invert-binary-tree.py b/problems/0226-invert-binary-tree/0226-invert-binary-tree.py similarity index 100% rename from 0226-invert-binary-tree/0226-invert-binary-tree.py rename to problems/0226-invert-binary-tree/0226-invert-binary-tree.py diff --git a/0226-invert-binary-tree/NOTES.md b/problems/0226-invert-binary-tree/NOTES.md similarity index 100% rename from 0226-invert-binary-tree/NOTES.md rename to problems/0226-invert-binary-tree/NOTES.md diff --git a/problems/0226-invert-binary-tree/README.md b/problems/0226-invert-binary-tree/README.md new file mode 100644 index 000000000..253f28a21 --- /dev/null +++ b/problems/0226-invert-binary-tree/README.md @@ -0,0 +1,29 @@ +

226. Invert Binary Tree

Easy


Given the root of a binary tree, invert the tree, and return its root.

+ +

 

+

Example 1:

+ +
Input: root = [4,2,7,1,3,6,9]
+Output: [4,7,2,9,6,3,1]
+
+ +

Example 2:

+ +
Input: root = [2,1,3]
+Output: [2,3,1]
+
+ +

Example 3:

+ +
Input: root = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 100].
  • +
  • -100 <= Node.val <= 100
  • +
+
\ No newline at end of file diff --git a/0229-majority-element-ii/0229-majority-element-ii.py b/problems/0229-majority-element-ii/0229-majority-element-ii.py similarity index 100% rename from 0229-majority-element-ii/0229-majority-element-ii.py rename to problems/0229-majority-element-ii/0229-majority-element-ii.py diff --git a/0229-majority-element-ii/NOTES.md b/problems/0229-majority-element-ii/NOTES.md similarity index 100% rename from 0229-majority-element-ii/NOTES.md rename to problems/0229-majority-element-ii/NOTES.md diff --git a/problems/0229-majority-element-ii/README.md b/problems/0229-majority-element-ii/README.md new file mode 100644 index 000000000..a3fbb6f98 --- /dev/null +++ b/problems/0229-majority-element-ii/README.md @@ -0,0 +1,32 @@ +

229. Majority Element II

Medium


Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

+ +

 

+

Example 1:

+ +
Input: nums = [3,2,3]
+Output: [3]
+
+ +

Example 2:

+ +
Input: nums = [1]
+Output: [1]
+
+ +

Example 3:

+ +
Input: nums = [1,2]
+Output: [1,2]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • -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/0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.py b/problems/0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.py similarity index 100% rename from 0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.py rename to problems/0230-kth-smallest-element-in-a-bst/0230-kth-smallest-element-in-a-bst.py diff --git a/0230-kth-smallest-element-in-a-bst/NOTES.md b/problems/0230-kth-smallest-element-in-a-bst/NOTES.md similarity index 100% rename from 0230-kth-smallest-element-in-a-bst/NOTES.md rename to problems/0230-kth-smallest-element-in-a-bst/NOTES.md diff --git a/problems/0230-kth-smallest-element-in-a-bst/README.md b/problems/0230-kth-smallest-element-in-a-bst/README.md new file mode 100644 index 000000000..ab773284c --- /dev/null +++ b/problems/0230-kth-smallest-element-in-a-bst/README.md @@ -0,0 +1,27 @@ +

230. Kth Smallest Element in a BST

Medium


Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.

+ +

 

+

Example 1:

+ +
Input: root = [3,1,4,null,2], k = 1
+Output: 1
+
+ +

Example 2:

+ +
Input: root = [5,3,6,2,4,null,null,1], k = 3
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is n.
  • +
  • 1 <= k <= n <= 104
  • +
  • 0 <= Node.val <= 104
  • +
+ +

 

+

Follow up: If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?

+
\ No newline at end of file diff --git a/0231-power-of-two/0231-power-of-two.cpp b/problems/0231-power-of-two/0231-power-of-two.cpp similarity index 100% rename from 0231-power-of-two/0231-power-of-two.cpp rename to problems/0231-power-of-two/0231-power-of-two.cpp diff --git a/0231-power-of-two/0231-power-of-two.py b/problems/0231-power-of-two/0231-power-of-two.py similarity index 100% rename from 0231-power-of-two/0231-power-of-two.py rename to problems/0231-power-of-two/0231-power-of-two.py diff --git a/0231-power-of-two/NOTES.md b/problems/0231-power-of-two/NOTES.md similarity index 100% rename from 0231-power-of-two/NOTES.md rename to problems/0231-power-of-two/NOTES.md diff --git a/problems/0231-power-of-two/README.md b/problems/0231-power-of-two/README.md new file mode 100644 index 000000000..b6b0cad94 --- /dev/null +++ b/problems/0231-power-of-two/README.md @@ -0,0 +1,34 @@ +

231. Power of Two

Easy


Given an integer n, return true if it is a power of two. Otherwise, return false.

+ +

An integer n is a power of two, if there exists an integer x such that n == 2x.

+ +

 

+

Example 1:

+ +
Input: n = 1
+Output: true
+Explanation: 20 = 1
+
+ +

Example 2:

+ +
Input: n = 16
+Output: true
+Explanation: 24 = 16
+
+ +

Example 3:

+ +
Input: n = 3
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= n <= 231 - 1
  • +
+ +

 

+Follow up: Could you solve it without loops/recursion?
\ No newline at end of file diff --git a/0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.cpp b/problems/0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.cpp similarity index 100% rename from 0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.cpp rename to problems/0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.cpp diff --git a/0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.py b/problems/0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.py similarity index 100% rename from 0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.py rename to problems/0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.py diff --git a/0232-implement-queue-using-stacks/NOTES.md b/problems/0232-implement-queue-using-stacks/NOTES.md similarity index 100% rename from 0232-implement-queue-using-stacks/NOTES.md rename to problems/0232-implement-queue-using-stacks/NOTES.md diff --git a/problems/0232-implement-queue-using-stacks/README.md b/problems/0232-implement-queue-using-stacks/README.md new file mode 100644 index 000000000..044efecc6 --- /dev/null +++ b/problems/0232-implement-queue-using-stacks/README.md @@ -0,0 +1,48 @@ +

232. Implement Queue using Stacks

Easy


Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).

+ +

Implement the MyQueue class:

+ +
    +
  • void push(int x) Pushes element x to the back of the queue.
  • +
  • int pop() Removes the element from the front of the queue and returns it.
  • +
  • int peek() Returns the element at the front of the queue.
  • +
  • boolean empty() Returns true if the queue is empty, false otherwise.
  • +
+ +

Notes:

+ +
    +
  • You must use only standard operations of a stack, which means only push to top, peek/pop from top, size, and is empty operations are valid.
  • +
  • Depending on your language, the stack may not be supported natively. You may simulate a stack using a list or deque (double-ended queue) as long as you use only a stack's standard operations.
  • +
+ +

 

+

Example 1:

+ +
Input
+["MyQueue", "push", "push", "peek", "pop", "empty"]
+[[], [1], [2], [], [], []]
+Output
+[null, null, null, 1, 1, false]
+
+Explanation
+MyQueue myQueue = new MyQueue();
+myQueue.push(1); // queue is: [1]
+myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
+myQueue.peek(); // return 1
+myQueue.pop(); // return 1, queue is [2]
+myQueue.empty(); // return false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= x <= 9
  • +
  • At most 100 calls will be made to push, pop, peek, and empty.
  • +
  • All the calls to pop and peek are valid.
  • +
+ +

 

+

Follow-up: Can you implement the queue such that each operation is amortized O(1) time complexity? In other words, performing n operations will take overall O(n) time even if one of those operations may take longer.

+
\ No newline at end of file diff --git a/0234-palindrome-linked-list/0234-palindrome-linked-list.py b/problems/0234-palindrome-linked-list/0234-palindrome-linked-list.py similarity index 100% rename from 0234-palindrome-linked-list/0234-palindrome-linked-list.py rename to problems/0234-palindrome-linked-list/0234-palindrome-linked-list.py diff --git a/0234-palindrome-linked-list/NOTES.md b/problems/0234-palindrome-linked-list/NOTES.md similarity index 100% rename from 0234-palindrome-linked-list/NOTES.md rename to problems/0234-palindrome-linked-list/NOTES.md diff --git a/problems/0234-palindrome-linked-list/README.md b/problems/0234-palindrome-linked-list/README.md new file mode 100644 index 000000000..d71facb12 --- /dev/null +++ b/problems/0234-palindrome-linked-list/README.md @@ -0,0 +1,25 @@ +

234. Palindrome Linked List

Easy


Given the head of a singly linked list, return true if it is a palindrome or false otherwise.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,2,1]
+Output: true
+
+ +

Example 2:

+ +
Input: head = [1,2]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 105].
  • +
  • 0 <= Node.val <= 9
  • +
+ +

 

+Follow up: Could you do it in O(n) time and O(1) space?
\ No newline at end of file diff --git a/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp b/problems/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp similarity index 100% rename from 0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp rename to problems/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.cpp diff --git a/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.py b/problems/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.py similarity index 100% rename from 0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.py rename to problems/0235-lowest-common-ancestor-of-a-binary-search-tree/0235-lowest-common-ancestor-of-a-binary-search-tree.py diff --git a/0235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md b/problems/0235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md similarity index 100% rename from 0235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md rename to problems/0235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md diff --git a/problems/0235-lowest-common-ancestor-of-a-binary-search-tree/README.md b/problems/0235-lowest-common-ancestor-of-a-binary-search-tree/README.md new file mode 100644 index 000000000..0640fe056 --- /dev/null +++ b/problems/0235-lowest-common-ancestor-of-a-binary-search-tree/README.md @@ -0,0 +1,36 @@ +

235. Lowest Common Ancestor of a Binary Search Tree

Medium


Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.

+ +

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

+ +

 

+

Example 1:

+ +
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
+Output: 6
+Explanation: The LCA of nodes 2 and 8 is 6.
+
+ +

Example 2:

+ +
Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
+Output: 2
+Explanation: The LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.
+
+ +

Example 3:

+ +
Input: root = [2,1], p = 2, q = 1
+Output: 2
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [2, 105].
  • +
  • -109 <= Node.val <= 109
  • +
  • All Node.val are unique.
  • +
  • p != q
  • +
  • p and q will exist in the BST.
  • +
+
\ No newline at end of file diff --git a/0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.py b/problems/0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.py similarity index 100% rename from 0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.py rename to problems/0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.py diff --git a/0236-lowest-common-ancestor-of-a-binary-tree/NOTES.md b/problems/0236-lowest-common-ancestor-of-a-binary-tree/NOTES.md similarity index 100% rename from 0236-lowest-common-ancestor-of-a-binary-tree/NOTES.md rename to problems/0236-lowest-common-ancestor-of-a-binary-tree/NOTES.md diff --git a/problems/0236-lowest-common-ancestor-of-a-binary-tree/README.md b/problems/0236-lowest-common-ancestor-of-a-binary-tree/README.md new file mode 100644 index 000000000..33fa84b0f --- /dev/null +++ b/problems/0236-lowest-common-ancestor-of-a-binary-tree/README.md @@ -0,0 +1,36 @@ +

236. Lowest Common Ancestor of a Binary Tree

Medium


Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.

+ +

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

+ +

 

+

Example 1:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
+Output: 3
+Explanation: The LCA of nodes 5 and 1 is 3.
+
+ +

Example 2:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
+Output: 5
+Explanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.
+
+ +

Example 3:

+ +
Input: root = [1,2], p = 1, q = 2
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [2, 105].
  • +
  • -109 <= Node.val <= 109
  • +
  • All Node.val are unique.
  • +
  • p != q
  • +
  • p and q will exist in the tree.
  • +
+
\ No newline at end of file diff --git a/0237-delete-node-in-a-linked-list/0237-delete-node-in-a-linked-list.py b/problems/0237-delete-node-in-a-linked-list/0237-delete-node-in-a-linked-list.py similarity index 100% rename from 0237-delete-node-in-a-linked-list/0237-delete-node-in-a-linked-list.py rename to problems/0237-delete-node-in-a-linked-list/0237-delete-node-in-a-linked-list.py diff --git a/0237-delete-node-in-a-linked-list/NOTES.md b/problems/0237-delete-node-in-a-linked-list/NOTES.md similarity index 100% rename from 0237-delete-node-in-a-linked-list/NOTES.md rename to problems/0237-delete-node-in-a-linked-list/NOTES.md diff --git a/problems/0237-delete-node-in-a-linked-list/README.md b/problems/0237-delete-node-in-a-linked-list/README.md new file mode 100644 index 000000000..3fc46f111 --- /dev/null +++ b/problems/0237-delete-node-in-a-linked-list/README.md @@ -0,0 +1,48 @@ +

237. Delete Node in a Linked List

Medium


There is a singly-linked list head and we want to delete a node node in it.

+ +

You are given the node to be deleted node. You will not be given access to the first node of head.

+ +

All the values of the linked list are unique, and it is guaranteed that the given node node is not the last node in the linked list.

+ +

Delete the given node. Note that by deleting the node, we do not mean removing it from memory. We mean:

+ +
    +
  • The value of the given node should not exist in the linked list.
  • +
  • The number of nodes in the linked list should decrease by one.
  • +
  • All the values before node should be in the same order.
  • +
  • All the values after node should be in the same order.
  • +
+ +

Custom testing:

+ +
    +
  • For the input, you should provide the entire linked list head and the node to be given node. node should not be the last node of the list and should be an actual node in the list.
  • +
  • We will build the linked list and pass the node to your function.
  • +
  • The output will be the entire list after calling your function.
  • +
+ +

 

+

Example 1:

+ +
Input: head = [4,5,1,9], node = 5
+Output: [4,1,9]
+Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
+
+ +

Example 2:

+ +
Input: head = [4,5,1,9], node = 1
+Output: [4,5,9]
+Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of the nodes in the given list is in the range [2, 1000].
  • +
  • -1000 <= Node.val <= 1000
  • +
  • The value of each node in the list is unique.
  • +
  • The node to be deleted is in the list and is not a tail node.
  • +
+
\ No newline at end of file diff --git a/0238-product-of-array-except-self/0238-product-of-array-except-self.py b/problems/0238-product-of-array-except-self/0238-product-of-array-except-self.py similarity index 100% rename from 0238-product-of-array-except-self/0238-product-of-array-except-self.py rename to problems/0238-product-of-array-except-self/0238-product-of-array-except-self.py diff --git a/0238-product-of-array-except-self/NOTES.md b/problems/0238-product-of-array-except-self/NOTES.md similarity index 100% rename from 0238-product-of-array-except-self/NOTES.md rename to problems/0238-product-of-array-except-self/NOTES.md diff --git a/problems/0238-product-of-array-except-self/README.md b/problems/0238-product-of-array-except-self/README.md new file mode 100644 index 000000000..8251a0f72 --- /dev/null +++ b/problems/0238-product-of-array-except-self/README.md @@ -0,0 +1,26 @@ +

238. Product of Array Except Self

Medium


Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

+ +

The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

+ +

You must write an algorithm that runs in O(n) time and without using the division operation.

+ +

 

+

Example 1:

+
Input: nums = [1,2,3,4]
+Output: [24,12,8,6]
+

Example 2:

+
Input: nums = [-1,1,0,-3,3]
+Output: [0,0,9,0,0]
+
+

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 105
  • +
  • -30 <= nums[i] <= 30
  • +
  • The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
  • +
+ +

 

+

Follow up: Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)

+
\ No newline at end of file diff --git a/0239-sliding-window-maximum/0239-sliding-window-maximum.py b/problems/0239-sliding-window-maximum/0239-sliding-window-maximum.py similarity index 100% rename from 0239-sliding-window-maximum/0239-sliding-window-maximum.py rename to problems/0239-sliding-window-maximum/0239-sliding-window-maximum.py diff --git a/0239-sliding-window-maximum/NOTES.md b/problems/0239-sliding-window-maximum/NOTES.md similarity index 100% rename from 0239-sliding-window-maximum/NOTES.md rename to problems/0239-sliding-window-maximum/NOTES.md diff --git a/problems/0239-sliding-window-maximum/README.md b/problems/0239-sliding-window-maximum/README.md new file mode 100644 index 000000000..e987f8953 --- /dev/null +++ b/problems/0239-sliding-window-maximum/README.md @@ -0,0 +1,35 @@ +

239. Sliding Window Maximum

Hard


You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

+ +

Return the max sliding window.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
+Output: [3,3,5,5,6,7]
+Explanation: 
+Window position                Max
+---------------               -----
+[1  3  -1] -3  5  3  6  7       3
+ 1 [3  -1  -3] 5  3  6  7       3
+ 1  3 [-1  -3  5] 3  6  7       5
+ 1  3  -1 [-3  5  3] 6  7       5
+ 1  3  -1  -3 [5  3  6] 7       6
+ 1  3  -1  -3  5 [3  6  7]      7
+
+ +

Example 2:

+ +
Input: nums = [1], k = 1
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -104 <= nums[i] <= 104
  • +
  • 1 <= k <= nums.length
  • +
+
\ No newline at end of file diff --git a/0242-valid-anagram/0242-valid-anagram.cpp b/problems/0242-valid-anagram/0242-valid-anagram.cpp similarity index 100% rename from 0242-valid-anagram/0242-valid-anagram.cpp rename to problems/0242-valid-anagram/0242-valid-anagram.cpp diff --git a/0242-valid-anagram/0242-valid-anagram.js b/problems/0242-valid-anagram/0242-valid-anagram.js similarity index 100% rename from 0242-valid-anagram/0242-valid-anagram.js rename to problems/0242-valid-anagram/0242-valid-anagram.js diff --git a/0242-valid-anagram/0242-valid-anagram.py b/problems/0242-valid-anagram/0242-valid-anagram.py similarity index 100% rename from 0242-valid-anagram/0242-valid-anagram.py rename to problems/0242-valid-anagram/0242-valid-anagram.py diff --git a/0242-valid-anagram/NOTES.md b/problems/0242-valid-anagram/NOTES.md similarity index 100% rename from 0242-valid-anagram/NOTES.md rename to problems/0242-valid-anagram/NOTES.md diff --git a/problems/0242-valid-anagram/README.md b/problems/0242-valid-anagram/README.md new file mode 100644 index 000000000..c06723c05 --- /dev/null +++ b/problems/0242-valid-anagram/README.md @@ -0,0 +1,23 @@ +

242. Valid Anagram

Easy


Given two strings s and t, return true if t is an anagram of s, and false otherwise.

+ +

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.

+ +

 

+

Example 1:

+
Input: s = "anagram", t = "nagaram"
+Output: true
+

Example 2:

+
Input: s = "rat", t = "car"
+Output: false
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length, t.length <= 5 * 104
  • +
  • s and t consist of lowercase English letters.
  • +
+ +

 

+

Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

+
\ No newline at end of file diff --git a/0253-meeting-rooms-ii/0253-meeting-rooms-ii.py b/problems/0253-meeting-rooms-ii/0253-meeting-rooms-ii.py similarity index 100% rename from 0253-meeting-rooms-ii/0253-meeting-rooms-ii.py rename to problems/0253-meeting-rooms-ii/0253-meeting-rooms-ii.py diff --git a/0253-meeting-rooms-ii/NOTES.md b/problems/0253-meeting-rooms-ii/NOTES.md similarity index 100% rename from 0253-meeting-rooms-ii/NOTES.md rename to problems/0253-meeting-rooms-ii/NOTES.md diff --git a/problems/0253-meeting-rooms-ii/README.md b/problems/0253-meeting-rooms-ii/README.md new file mode 100644 index 000000000..2e04a9171 --- /dev/null +++ b/problems/0253-meeting-rooms-ii/README.md @@ -0,0 +1,18 @@ +

253. Meeting Rooms II

Medium


Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

+ +

 

+

Example 1:

+
Input: intervals = [[0,30],[5,10],[15,20]]
+Output: 2
+

Example 2:

+
Input: intervals = [[7,10],[2,4]]
+Output: 1
+
+

 

+

Constraints:

+ +
    +
  • 1 <= intervals.length <= 104
  • +
  • 0 <= starti < endi <= 106
  • +
+
\ No newline at end of file diff --git a/0255-verify-preorder-sequence-in-binary-search-tree/0255-verify-preorder-sequence-in-binary-search-tree.py b/problems/0255-verify-preorder-sequence-in-binary-search-tree/0255-verify-preorder-sequence-in-binary-search-tree.py similarity index 100% rename from 0255-verify-preorder-sequence-in-binary-search-tree/0255-verify-preorder-sequence-in-binary-search-tree.py rename to problems/0255-verify-preorder-sequence-in-binary-search-tree/0255-verify-preorder-sequence-in-binary-search-tree.py diff --git a/0255-verify-preorder-sequence-in-binary-search-tree/NOTES.md b/problems/0255-verify-preorder-sequence-in-binary-search-tree/NOTES.md similarity index 100% rename from 0255-verify-preorder-sequence-in-binary-search-tree/NOTES.md rename to problems/0255-verify-preorder-sequence-in-binary-search-tree/NOTES.md diff --git a/problems/0255-verify-preorder-sequence-in-binary-search-tree/README.md b/problems/0255-verify-preorder-sequence-in-binary-search-tree/README.md new file mode 100644 index 000000000..a30403594 --- /dev/null +++ b/problems/0255-verify-preorder-sequence-in-binary-search-tree/README.md @@ -0,0 +1,27 @@ +

255. Verify Preorder Sequence in Binary Search Tree

Medium


Given an array of unique integers preorder, return true if it is the correct preorder traversal sequence of a binary search tree.

+ +

 

+

Example 1:

+ +
Input: preorder = [5,2,1,3,6]
+Output: true
+
+ +

Example 2:

+ +
Input: preorder = [5,2,6,1,3]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= preorder.length <= 104
  • +
  • 1 <= preorder[i] <= 104
  • +
  • All the elements of preorder are unique.
  • +
+ +

 

+

Follow up: Could you do it using only constant space complexity?

+
\ No newline at end of file diff --git a/0256-paint-house/0256-paint-house.py b/problems/0256-paint-house/0256-paint-house.py similarity index 100% rename from 0256-paint-house/0256-paint-house.py rename to problems/0256-paint-house/0256-paint-house.py diff --git a/0256-paint-house/NOTES.md b/problems/0256-paint-house/NOTES.md similarity index 100% rename from 0256-paint-house/NOTES.md rename to problems/0256-paint-house/NOTES.md diff --git a/problems/0256-paint-house/README.md b/problems/0256-paint-house/README.md new file mode 100644 index 000000000..d0589855a --- /dev/null +++ b/problems/0256-paint-house/README.md @@ -0,0 +1,35 @@ +

256. Paint House

Medium


There is a row of n houses, where each house can be painted one of three colors: red, blue, or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.

+ +

The cost of painting each house with a certain color is represented by an n x 3 cost matrix costs.

+ +
    +
  • For example, costs[0][0] is the cost of painting house 0 with the color red; costs[1][2] is the cost of painting house 1 with color green, and so on...
  • +
+ +

Return the minimum cost to paint all houses.

+ +

 

+

Example 1:

+ +
Input: costs = [[17,2,17],[16,16,5],[14,3,19]]
+Output: 10
+Explanation: Paint house 0 into blue, paint house 1 into green, paint house 2 into blue.
+Minimum cost: 2 + 5 + 3 = 10.
+
+ +

Example 2:

+ +
Input: costs = [[7,6,2]]
+Output: 2
+
+ +

 

+

Constraints:

+ +
    +
  • costs.length == n
  • +
  • costs[i].length == 3
  • +
  • 1 <= n <= 100
  • +
  • 1 <= costs[i][j] <= 20
  • +
+
\ No newline at end of file diff --git a/0260-single-number-iii/0260-single-number-iii.py b/problems/0260-single-number-iii/0260-single-number-iii.py similarity index 100% rename from 0260-single-number-iii/0260-single-number-iii.py rename to problems/0260-single-number-iii/0260-single-number-iii.py diff --git a/0260-single-number-iii/NOTES.md b/problems/0260-single-number-iii/NOTES.md similarity index 100% rename from 0260-single-number-iii/NOTES.md rename to problems/0260-single-number-iii/NOTES.md diff --git a/problems/0260-single-number-iii/README.md b/problems/0260-single-number-iii/README.md new file mode 100644 index 000000000..203cd5d78 --- /dev/null +++ b/problems/0260-single-number-iii/README.md @@ -0,0 +1,33 @@ +

260. Single Number III

Medium


Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.

+ +

You must write an algorithm that runs in linear runtime complexity and uses only constant extra space.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,1,3,2,5]
+Output: [3,5]
+Explanation:  [5, 3] is also a valid answer.
+
+ +

Example 2:

+ +
Input: nums = [-1,0]
+Output: [-1,0]
+
+ +

Example 3:

+ +
Input: nums = [0,1]
+Output: [1,0]
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 3 * 104
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • Each integer in nums will appear twice, only two integers will appear once.
  • +
+
\ No newline at end of file diff --git a/0263-ugly-number/0263-ugly-number.py b/problems/0263-ugly-number/0263-ugly-number.py similarity index 100% rename from 0263-ugly-number/0263-ugly-number.py rename to problems/0263-ugly-number/0263-ugly-number.py diff --git a/0263-ugly-number/NOTES.md b/problems/0263-ugly-number/NOTES.md similarity index 100% rename from 0263-ugly-number/NOTES.md rename to problems/0263-ugly-number/NOTES.md diff --git a/problems/0263-ugly-number/README.md b/problems/0263-ugly-number/README.md new file mode 100644 index 000000000..f394e9383 --- /dev/null +++ b/problems/0263-ugly-number/README.md @@ -0,0 +1,33 @@ +

263. Ugly Number

Easy


An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

+ +

Given an integer n, return true if n is an ugly number.

+ +

 

+

Example 1:

+ +
Input: n = 6
+Output: true
+Explanation: 6 = 2 × 3
+
+ +

Example 2:

+ +
Input: n = 1
+Output: true
+Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
+
+ +

Example 3:

+ +
Input: n = 14
+Output: false
+Explanation: 14 is not ugly since it includes the prime factor 7.
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= n <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0264-ugly-number-ii/0264-ugly-number-ii.py b/problems/0264-ugly-number-ii/0264-ugly-number-ii.py similarity index 100% rename from 0264-ugly-number-ii/0264-ugly-number-ii.py rename to problems/0264-ugly-number-ii/0264-ugly-number-ii.py diff --git a/0264-ugly-number-ii/NOTES.md b/problems/0264-ugly-number-ii/NOTES.md similarity index 100% rename from 0264-ugly-number-ii/NOTES.md rename to problems/0264-ugly-number-ii/NOTES.md diff --git a/problems/0264-ugly-number-ii/README.md b/problems/0264-ugly-number-ii/README.md new file mode 100644 index 000000000..296532e1b --- /dev/null +++ b/problems/0264-ugly-number-ii/README.md @@ -0,0 +1,26 @@ +

264. Ugly Number II

Medium


An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

+ +

Given an integer n, return the nth ugly number.

+ +

 

+

Example 1:

+ +
Input: n = 10
+Output: 12
+Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.
+
+ +

Example 2:

+ +
Input: n = 1
+Output: 1
+Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1690
  • +
+
\ No newline at end of file diff --git a/0268-missing-number/0268-missing-number.py b/problems/0268-missing-number/0268-missing-number.py similarity index 100% rename from 0268-missing-number/0268-missing-number.py rename to problems/0268-missing-number/0268-missing-number.py diff --git a/0268-missing-number/NOTES.md b/problems/0268-missing-number/NOTES.md similarity index 100% rename from 0268-missing-number/NOTES.md rename to problems/0268-missing-number/NOTES.md diff --git a/problems/0268-missing-number/README.md b/problems/0268-missing-number/README.md new file mode 100644 index 000000000..f88e56a1a --- /dev/null +++ b/problems/0268-missing-number/README.md @@ -0,0 +1,37 @@ +

268. Missing Number

Easy


Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

+ +

 

+

Example 1:

+ +
Input: nums = [3,0,1]
+Output: 2
+Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums.
+
+ +

Example 2:

+ +
Input: nums = [0,1]
+Output: 2
+Explanation: n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the missing number in the range since it does not appear in nums.
+
+ +

Example 3:

+ +
Input: nums = [9,6,4,2,3,5,7,0,1]
+Output: 8
+Explanation: n = 9 since there are 9 numbers, so all numbers are in the range [0,9]. 8 is the missing number in the range since it does not appear in nums.
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 104
  • +
  • 0 <= nums[i] <= n
  • +
  • All the numbers of nums are unique.
  • +
+ +

 

+

Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity?

+
\ No newline at end of file diff --git a/0271-encode-and-decode-strings/0271-encode-and-decode-strings.py b/problems/0271-encode-and-decode-strings/0271-encode-and-decode-strings.py similarity index 100% rename from 0271-encode-and-decode-strings/0271-encode-and-decode-strings.py rename to problems/0271-encode-and-decode-strings/0271-encode-and-decode-strings.py diff --git a/0271-encode-and-decode-strings/NOTES.md b/problems/0271-encode-and-decode-strings/NOTES.md similarity index 100% rename from 0271-encode-and-decode-strings/NOTES.md rename to problems/0271-encode-and-decode-strings/NOTES.md diff --git a/problems/0271-encode-and-decode-strings/README.md b/problems/0271-encode-and-decode-strings/README.md new file mode 100644 index 000000000..c38f8bbfa --- /dev/null +++ b/problems/0271-encode-and-decode-strings/README.md @@ -0,0 +1,66 @@ +

271. Encode and Decode Strings

Medium


Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.

+ +

Machine 1 (sender) has the function:

+ +
string encode(vector<string> strs) {
+  // ... your code
+  return encoded_string;
+}
+Machine 2 (receiver) has the function: + +
vector<string> decode(string s) {
+  //... your code
+  return strs;
+}
+
+ +

So Machine 1 does:

+ +
string encoded_string = encode(strs);
+
+ +

and Machine 2 does:

+ +
vector<string> strs2 = decode(encoded_string);
+
+ +

strs2 in Machine 2 should be the same as strs in Machine 1.

+ +

Implement the encode and decode methods.

+ +

You are not allowed to solve the problem using any serialize methods (such as eval).

+ +

 

+

Example 1:

+ +
Input: dummy_input = ["Hello","World"]
+Output: ["Hello","World"]
+Explanation:
+Machine 1:
+Codec encoder = new Codec();
+String msg = encoder.encode(strs);
+Machine 1 ---msg---> Machine 2
+
+Machine 2:
+Codec decoder = new Codec();
+String[] strs = decoder.decode(msg);
+
+ +

Example 2:

+ +
Input: dummy_input = [""]
+Output: [""]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= strs.length <= 200
  • +
  • 0 <= strs[i].length <= 200
  • +
  • strs[i] contains any possible characters out of 256 valid ASCII characters.
  • +
+ +

 

+

Follow up: Could you write a generalized algorithm to work on any possible set of characters?

+
\ No newline at end of file diff --git a/0273-integer-to-english-words/0273-integer-to-english-words.py b/problems/0273-integer-to-english-words/0273-integer-to-english-words.py similarity index 100% rename from 0273-integer-to-english-words/0273-integer-to-english-words.py rename to problems/0273-integer-to-english-words/0273-integer-to-english-words.py diff --git a/problems/0273-integer-to-english-words/README.md b/problems/0273-integer-to-english-words/README.md new file mode 100644 index 000000000..708515e3a --- /dev/null +++ b/problems/0273-integer-to-english-words/README.md @@ -0,0 +1,28 @@ +

273. Integer to English Words

Hard


Convert a non-negative integer num to its English words representation.

+ +

 

+

Example 1:

+ +
Input: num = 123
+Output: "One Hundred Twenty Three"
+
+ +

Example 2:

+ +
Input: num = 12345
+Output: "Twelve Thousand Three Hundred Forty Five"
+
+ +

Example 3:

+ +
Input: num = 1234567
+Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= num <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0276-paint-fence/0276-paint-fence.py b/problems/0276-paint-fence/0276-paint-fence.py similarity index 100% rename from 0276-paint-fence/0276-paint-fence.py rename to problems/0276-paint-fence/0276-paint-fence.py diff --git a/0276-paint-fence/NOTES.md b/problems/0276-paint-fence/NOTES.md similarity index 100% rename from 0276-paint-fence/NOTES.md rename to problems/0276-paint-fence/NOTES.md diff --git a/problems/0276-paint-fence/README.md b/problems/0276-paint-fence/README.md new file mode 100644 index 000000000..44ba632fc --- /dev/null +++ b/problems/0276-paint-fence/README.md @@ -0,0 +1,39 @@ +

276. Paint Fence

Medium


You are painting a fence of n posts with k different colors. You must paint the posts following these rules:

+ +
    +
  • Every post must be painted exactly one color.
  • +
  • There cannot be three or more consecutive posts with the same color.
  • +
+ +

Given the two integers n and k, return the number of ways you can paint the fence.

+ +

 

+

Example 1:

+ +
Input: n = 3, k = 2
+Output: 6
+Explanation: All the possibilities are shown.
+Note that painting all the posts red or all the posts green is invalid because there cannot be three posts in a row with the same color.
+
+ +

Example 2:

+ +
Input: n = 1, k = 1
+Output: 1
+
+ +

Example 3:

+ +
Input: n = 7, k = 2
+Output: 42
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 50
  • +
  • 1 <= k <= 105
  • +
  • The testcases are generated such that the answer is in the range [0, 231 - 1] for the given n and k.
  • +
+
\ No newline at end of file diff --git a/0278-first-bad-version/0278-first-bad-version.cpp b/problems/0278-first-bad-version/0278-first-bad-version.cpp similarity index 100% rename from 0278-first-bad-version/0278-first-bad-version.cpp rename to problems/0278-first-bad-version/0278-first-bad-version.cpp diff --git a/0278-first-bad-version/0278-first-bad-version.py b/problems/0278-first-bad-version/0278-first-bad-version.py similarity index 100% rename from 0278-first-bad-version/0278-first-bad-version.py rename to problems/0278-first-bad-version/0278-first-bad-version.py diff --git a/0278-first-bad-version/NOTES.md b/problems/0278-first-bad-version/NOTES.md similarity index 100% rename from 0278-first-bad-version/NOTES.md rename to problems/0278-first-bad-version/NOTES.md diff --git a/problems/0278-first-bad-version/README.md b/problems/0278-first-bad-version/README.md new file mode 100644 index 000000000..ee43afcb3 --- /dev/null +++ b/problems/0278-first-bad-version/README.md @@ -0,0 +1,31 @@ +

278. First Bad Version

Easy


You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.

+ +

Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.

+ +

You are given an API bool isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

+ +

 

+

Example 1:

+ +
Input: n = 5, bad = 4
+Output: 4
+Explanation:
+call isBadVersion(3) -> false
+call isBadVersion(5) -> true
+call isBadVersion(4) -> true
+Then 4 is the first bad version.
+
+ +

Example 2:

+ +
Input: n = 1, bad = 1
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= bad <= n <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0279-perfect-squares/0279-perfect-squares.py b/problems/0279-perfect-squares/0279-perfect-squares.py similarity index 100% rename from 0279-perfect-squares/0279-perfect-squares.py rename to problems/0279-perfect-squares/0279-perfect-squares.py diff --git a/0279-perfect-squares/NOTES.md b/problems/0279-perfect-squares/NOTES.md similarity index 100% rename from 0279-perfect-squares/NOTES.md rename to problems/0279-perfect-squares/NOTES.md diff --git a/problems/0279-perfect-squares/README.md b/problems/0279-perfect-squares/README.md new file mode 100644 index 000000000..cfd0d4337 --- /dev/null +++ b/problems/0279-perfect-squares/README.md @@ -0,0 +1,26 @@ +

279. Perfect Squares

Medium


Given an integer n, return the least number of perfect square numbers that sum to n.

+ +

A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.

+ +

 

+

Example 1:

+ +
Input: n = 12
+Output: 3
+Explanation: 12 = 4 + 4 + 4.
+
+ +

Example 2:

+ +
Input: n = 13
+Output: 2
+Explanation: 13 = 4 + 9.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 104
  • +
+
\ No newline at end of file diff --git a/0283-move-zeroes/0283-move-zeroes.cpp b/problems/0283-move-zeroes/0283-move-zeroes.cpp similarity index 100% rename from 0283-move-zeroes/0283-move-zeroes.cpp rename to problems/0283-move-zeroes/0283-move-zeroes.cpp diff --git a/0283-move-zeroes/NOTES.md b/problems/0283-move-zeroes/NOTES.md similarity index 100% rename from 0283-move-zeroes/NOTES.md rename to problems/0283-move-zeroes/NOTES.md diff --git a/problems/0283-move-zeroes/README.md b/problems/0283-move-zeroes/README.md new file mode 100644 index 000000000..4867dc0c6 --- /dev/null +++ b/problems/0283-move-zeroes/README.md @@ -0,0 +1,22 @@ +

283. Move Zeroes

Easy


Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.

+ +

Note that you must do this in-place without making a copy of the array.

+ +

 

+

Example 1:

+
Input: nums = [0,1,0,3,12]
+Output: [1,3,12,0,0]
+

Example 2:

+
Input: nums = [0]
+Output: [0]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 104
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
+ +

 

+Follow up: Could you minimize the total number of operations done?
\ No newline at end of file diff --git a/0287-find-the-duplicate-number/0287-find-the-duplicate-number.py b/problems/0287-find-the-duplicate-number/0287-find-the-duplicate-number.py similarity index 100% rename from 0287-find-the-duplicate-number/0287-find-the-duplicate-number.py rename to problems/0287-find-the-duplicate-number/0287-find-the-duplicate-number.py diff --git a/0287-find-the-duplicate-number/NOTES.md b/problems/0287-find-the-duplicate-number/NOTES.md similarity index 100% rename from 0287-find-the-duplicate-number/NOTES.md rename to problems/0287-find-the-duplicate-number/NOTES.md diff --git a/problems/0287-find-the-duplicate-number/README.md b/problems/0287-find-the-duplicate-number/README.md new file mode 100644 index 000000000..63bff0a6a --- /dev/null +++ b/problems/0287-find-the-duplicate-number/README.md @@ -0,0 +1,37 @@ +

287. Find the Duplicate Number

Medium


Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

+ +

There is only one repeated number in nums, return this repeated number.

+ +

You must solve the problem without modifying the array nums and uses only constant extra space.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3,4,2,2]
+Output: 2
+
+ +

Example 2:

+ +
Input: nums = [3,1,3,4,2]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 105
  • +
  • nums.length == n + 1
  • +
  • 1 <= nums[i] <= n
  • +
  • All the integers in nums appear only once except for precisely one integer which appears two or more times.
  • +
+ +

 

+

Follow up:

+ +
    +
  • How can we prove that at least one duplicate number must exist in nums?
  • +
  • Can you solve the problem in linear runtime complexity?
  • +
+
\ No newline at end of file diff --git a/0290-word-pattern/0290-word-pattern.py b/problems/0290-word-pattern/0290-word-pattern.py similarity index 100% rename from 0290-word-pattern/0290-word-pattern.py rename to problems/0290-word-pattern/0290-word-pattern.py diff --git a/0290-word-pattern/NOTES.md b/problems/0290-word-pattern/NOTES.md similarity index 100% rename from 0290-word-pattern/NOTES.md rename to problems/0290-word-pattern/NOTES.md diff --git a/problems/0290-word-pattern/README.md b/problems/0290-word-pattern/README.md new file mode 100644 index 000000000..1f095e4cb --- /dev/null +++ b/problems/0290-word-pattern/README.md @@ -0,0 +1,35 @@ +

290. Word Pattern

Easy


Given a pattern and a string s, find if s follows the same pattern.

+ +

Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s.

+ +

 

+

Example 1:

+ +
Input: pattern = "abba", s = "dog cat cat dog"
+Output: true
+
+ +

Example 2:

+ +
Input: pattern = "abba", s = "dog cat cat fish"
+Output: false
+
+ +

Example 3:

+ +
Input: pattern = "aaaa", s = "dog cat cat dog"
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= pattern.length <= 300
  • +
  • pattern contains only lower-case English letters.
  • +
  • 1 <= s.length <= 3000
  • +
  • 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/0291-word-pattern-ii/0291-word-pattern-ii.py b/problems/0291-word-pattern-ii/0291-word-pattern-ii.py similarity index 100% rename from 0291-word-pattern-ii/0291-word-pattern-ii.py rename to problems/0291-word-pattern-ii/0291-word-pattern-ii.py diff --git a/0291-word-pattern-ii/NOTES.md b/problems/0291-word-pattern-ii/NOTES.md similarity index 100% rename from 0291-word-pattern-ii/NOTES.md rename to problems/0291-word-pattern-ii/NOTES.md diff --git a/problems/0291-word-pattern-ii/README.md b/problems/0291-word-pattern-ii/README.md new file mode 100644 index 000000000..8789bc0df --- /dev/null +++ b/problems/0291-word-pattern-ii/README.md @@ -0,0 +1,35 @@ +

291. Word Pattern II

Medium


Given a pattern and a string s, return true if s matches the pattern.

+ +

A string s matches a pattern if there is some bijective mapping of single characters to non-empty strings such that if each character in pattern is replaced by the string it maps to, then the resulting string is s. A bijective mapping means that no two characters map to the same string, and no character maps to two different strings.

+ +

 

+

Example 1:

+ +
Input: pattern = "abab", s = "redblueredblue"
+Output: true
+Explanation: One possible mapping is as follows:
+'a' -> "red"
+'b' -> "blue"
+ +

Example 2:

+ +
Input: pattern = "aaaa", s = "asdasdasdasd"
+Output: true
+Explanation: One possible mapping is as follows:
+'a' -> "asd"
+
+ +

Example 3:

+ +
Input: pattern = "aabb", s = "xyzabcxzyabc"
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= pattern.length, s.length <= 20
  • +
  • pattern and s consist of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0293-flip-game/0293-flip-game.py b/problems/0293-flip-game/0293-flip-game.py similarity index 100% rename from 0293-flip-game/0293-flip-game.py rename to problems/0293-flip-game/0293-flip-game.py diff --git a/0293-flip-game/NOTES.md b/problems/0293-flip-game/NOTES.md similarity index 100% rename from 0293-flip-game/NOTES.md rename to problems/0293-flip-game/NOTES.md diff --git a/problems/0293-flip-game/README.md b/problems/0293-flip-game/README.md new file mode 100644 index 000000000..b55324905 --- /dev/null +++ b/problems/0293-flip-game/README.md @@ -0,0 +1,27 @@ +

293. Flip Game

Easy


You are playing a Flip Game with your friend.

+ +

You are given a string currentState that contains only '+' and '-'. You and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can no longer make a move, and therefore the other person will be the winner.

+ +

Return all possible states of the string currentState after one valid move. You may return the answer in any order. If there is no valid move, return an empty list [].

+ +

 

+

Example 1:

+ +
Input: currentState = "++++"
+Output: ["--++","+--+","++--"]
+
+ +

Example 2:

+ +
Input: currentState = "+"
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= currentState.length <= 500
  • +
  • currentState[i] is either '+' or '-'.
  • +
+
\ No newline at end of file diff --git a/0295-find-median-from-data-stream/0295-find-median-from-data-stream.py b/problems/0295-find-median-from-data-stream/0295-find-median-from-data-stream.py similarity index 100% rename from 0295-find-median-from-data-stream/0295-find-median-from-data-stream.py rename to problems/0295-find-median-from-data-stream/0295-find-median-from-data-stream.py diff --git a/0295-find-median-from-data-stream/NOTES.md b/problems/0295-find-median-from-data-stream/NOTES.md similarity index 100% rename from 0295-find-median-from-data-stream/NOTES.md rename to problems/0295-find-median-from-data-stream/NOTES.md diff --git a/problems/0295-find-median-from-data-stream/README.md b/problems/0295-find-median-from-data-stream/README.md new file mode 100644 index 000000000..40d107409 --- /dev/null +++ b/problems/0295-find-median-from-data-stream/README.md @@ -0,0 +1,50 @@ +

295. Find Median from Data Stream

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.

+ +
    +
  • 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.
  • +
+ +

Implement the MedianFinder class:

+ +
    +
  • MedianFinder() initializes the MedianFinder object.
  • +
  • void addNum(int num) adds the integer num from the data stream to the data structure.
  • +
  • double findMedian() returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted.
  • +
+ +

 

+

Example 1:

+ +
Input
+["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"]
+[[], [1], [2], [], [3], []]
+Output
+[null, null, null, 1.5, null, 2.0]
+
+Explanation
+MedianFinder medianFinder = new MedianFinder();
+medianFinder.addNum(1);    // arr = [1]
+medianFinder.addNum(2);    // arr = [1, 2]
+medianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2)
+medianFinder.addNum(3);    // arr[1, 2, 3]
+medianFinder.findMedian(); // return 2.0
+
+ +

 

+

Constraints:

+ +
    +
  • -105 <= num <= 105
  • +
  • There will be at least one element in the data structure before calling findMedian.
  • +
  • At most 5 * 104 calls will be made to addNum and findMedian.
  • +
+ +

 

+

Follow up:

+ +
    +
  • If all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?
  • +
  • If 99% of all integer numbers from the stream are in the range [0, 100], how would you optimize your solution?
  • +
+
\ No newline at end of file diff --git a/0296-best-meeting-point/0296-best-meeting-point.py b/problems/0296-best-meeting-point/0296-best-meeting-point.py similarity index 100% rename from 0296-best-meeting-point/0296-best-meeting-point.py rename to problems/0296-best-meeting-point/0296-best-meeting-point.py diff --git a/0296-best-meeting-point/NOTES.md b/problems/0296-best-meeting-point/NOTES.md similarity index 100% rename from 0296-best-meeting-point/NOTES.md rename to problems/0296-best-meeting-point/NOTES.md diff --git a/problems/0296-best-meeting-point/README.md b/problems/0296-best-meeting-point/README.md new file mode 100644 index 000000000..aa59726d8 --- /dev/null +++ b/problems/0296-best-meeting-point/README.md @@ -0,0 +1,33 @@ +

296. Best Meeting Point

Hard


Given an m x n binary grid grid where each 1 marks the home of one friend, return the minimal total travel distance.

+ +

The total travel distance is the sum of the distances between the houses of the friends and the meeting point.

+ +

The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

+ +

 

+

Example 1:

+ +
Input: grid = [[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0]]
+Output: 6
+Explanation: Given three friends living at (0,0), (0,4), and (2,2).
+The point (0,2) is an ideal meeting point, as the total travel distance of 2 + 2 + 2 = 6 is minimal.
+So return 6.
+
+ +

Example 2:

+ +
Input: grid = [[1,1]]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 200
  • +
  • grid[i][j] is either 0 or 1.
  • +
  • There will be at least two friends in the grid.
  • +
+
\ No newline at end of file diff --git a/0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.py b/problems/0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.py similarity index 100% rename from 0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.py rename to problems/0297-serialize-and-deserialize-binary-tree/0297-serialize-and-deserialize-binary-tree.py diff --git a/0297-serialize-and-deserialize-binary-tree/NOTES.md b/problems/0297-serialize-and-deserialize-binary-tree/NOTES.md similarity index 100% rename from 0297-serialize-and-deserialize-binary-tree/NOTES.md rename to problems/0297-serialize-and-deserialize-binary-tree/NOTES.md diff --git a/problems/0297-serialize-and-deserialize-binary-tree/README.md b/problems/0297-serialize-and-deserialize-binary-tree/README.md new file mode 100644 index 000000000..e423e5258 --- /dev/null +++ b/problems/0297-serialize-and-deserialize-binary-tree/README.md @@ -0,0 +1,27 @@ +

297. Serialize and Deserialize Binary Tree

Hard


Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

+ +

Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.

+ +

Clarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,null,null,4,5]
+Output: [1,2,3,null,null,4,5]
+
+ +

Example 2:

+ +
Input: root = []
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 104].
  • +
  • -1000 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.py b/problems/0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.py similarity index 100% rename from 0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.py rename to problems/0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.py diff --git a/0300-longest-increasing-subsequence/NOTES.md b/problems/0300-longest-increasing-subsequence/NOTES.md similarity index 100% rename from 0300-longest-increasing-subsequence/NOTES.md rename to problems/0300-longest-increasing-subsequence/NOTES.md diff --git a/problems/0300-longest-increasing-subsequence/README.md b/problems/0300-longest-increasing-subsequence/README.md new file mode 100644 index 000000000..74241c8e8 --- /dev/null +++ b/problems/0300-longest-increasing-subsequence/README.md @@ -0,0 +1,33 @@ +

300. Longest Increasing Subsequence

Medium


Given an integer array nums, return the length of the longest strictly increasing subsequence.

+ +

 

+

Example 1:

+ +
Input: nums = [10,9,2,5,3,7,101,18]
+Output: 4
+Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
+
+ +

Example 2:

+ +
Input: nums = [0,1,0,3,2,3]
+Output: 4
+
+ +

Example 3:

+ +
Input: nums = [7,7,7,7,7,7,7]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 2500
  • +
  • -104 <= nums[i] <= 104
  • +
+ +

 

+

Follow up: Can you come up with an algorithm that runs in O(n log(n)) time complexity?

+
\ No newline at end of file diff --git a/0305-number-of-islands-ii/0305-number-of-islands-ii.py b/problems/0305-number-of-islands-ii/0305-number-of-islands-ii.py similarity index 100% rename from 0305-number-of-islands-ii/0305-number-of-islands-ii.py rename to problems/0305-number-of-islands-ii/0305-number-of-islands-ii.py diff --git a/0305-number-of-islands-ii/NOTES.md b/problems/0305-number-of-islands-ii/NOTES.md similarity index 100% rename from 0305-number-of-islands-ii/NOTES.md rename to problems/0305-number-of-islands-ii/NOTES.md diff --git a/problems/0305-number-of-islands-ii/README.md b/problems/0305-number-of-islands-ii/README.md new file mode 100644 index 000000000..f9a5f0680 --- /dev/null +++ b/problems/0305-number-of-islands-ii/README.md @@ -0,0 +1,41 @@ +

305. Number of Islands II

Hard


You are given an empty 2D binary grid grid of size m x n. The grid represents a map where 0's represent water and 1's represent land. Initially, all the cells of grid are water cells (i.e., all the cells are 0's).

+ +

We may perform an add land operation which turns the water at position into a land. You are given an array positions where positions[i] = [ri, ci] is the position (ri, ci) at which we should operate the ith operation.

+ +

Return an array of integers answer where answer[i] is the number of islands after turning the cell (ri, ci) into a land.

+ +

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.

+ +

 

+

Example 1:

+ +
Input: m = 3, n = 3, positions = [[0,0],[0,1],[1,2],[2,1]]
+Output: [1,1,2,3]
+Explanation:
+Initially, the 2d grid is filled with water.
+- Operation #1: addLand(0, 0) turns the water at grid[0][0] into a land. We have 1 island.
+- Operation #2: addLand(0, 1) turns the water at grid[0][1] into a land. We still have 1 island.
+- Operation #3: addLand(1, 2) turns the water at grid[1][2] into a land. We have 2 islands.
+- Operation #4: addLand(2, 1) turns the water at grid[2][1] into a land. We have 3 islands.
+
+ +

Example 2:

+ +
Input: m = 1, n = 1, positions = [[0,0]]
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= m, n, positions.length <= 104
  • +
  • 1 <= m * n <= 104
  • +
  • positions[i].length == 2
  • +
  • 0 <= ri < m
  • +
  • 0 <= ci < n
  • +
+ +

 

+

Follow up: Could you solve it in time complexity O(k log(mn)), where k == positions.length?

+
\ No newline at end of file diff --git a/0310-minimum-height-trees/0310-minimum-height-trees.py b/problems/0310-minimum-height-trees/0310-minimum-height-trees.py similarity index 100% rename from 0310-minimum-height-trees/0310-minimum-height-trees.py rename to problems/0310-minimum-height-trees/0310-minimum-height-trees.py diff --git a/0310-minimum-height-trees/NOTES.md b/problems/0310-minimum-height-trees/NOTES.md similarity index 100% rename from 0310-minimum-height-trees/NOTES.md rename to problems/0310-minimum-height-trees/NOTES.md diff --git a/problems/0310-minimum-height-trees/README.md b/problems/0310-minimum-height-trees/README.md new file mode 100644 index 000000000..de5a228ad --- /dev/null +++ b/problems/0310-minimum-height-trees/README.md @@ -0,0 +1,34 @@ +

310. Minimum Height Trees

Medium


A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.

+ +

Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree as the root. When you select a node x as the root, the result tree has height h. Among all possible rooted trees, those with minimum height (i.e. min(h))  are called minimum height trees (MHTs).

+ +

Return a list of all MHTs' root labels. You can return the answer in any order.

+ +

The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf.

+ +

 

+

Example 1:

+ +
Input: n = 4, edges = [[1,0],[1,2],[1,3]]
+Output: [1]
+Explanation: As shown, the height of the tree is 1 when the root is the node with label 1 which is the only MHT.
+
+ +

Example 2:

+ +
Input: n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]
+Output: [3,4]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 2 * 104
  • +
  • edges.length == n - 1
  • +
  • 0 <= ai, bi < n
  • +
  • ai != bi
  • +
  • All the pairs (ai, bi) are distinct.
  • +
  • The given input is guaranteed to be a tree and there will be no repeated edges.
  • +
+
\ No newline at end of file diff --git a/0316-remove-duplicate-letters/0316-remove-duplicate-letters.py b/problems/0316-remove-duplicate-letters/0316-remove-duplicate-letters.py similarity index 100% rename from 0316-remove-duplicate-letters/0316-remove-duplicate-letters.py rename to problems/0316-remove-duplicate-letters/0316-remove-duplicate-letters.py diff --git a/0316-remove-duplicate-letters/NOTES.md b/problems/0316-remove-duplicate-letters/NOTES.md similarity index 100% rename from 0316-remove-duplicate-letters/NOTES.md rename to problems/0316-remove-duplicate-letters/NOTES.md diff --git a/problems/0316-remove-duplicate-letters/README.md b/problems/0316-remove-duplicate-letters/README.md new file mode 100644 index 000000000..22848ad23 --- /dev/null +++ b/problems/0316-remove-duplicate-letters/README.md @@ -0,0 +1,26 @@ +

316. Remove Duplicate Letters

Medium


Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.

+ +

 

+

Example 1:

+ +
Input: s = "bcabc"
+Output: "abc"
+
+ +

Example 2:

+ +
Input: s = "cbacdcbc"
+Output: "acdb"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 104
  • +
  • s consists of lowercase English letters.
  • +
+ +

 

+

Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/

+
\ No newline at end of file diff --git a/0320-generalized-abbreviation/0320-generalized-abbreviation.py b/problems/0320-generalized-abbreviation/0320-generalized-abbreviation.py similarity index 100% rename from 0320-generalized-abbreviation/0320-generalized-abbreviation.py rename to problems/0320-generalized-abbreviation/0320-generalized-abbreviation.py diff --git a/problems/0320-generalized-abbreviation/README.md b/problems/0320-generalized-abbreviation/README.md new file mode 100644 index 000000000..769075d9f --- /dev/null +++ b/problems/0320-generalized-abbreviation/README.md @@ -0,0 +1,38 @@ +

320. Generalized Abbreviation

Medium


A word's generalized abbreviation can be constructed by taking any number of non-overlapping and non-adjacent substrings and replacing them with their respective lengths.

+ +
    +
  • For example, "abcde" can be abbreviated into: + +
      +
    • "a3e" ("bcd" turned into "3")
    • +
    • "1bcd1" ("a" and "e" both turned into "1")
    • +
    • "5" ("abcde" turned into "5")
    • +
    • "abcde" (no substrings replaced)
    • +
    +
  • +
  • However, these abbreviations are invalid: +
      +
    • "23" ("ab" turned into "2" and "cde" turned into "3") is invalid as the substrings chosen are adjacent.
    • +
    • "22de" ("ab" turned into "2" and "bc" turned into "2") is invalid as the substring chosen overlap.
    • +
    +
  • +
+ +

Given a string word, return a list of all the possible generalized abbreviations of word. Return the answer in any order.

+ +

 

+

Example 1:

+
Input: word = "word"
+Output: ["4","3d","2r1","2rd","1o2","1o1d","1or1","1ord","w3","w2d","w1r1","w1rd","wo2","wo1d","wor1","word"]
+

Example 2:

+
Input: word = "a"
+Output: ["1","a"]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= word.length <= 15
  • +
  • word consists of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0322-coin-change/0322-coin-change.py b/problems/0322-coin-change/0322-coin-change.py similarity index 100% rename from 0322-coin-change/0322-coin-change.py rename to problems/0322-coin-change/0322-coin-change.py diff --git a/0322-coin-change/NOTES.md b/problems/0322-coin-change/NOTES.md similarity index 100% rename from 0322-coin-change/NOTES.md rename to problems/0322-coin-change/NOTES.md diff --git a/problems/0322-coin-change/README.md b/problems/0322-coin-change/README.md new file mode 100644 index 000000000..6aa78759e --- /dev/null +++ b/problems/0322-coin-change/README.md @@ -0,0 +1,35 @@ +

322. Coin Change

Medium


You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

+ +

Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

+ +

You may assume that you have an infinite number of each kind of coin.

+ +

 

+

Example 1:

+ +
Input: coins = [1,2,5], amount = 11
+Output: 3
+Explanation: 11 = 5 + 5 + 1
+
+ +

Example 2:

+ +
Input: coins = [2], amount = 3
+Output: -1
+
+ +

Example 3:

+ +
Input: coins = [1], amount = 0
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= coins.length <= 12
  • +
  • 1 <= coins[i] <= 231 - 1
  • +
  • 0 <= amount <= 104
  • +
+
\ No newline at end of file diff --git a/0330-patching-array/0330-patching-array.py b/problems/0330-patching-array/0330-patching-array.py similarity index 100% rename from 0330-patching-array/0330-patching-array.py rename to problems/0330-patching-array/0330-patching-array.py diff --git a/problems/0330-patching-array/README.md b/problems/0330-patching-array/README.md new file mode 100644 index 000000000..fcebede2a --- /dev/null +++ b/problems/0330-patching-array/README.md @@ -0,0 +1,39 @@ +

330. Patching Array

Hard


Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array.

+ +

Return the minimum number of patches required.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3], n = 6
+Output: 1
+Explanation:
+Combinations of nums are [1], [3], [1,3], which form possible sums of: 1, 3, 4.
+Now if we add/patch 2 to nums, the combinations are: [1], [2], [3], [1,3], [2,3], [1,2,3].
+Possible sums are 1, 2, 3, 4, 5, 6, which now covers the range [1, 6].
+So we only need 1 patch.
+
+ +

Example 2:

+ +
Input: nums = [1,5,10], n = 20
+Output: 2
+Explanation: The two patches can be [2, 4].
+
+ +

Example 3:

+ +
Input: nums = [1,2,2], n = 5
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • 1 <= nums[i] <= 104
  • +
  • nums is sorted in ascending order.
  • +
  • 1 <= n <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0332-reconstruct-itinerary/0332-reconstruct-itinerary.py b/problems/0332-reconstruct-itinerary/0332-reconstruct-itinerary.py similarity index 100% rename from 0332-reconstruct-itinerary/0332-reconstruct-itinerary.py rename to problems/0332-reconstruct-itinerary/0332-reconstruct-itinerary.py diff --git a/0332-reconstruct-itinerary/NOTES.md b/problems/0332-reconstruct-itinerary/NOTES.md similarity index 100% rename from 0332-reconstruct-itinerary/NOTES.md rename to problems/0332-reconstruct-itinerary/NOTES.md diff --git a/problems/0332-reconstruct-itinerary/README.md b/problems/0332-reconstruct-itinerary/README.md new file mode 100644 index 000000000..732c4175b --- /dev/null +++ b/problems/0332-reconstruct-itinerary/README.md @@ -0,0 +1,36 @@ +

332. Reconstruct Itinerary

Hard


You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.

+ +

All of the tickets belong to a man who departs from "JFK", thus, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.

+ +
    +
  • For example, the itinerary ["JFK", "LGA"] has a smaller lexical order than ["JFK", "LGB"].
  • +
+ +

You may assume all tickets form at least one valid itinerary. You must use all the tickets once and only once.

+ +

 

+

Example 1:

+ +
Input: tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]
+Output: ["JFK","MUC","LHR","SFO","SJC"]
+
+ +

Example 2:

+ +
Input: tickets = [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
+Output: ["JFK","ATL","JFK","SFO","ATL","SFO"]
+Explanation: Another possible reconstruction is ["JFK","SFO","ATL","JFK","ATL","SFO"] but it is larger in lexical order.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= tickets.length <= 300
  • +
  • tickets[i].length == 2
  • +
  • fromi.length == 3
  • +
  • toi.length == 3
  • +
  • fromi and toi consist of uppercase English letters.
  • +
  • fromi != toi
  • +
+
\ No newline at end of file diff --git a/0338-counting-bits/0338-counting-bits.py b/problems/0338-counting-bits/0338-counting-bits.py similarity index 100% rename from 0338-counting-bits/0338-counting-bits.py rename to problems/0338-counting-bits/0338-counting-bits.py diff --git a/0338-counting-bits/NOTES.md b/problems/0338-counting-bits/NOTES.md similarity index 100% rename from 0338-counting-bits/NOTES.md rename to problems/0338-counting-bits/NOTES.md diff --git a/problems/0338-counting-bits/README.md b/problems/0338-counting-bits/README.md new file mode 100644 index 000000000..6ee2a914f --- /dev/null +++ b/problems/0338-counting-bits/README.md @@ -0,0 +1,41 @@ +

338. Counting Bits

Easy


Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.

+ +

 

+

Example 1:

+ +
Input: n = 2
+Output: [0,1,1]
+Explanation:
+0 --> 0
+1 --> 1
+2 --> 10
+
+ +

Example 2:

+ +
Input: n = 5
+Output: [0,1,1,2,1,2]
+Explanation:
+0 --> 0
+1 --> 1
+2 --> 10
+3 --> 11
+4 --> 100
+5 --> 101
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= n <= 105
  • +
+ +

 

+

Follow up:

+ +
    +
  • It is very easy to come up with a solution with a runtime of O(n log n). Can you do it in linear time O(n) and possibly in a single pass?
  • +
  • Can you do it without using any built-in function (i.e., like __builtin_popcount in C++)?
  • +
+
\ No newline at end of file diff --git a/0340-longest-substring-with-at-most-k-distinct-characters/0340-longest-substring-with-at-most-k-distinct-characters.py b/problems/0340-longest-substring-with-at-most-k-distinct-characters/0340-longest-substring-with-at-most-k-distinct-characters.py similarity index 100% rename from 0340-longest-substring-with-at-most-k-distinct-characters/0340-longest-substring-with-at-most-k-distinct-characters.py rename to problems/0340-longest-substring-with-at-most-k-distinct-characters/0340-longest-substring-with-at-most-k-distinct-characters.py diff --git a/0340-longest-substring-with-at-most-k-distinct-characters/NOTES.md b/problems/0340-longest-substring-with-at-most-k-distinct-characters/NOTES.md similarity index 100% rename from 0340-longest-substring-with-at-most-k-distinct-characters/NOTES.md rename to problems/0340-longest-substring-with-at-most-k-distinct-characters/NOTES.md diff --git a/problems/0340-longest-substring-with-at-most-k-distinct-characters/README.md b/problems/0340-longest-substring-with-at-most-k-distinct-characters/README.md new file mode 100644 index 000000000..3d59f9315 --- /dev/null +++ b/problems/0340-longest-substring-with-at-most-k-distinct-characters/README.md @@ -0,0 +1,24 @@ +

340. Longest Substring with At Most K Distinct Characters

Medium


Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.

+ +

 

+

Example 1:

+ +
Input: s = "eceba", k = 2
+Output: 3
+Explanation: The substring is "ece" with length 3.
+ +

Example 2:

+ +
Input: s = "aa", k = 1
+Output: 2
+Explanation: The substring is "aa" with length 2.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 5 * 104
  • +
  • 0 <= k <= 50
  • +
+
\ No newline at end of file diff --git a/0341-flatten-nested-list-iterator/0341-flatten-nested-list-iterator.py b/problems/0341-flatten-nested-list-iterator/0341-flatten-nested-list-iterator.py similarity index 100% rename from 0341-flatten-nested-list-iterator/0341-flatten-nested-list-iterator.py rename to problems/0341-flatten-nested-list-iterator/0341-flatten-nested-list-iterator.py diff --git a/0341-flatten-nested-list-iterator/NOTES.md b/problems/0341-flatten-nested-list-iterator/NOTES.md similarity index 100% rename from 0341-flatten-nested-list-iterator/NOTES.md rename to problems/0341-flatten-nested-list-iterator/NOTES.md diff --git a/problems/0341-flatten-nested-list-iterator/README.md b/problems/0341-flatten-nested-list-iterator/README.md new file mode 100644 index 000000000..be9109a3e --- /dev/null +++ b/problems/0341-flatten-nested-list-iterator/README.md @@ -0,0 +1,44 @@ +

341. Flatten Nested List Iterator

Medium


You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it.

+ +

Implement the NestedIterator class:

+ +
    +
  • NestedIterator(List<NestedInteger> nestedList) Initializes the iterator with the nested list nestedList.
  • +
  • int next() Returns the next integer in the nested list.
  • +
  • boolean hasNext() Returns true if there are still some integers in the nested list and false otherwise.
  • +
+ +

Your code will be tested with the following pseudocode:

+ +
initialize iterator with nestedList
+res = []
+while iterator.hasNext()
+    append iterator.next() to the end of res
+return res
+
+ +

If res matches the expected flattened list, then your code will be judged as correct.

+ +

 

+

Example 1:

+ +
Input: nestedList = [[1,1],2,[1,1]]
+Output: [1,1,2,1,1]
+Explanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1].
+
+ +

Example 2:

+ +
Input: nestedList = [1,[4,[6]]]
+Output: [1,4,6]
+Explanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nestedList.length <= 500
  • +
  • The values of the integers in the nested list is in the range [-106, 106].
  • +
+
\ No newline at end of file diff --git a/0342-power-of-four/0342-power-of-four.py b/problems/0342-power-of-four/0342-power-of-four.py similarity index 100% rename from 0342-power-of-four/0342-power-of-four.py rename to problems/0342-power-of-four/0342-power-of-four.py diff --git a/0342-power-of-four/NOTES.md b/problems/0342-power-of-four/NOTES.md similarity index 100% rename from 0342-power-of-four/NOTES.md rename to problems/0342-power-of-four/NOTES.md diff --git a/problems/0342-power-of-four/README.md b/problems/0342-power-of-four/README.md new file mode 100644 index 000000000..e5dba89e1 --- /dev/null +++ b/problems/0342-power-of-four/README.md @@ -0,0 +1,24 @@ +

342. Power of Four

Easy


Given an integer n, return true if it is a power of four. Otherwise, return false.

+ +

An integer n is a power of four, if there exists an integer x such that n == 4x.

+ +

 

+

Example 1:

+
Input: n = 16
+Output: true
+

Example 2:

+
Input: n = 5
+Output: false
+

Example 3:

+
Input: n = 1
+Output: true
+
+

 

+

Constraints:

+ +
    +
  • -231 <= n <= 231 - 1
  • +
+ +

 

+Follow up: Could you solve it without loops/recursion?
\ No newline at end of file diff --git a/0343-integer-break/0343-integer-break.py b/problems/0343-integer-break/0343-integer-break.py similarity index 100% rename from 0343-integer-break/0343-integer-break.py rename to problems/0343-integer-break/0343-integer-break.py diff --git a/0343-integer-break/NOTES.md b/problems/0343-integer-break/NOTES.md similarity index 100% rename from 0343-integer-break/NOTES.md rename to problems/0343-integer-break/NOTES.md diff --git a/problems/0343-integer-break/README.md b/problems/0343-integer-break/README.md new file mode 100644 index 000000000..eeb0e4fae --- /dev/null +++ b/problems/0343-integer-break/README.md @@ -0,0 +1,26 @@ +

343. Integer Break

Medium


Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.

+ +

Return the maximum product you can get.

+ +

 

+

Example 1:

+ +
Input: n = 2
+Output: 1
+Explanation: 2 = 1 + 1, 1 × 1 = 1.
+
+ +

Example 2:

+ +
Input: n = 10
+Output: 36
+Explanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 58
  • +
+
\ No newline at end of file diff --git a/0344-reverse-string/0344-reverse-string.cpp b/problems/0344-reverse-string/0344-reverse-string.cpp similarity index 100% rename from 0344-reverse-string/0344-reverse-string.cpp rename to problems/0344-reverse-string/0344-reverse-string.cpp diff --git a/0344-reverse-string/0344-reverse-string.py b/problems/0344-reverse-string/0344-reverse-string.py similarity index 100% rename from 0344-reverse-string/0344-reverse-string.py rename to problems/0344-reverse-string/0344-reverse-string.py diff --git a/0344-reverse-string/NOTES.md b/problems/0344-reverse-string/NOTES.md similarity index 100% rename from 0344-reverse-string/NOTES.md rename to problems/0344-reverse-string/NOTES.md diff --git a/problems/0344-reverse-string/README.md b/problems/0344-reverse-string/README.md new file mode 100644 index 000000000..5c9b221e7 --- /dev/null +++ b/problems/0344-reverse-string/README.md @@ -0,0 +1,20 @@ +

344. Reverse String

Easy


Write a function that reverses a string. The input string is given as an array of characters s.

+ +

You must do this by modifying the input array in-place with O(1) extra memory.

+ +

 

+

Example 1:

+
Input: s = ["h","e","l","l","o"]
+Output: ["o","l","l","e","h"]
+

Example 2:

+
Input: s = ["H","a","n","n","a","h"]
+Output: ["h","a","n","n","a","H"]
+
+

 

+

Constraints:

+ + +
\ No newline at end of file diff --git a/0346-moving-average-from-data-stream/0346-moving-average-from-data-stream.py b/problems/0346-moving-average-from-data-stream/0346-moving-average-from-data-stream.py similarity index 100% rename from 0346-moving-average-from-data-stream/0346-moving-average-from-data-stream.py rename to problems/0346-moving-average-from-data-stream/0346-moving-average-from-data-stream.py diff --git a/0346-moving-average-from-data-stream/NOTES.md b/problems/0346-moving-average-from-data-stream/NOTES.md similarity index 100% rename from 0346-moving-average-from-data-stream/NOTES.md rename to problems/0346-moving-average-from-data-stream/NOTES.md diff --git a/problems/0346-moving-average-from-data-stream/README.md b/problems/0346-moving-average-from-data-stream/README.md new file mode 100644 index 000000000..18b095b21 --- /dev/null +++ b/problems/0346-moving-average-from-data-stream/README.md @@ -0,0 +1,35 @@ +

346. Moving Average from Data Stream

Easy


Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

+ +

Implement the MovingAverage class:

+ +
    +
  • MovingAverage(int size) Initializes the object with the size of the window size.
  • +
  • double next(int val) Returns the moving average of the last size values of the stream.
  • +
+ +

 

+

Example 1:

+ +
Input
+["MovingAverage", "next", "next", "next", "next"]
+[[3], [1], [10], [3], [5]]
+Output
+[null, 1.0, 5.5, 4.66667, 6.0]
+
+Explanation
+MovingAverage movingAverage = new MovingAverage(3);
+movingAverage.next(1); // return 1.0 = 1 / 1
+movingAverage.next(10); // return 5.5 = (1 + 10) / 2
+movingAverage.next(3); // return 4.66667 = (1 + 10 + 3) / 3
+movingAverage.next(5); // return 6.0 = (10 + 3 + 5) / 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= size <= 1000
  • +
  • -105 <= val <= 105
  • +
  • At most 104 calls will be made to next.
  • +
+
\ No newline at end of file diff --git a/0347-top-k-frequent-elements/0347-top-k-frequent-elements.py b/problems/0347-top-k-frequent-elements/0347-top-k-frequent-elements.py similarity index 100% rename from 0347-top-k-frequent-elements/0347-top-k-frequent-elements.py rename to problems/0347-top-k-frequent-elements/0347-top-k-frequent-elements.py diff --git a/0347-top-k-frequent-elements/NOTES.md b/problems/0347-top-k-frequent-elements/NOTES.md similarity index 100% rename from 0347-top-k-frequent-elements/NOTES.md rename to problems/0347-top-k-frequent-elements/NOTES.md diff --git a/problems/0347-top-k-frequent-elements/README.md b/problems/0347-top-k-frequent-elements/README.md new file mode 100644 index 000000000..708d6ca4b --- /dev/null +++ b/problems/0347-top-k-frequent-elements/README.md @@ -0,0 +1,23 @@ +

347. Top K Frequent Elements

Medium


Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

+ +

 

+

Example 1:

+
Input: nums = [1,1,1,2,2,3], k = 2
+Output: [1,2]
+

Example 2:

+
Input: nums = [1], k = 1
+Output: [1]
+
+

 

+

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.
  • +
+ +

 

+

Follow up: Your algorithm's time complexity must be better than O(n log n), where n is the array's size.

+
\ No newline at end of file diff --git a/0349-intersection-of-two-arrays/0349-intersection-of-two-arrays.py b/problems/0349-intersection-of-two-arrays/0349-intersection-of-two-arrays.py similarity index 100% rename from 0349-intersection-of-two-arrays/0349-intersection-of-two-arrays.py rename to problems/0349-intersection-of-two-arrays/0349-intersection-of-two-arrays.py diff --git a/0349-intersection-of-two-arrays/NOTES.md b/problems/0349-intersection-of-two-arrays/NOTES.md similarity index 100% rename from 0349-intersection-of-two-arrays/NOTES.md rename to problems/0349-intersection-of-two-arrays/NOTES.md diff --git a/problems/0349-intersection-of-two-arrays/README.md b/problems/0349-intersection-of-two-arrays/README.md new file mode 100644 index 000000000..24bc72841 --- /dev/null +++ b/problems/0349-intersection-of-two-arrays/README.md @@ -0,0 +1,24 @@ +

349. Intersection of Two Arrays

Easy


Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.

+ +

 

+

Example 1:

+ +
Input: nums1 = [1,2,2,1], nums2 = [2,2]
+Output: [2]
+
+ +

Example 2:

+ +
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
+Output: [9,4]
+Explanation: [4,9] is also accepted.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums1.length, nums2.length <= 1000
  • +
  • 0 <= nums1[i], nums2[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.cpp b/problems/0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.cpp similarity index 100% rename from 0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.cpp rename to problems/0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.cpp diff --git a/0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.py b/problems/0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.py similarity index 100% rename from 0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.py rename to problems/0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.py diff --git a/0350-intersection-of-two-arrays-ii/NOTES.md b/problems/0350-intersection-of-two-arrays-ii/NOTES.md similarity index 100% rename from 0350-intersection-of-two-arrays-ii/NOTES.md rename to problems/0350-intersection-of-two-arrays-ii/NOTES.md diff --git a/problems/0350-intersection-of-two-arrays-ii/README.md b/problems/0350-intersection-of-two-arrays-ii/README.md new file mode 100644 index 000000000..20f1306d2 --- /dev/null +++ b/problems/0350-intersection-of-two-arrays-ii/README.md @@ -0,0 +1,33 @@ +

350. Intersection of Two Arrays II

Easy


Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.

+ +

 

+

Example 1:

+ +
Input: nums1 = [1,2,2,1], nums2 = [2,2]
+Output: [2,2]
+
+ +

Example 2:

+ +
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
+Output: [4,9]
+Explanation: [9,4] is also accepted.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums1.length, nums2.length <= 1000
  • +
  • 0 <= nums1[i], nums2[i] <= 1000
  • +
+ +

 

+

Follow up:

+ +
    +
  • What if the given array is already sorted? How would you optimize your algorithm?
  • +
  • What if nums1's size is small compared to nums2's size? Which algorithm is better?
  • +
  • What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?
  • +
+
\ No newline at end of file diff --git a/0351-android-unlock-patterns/0351-android-unlock-patterns.py b/problems/0351-android-unlock-patterns/0351-android-unlock-patterns.py similarity index 100% rename from 0351-android-unlock-patterns/0351-android-unlock-patterns.py rename to problems/0351-android-unlock-patterns/0351-android-unlock-patterns.py diff --git a/0351-android-unlock-patterns/NOTES.md b/problems/0351-android-unlock-patterns/NOTES.md similarity index 100% rename from 0351-android-unlock-patterns/NOTES.md rename to problems/0351-android-unlock-patterns/NOTES.md diff --git a/problems/0351-android-unlock-patterns/README.md b/problems/0351-android-unlock-patterns/README.md new file mode 100644 index 000000000..e1baadba0 --- /dev/null +++ b/problems/0351-android-unlock-patterns/README.md @@ -0,0 +1,47 @@ +

351. Android Unlock Patterns

Medium


Android devices have a special lock screen with a 3 x 3 grid of dots. Users can set an "unlock pattern" by connecting the dots in a specific sequence, forming a series of joined line segments where each segment's endpoints are two consecutive dots in the sequence. A sequence of k dots is a valid unlock pattern if both of the following are true:

+ +
    +
  • All the dots in the sequence are distinct.
  • +
  • If the line segment connecting two consecutive dots in the sequence passes through the center of any other dot, the other dot must have previously appeared in the sequence. No jumps through the center non-selected dots are allowed. +
      +
    • For example, connecting dots 2 and 9 without dots 5 or 6 appearing beforehand is valid because the line from dot 2 to dot 9 does not pass through the center of either dot 5 or 6.
    • +
    • However, connecting dots 1 and 3 without dot 2 appearing beforehand is invalid because the line from dot 1 to dot 3 passes through the center of dot 2.
    • +
    +
  • +
+ +

Here are some example valid and invalid unlock patterns:

+ +

+ +
    +
  • The 1st pattern [4,1,3,6] is invalid because the line connecting dots 1 and 3 pass through dot 2, but dot 2 did not previously appear in the sequence.
  • +
  • The 2nd pattern [4,1,9,2] is invalid because the line connecting dots 1 and 9 pass through dot 5, but dot 5 did not previously appear in the sequence.
  • +
  • The 3rd pattern [2,4,1,3,6] is valid because it follows the conditions. The line connecting dots 1 and 3 meets the condition because dot 2 previously appeared in the sequence.
  • +
  • The 4th pattern [6,5,4,1,9,2] is valid because it follows the conditions. The line connecting dots 1 and 9 meets the condition because dot 5 previously appeared in the sequence.
  • +
+ +

Given two integers m and n, return the number of unique and valid unlock patterns of the Android grid lock screen that consist of at least m keys and at most n keys.

+ +

Two unlock patterns are considered unique if there is a dot in one sequence that is not in the other, or the order of the dots is different.

+ +

 

+

Example 1:

+ +
Input: m = 1, n = 1
+Output: 9
+
+ +

Example 2:

+ +
Input: m = 1, n = 2
+Output: 65
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= m, n <= 9
  • +
+
\ No newline at end of file diff --git a/0358-rearrange-string-k-distance-apart/0358-rearrange-string-k-distance-apart.py b/problems/0358-rearrange-string-k-distance-apart/0358-rearrange-string-k-distance-apart.py similarity index 100% rename from 0358-rearrange-string-k-distance-apart/0358-rearrange-string-k-distance-apart.py rename to problems/0358-rearrange-string-k-distance-apart/0358-rearrange-string-k-distance-apart.py diff --git a/0358-rearrange-string-k-distance-apart/NOTES.md b/problems/0358-rearrange-string-k-distance-apart/NOTES.md similarity index 100% rename from 0358-rearrange-string-k-distance-apart/NOTES.md rename to problems/0358-rearrange-string-k-distance-apart/NOTES.md diff --git a/problems/0358-rearrange-string-k-distance-apart/README.md b/problems/0358-rearrange-string-k-distance-apart/README.md new file mode 100644 index 000000000..dc5cc6e31 --- /dev/null +++ b/problems/0358-rearrange-string-k-distance-apart/README.md @@ -0,0 +1,33 @@ +

358. Rearrange String k Distance Apart

Hard


Given a string s and an integer k, rearrange s such that the same characters are at least distance k from each other. If it is not possible to rearrange the string, return an empty string "".

+ +

 

+

Example 1:

+ +
Input: s = "aabbcc", k = 3
+Output: "abcabc"
+Explanation: The same letters are at least a distance of 3 from each other.
+
+ +

Example 2:

+ +
Input: s = "aaabc", k = 3
+Output: ""
+Explanation: It is not possible to rearrange the string.
+
+ +

Example 3:

+ +
Input: s = "aaadbbcc", k = 2
+Output: "abacabcd"
+Explanation: The same letters are at least a distance of 2 from each other.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 3 * 105
  • +
  • s consists of only lowercase English letters.
  • +
  • 0 <= k <= s.length
  • +
+
\ No newline at end of file diff --git a/0368-largest-divisible-subset/0368-largest-divisible-subset.py b/problems/0368-largest-divisible-subset/0368-largest-divisible-subset.py similarity index 100% rename from 0368-largest-divisible-subset/0368-largest-divisible-subset.py rename to problems/0368-largest-divisible-subset/0368-largest-divisible-subset.py diff --git a/0368-largest-divisible-subset/NOTES.md b/problems/0368-largest-divisible-subset/NOTES.md similarity index 100% rename from 0368-largest-divisible-subset/NOTES.md rename to problems/0368-largest-divisible-subset/NOTES.md diff --git a/problems/0368-largest-divisible-subset/README.md b/problems/0368-largest-divisible-subset/README.md new file mode 100644 index 000000000..ae432a88b --- /dev/null +++ b/problems/0368-largest-divisible-subset/README.md @@ -0,0 +1,32 @@ +

368. Largest Divisible Subset

Medium


Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:

+ +
    +
  • answer[i] % answer[j] == 0, or
  • +
  • answer[j] % answer[i] == 0
  • +
+ +

If there are multiple solutions, return any of them.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3]
+Output: [1,2]
+Explanation: [1,3] is also accepted.
+
+ +

Example 2:

+ +
Input: nums = [1,2,4,8]
+Output: [1,2,4,8]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • 1 <= nums[i] <= 2 * 109
  • +
  • All the integers in nums are unique.
  • +
+
\ No newline at end of file diff --git a/0377-combination-sum-iv/0377-combination-sum-iv.py b/problems/0377-combination-sum-iv/0377-combination-sum-iv.py similarity index 100% rename from 0377-combination-sum-iv/0377-combination-sum-iv.py rename to problems/0377-combination-sum-iv/0377-combination-sum-iv.py diff --git a/0377-combination-sum-iv/NOTES.md b/problems/0377-combination-sum-iv/NOTES.md similarity index 100% rename from 0377-combination-sum-iv/NOTES.md rename to problems/0377-combination-sum-iv/NOTES.md diff --git a/problems/0377-combination-sum-iv/README.md b/problems/0377-combination-sum-iv/README.md new file mode 100644 index 000000000..842b55ae6 --- /dev/null +++ b/problems/0377-combination-sum-iv/README.md @@ -0,0 +1,40 @@ +

377. Combination Sum IV

Medium


Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.

+ +

The test cases are generated so that the answer can fit in a 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3], target = 4
+Output: 7
+Explanation:
+The possible combination ways are:
+(1, 1, 1, 1)
+(1, 1, 2)
+(1, 2, 1)
+(1, 3)
+(2, 1, 1)
+(2, 2)
+(3, 1)
+Note that different sequences are counted as different combinations.
+
+ +

Example 2:

+ +
Input: nums = [9], target = 3
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 200
  • +
  • 1 <= nums[i] <= 1000
  • +
  • All the elements of nums are unique.
  • +
  • 1 <= target <= 1000
  • +
+ +

 

+

Follow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?

+
\ No newline at end of file diff --git a/0380-insert-delete-getrandom-o1/0380-insert-delete-getrandom-o1.py b/problems/0380-insert-delete-getrandom-o1/0380-insert-delete-getrandom-o1.py similarity index 100% rename from 0380-insert-delete-getrandom-o1/0380-insert-delete-getrandom-o1.py rename to problems/0380-insert-delete-getrandom-o1/0380-insert-delete-getrandom-o1.py diff --git a/0380-insert-delete-getrandom-o1/NOTES.md b/problems/0380-insert-delete-getrandom-o1/NOTES.md similarity index 100% rename from 0380-insert-delete-getrandom-o1/NOTES.md rename to problems/0380-insert-delete-getrandom-o1/NOTES.md diff --git a/problems/0380-insert-delete-getrandom-o1/README.md b/problems/0380-insert-delete-getrandom-o1/README.md new file mode 100644 index 000000000..fc1cda7ba --- /dev/null +++ b/problems/0380-insert-delete-getrandom-o1/README.md @@ -0,0 +1,40 @@ +

380. Insert Delete GetRandom O(1)

Medium


Implement the RandomizedSet class:

+ +
    +
  • RandomizedSet() Initializes the RandomizedSet object.
  • +
  • bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.
  • +
  • bool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false otherwise.
  • +
  • int getRandom() Returns a random element from the current set of elements (it's guaranteed that at least one element exists when this method is called). Each element must have the same probability of being returned.
  • +
+ +

You must implement the functions of the class such that each function works in average O(1) time complexity.

+ +

 

+

Example 1:

+ +
Input
+["RandomizedSet", "insert", "remove", "insert", "getRandom", "remove", "insert", "getRandom"]
+[[], [1], [2], [2], [], [1], [2], []]
+Output
+[null, true, false, true, 2, true, false, 2]
+
+Explanation
+RandomizedSet randomizedSet = new RandomizedSet();
+randomizedSet.insert(1); // Inserts 1 to the set. Returns true as 1 was inserted successfully.
+randomizedSet.remove(2); // Returns false as 2 does not exist in the set.
+randomizedSet.insert(2); // Inserts 2 to the set, returns true. Set now contains [1,2].
+randomizedSet.getRandom(); // getRandom() should return either 1 or 2 randomly.
+randomizedSet.remove(1); // Removes 1 from the set, returns true. Set now contains [2].
+randomizedSet.insert(2); // 2 was already in the set, so return false.
+randomizedSet.getRandom(); // Since 2 is the only number in the set, getRandom() will always return 2.
+
+ +

 

+

Constraints:

+ +
    +
  • -231 <= val <= 231 - 1
  • +
  • At most 2 * 105 calls will be made to insert, remove, and getRandom.
  • +
  • There will be at least one element in the data structure when getRandom is called.
  • +
+
\ No newline at end of file diff --git a/0383-ransom-note/0383-ransom-note.cpp b/problems/0383-ransom-note/0383-ransom-note.cpp similarity index 100% rename from 0383-ransom-note/0383-ransom-note.cpp rename to problems/0383-ransom-note/0383-ransom-note.cpp diff --git a/0383-ransom-note/0383-ransom-note.py b/problems/0383-ransom-note/0383-ransom-note.py similarity index 100% rename from 0383-ransom-note/0383-ransom-note.py rename to problems/0383-ransom-note/0383-ransom-note.py diff --git a/0383-ransom-note/NOTES.md b/problems/0383-ransom-note/NOTES.md similarity index 100% rename from 0383-ransom-note/NOTES.md rename to problems/0383-ransom-note/NOTES.md diff --git a/problems/0383-ransom-note/README.md b/problems/0383-ransom-note/README.md new file mode 100644 index 000000000..c4acf7a22 --- /dev/null +++ b/problems/0383-ransom-note/README.md @@ -0,0 +1,23 @@ +

383. Ransom Note

Easy


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.

+ +

 

+

Example 1:

+
Input: ransomNote = "a", magazine = "b"
+Output: false
+

Example 2:

+
Input: ransomNote = "aa", magazine = "ab"
+Output: false
+

Example 3:

+
Input: ransomNote = "aa", magazine = "aab"
+Output: true
+
+

 

+

Constraints:

+ +
    +
  • 1 <= ransomNote.length, magazine.length <= 105
  • +
  • ransomNote and magazine consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.cpp b/problems/0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.cpp similarity index 100% rename from 0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.cpp rename to problems/0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.cpp diff --git a/0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.py b/problems/0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.py similarity index 100% rename from 0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.py rename to problems/0387-first-unique-character-in-a-string/0387-first-unique-character-in-a-string.py diff --git a/0387-first-unique-character-in-a-string/NOTES.md b/problems/0387-first-unique-character-in-a-string/NOTES.md similarity index 100% rename from 0387-first-unique-character-in-a-string/NOTES.md rename to problems/0387-first-unique-character-in-a-string/NOTES.md diff --git a/problems/0387-first-unique-character-in-a-string/README.md b/problems/0387-first-unique-character-in-a-string/README.md new file mode 100644 index 000000000..e06661f43 --- /dev/null +++ b/problems/0387-first-unique-character-in-a-string/README.md @@ -0,0 +1,21 @@ +

387. First Unique Character in a String

Easy


Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

+ +

 

+

Example 1:

+
Input: s = "leetcode"
+Output: 0
+

Example 2:

+
Input: s = "loveleetcode"
+Output: 2
+

Example 3:

+
Input: s = "aabb"
+Output: -1
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s consists of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0389-find-the-difference/0389-find-the-difference.py b/problems/0389-find-the-difference/0389-find-the-difference.py similarity index 100% rename from 0389-find-the-difference/0389-find-the-difference.py rename to problems/0389-find-the-difference/0389-find-the-difference.py diff --git a/0389-find-the-difference/NOTES.md b/problems/0389-find-the-difference/NOTES.md similarity index 100% rename from 0389-find-the-difference/NOTES.md rename to problems/0389-find-the-difference/NOTES.md diff --git a/problems/0389-find-the-difference/README.md b/problems/0389-find-the-difference/README.md new file mode 100644 index 000000000..0663dd96e --- /dev/null +++ b/problems/0389-find-the-difference/README.md @@ -0,0 +1,29 @@ +

389. Find the Difference

Easy


You are given two strings s and t.

+ +

String t is generated by random shuffling string s and then add one more letter at a random position.

+ +

Return the letter that was added to t.

+ +

 

+

Example 1:

+ +
Input: s = "abcd", t = "abcde"
+Output: "e"
+Explanation: 'e' is the letter that was added.
+
+ +

Example 2:

+ +
Input: s = "", t = "y"
+Output: "y"
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= s.length <= 1000
  • +
  • t.length == s.length + 1
  • +
  • s and t consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0392-is-subsequence/0392-is-subsequence.py b/problems/0392-is-subsequence/0392-is-subsequence.py similarity index 100% rename from 0392-is-subsequence/0392-is-subsequence.py rename to problems/0392-is-subsequence/0392-is-subsequence.py diff --git a/0392-is-subsequence/NOTES.md b/problems/0392-is-subsequence/NOTES.md similarity index 100% rename from 0392-is-subsequence/NOTES.md rename to problems/0392-is-subsequence/NOTES.md diff --git a/problems/0392-is-subsequence/README.md b/problems/0392-is-subsequence/README.md new file mode 100644 index 000000000..56e9b407b --- /dev/null +++ b/problems/0392-is-subsequence/README.md @@ -0,0 +1,23 @@ +

392. Is Subsequence

Easy


Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

+ +

A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

+ +

 

+

Example 1:

+
Input: s = "abc", t = "ahbgdc"
+Output: true
+

Example 2:

+
Input: s = "axc", t = "ahbgdc"
+Output: false
+
+

 

+

Constraints:

+ +
    +
  • 0 <= s.length <= 100
  • +
  • 0 <= t.length <= 104
  • +
  • s and t consist only of lowercase English letters.
  • +
+ +

 

+Follow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?
\ No newline at end of file diff --git a/0402-remove-k-digits/0402-remove-k-digits.py b/problems/0402-remove-k-digits/0402-remove-k-digits.py similarity index 100% rename from 0402-remove-k-digits/0402-remove-k-digits.py rename to problems/0402-remove-k-digits/0402-remove-k-digits.py diff --git a/0402-remove-k-digits/NOTES.md b/problems/0402-remove-k-digits/NOTES.md similarity index 100% rename from 0402-remove-k-digits/NOTES.md rename to problems/0402-remove-k-digits/NOTES.md diff --git a/problems/0402-remove-k-digits/README.md b/problems/0402-remove-k-digits/README.md new file mode 100644 index 000000000..4319e3f39 --- /dev/null +++ b/problems/0402-remove-k-digits/README.md @@ -0,0 +1,33 @@ +

402. Remove K Digits

Medium


Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.

+ +

 

+

Example 1:

+ +
Input: num = "1432219", k = 3
+Output: "1219"
+Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
+
+ +

Example 2:

+ +
Input: num = "10200", k = 1
+Output: "200"
+Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
+
+ +

Example 3:

+ +
Input: num = "10", k = 2
+Output: "0"
+Explanation: Remove all the digits from the number and it is left with nothing which is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= num.length <= 105
  • +
  • num consists of only digits.
  • +
  • num does not have any leading zeros except for the zero itself.
  • +
+
\ No newline at end of file diff --git a/0403-frog-jump/0403-frog-jump.py b/problems/0403-frog-jump/0403-frog-jump.py similarity index 100% rename from 0403-frog-jump/0403-frog-jump.py rename to problems/0403-frog-jump/0403-frog-jump.py diff --git a/0403-frog-jump/NOTES.md b/problems/0403-frog-jump/NOTES.md similarity index 100% rename from 0403-frog-jump/NOTES.md rename to problems/0403-frog-jump/NOTES.md diff --git a/problems/0403-frog-jump/README.md b/problems/0403-frog-jump/README.md new file mode 100644 index 000000000..e2b6e5674 --- /dev/null +++ b/problems/0403-frog-jump/README.md @@ -0,0 +1,31 @@ +

403. Frog Jump

Hard


A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.

+ +

Given a list of stones' positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be 1 unit.

+ +

If the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only jump in the forward direction.

+ +

 

+

Example 1:

+ +
Input: stones = [0,1,3,5,6,8,12,17]
+Output: true
+Explanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.
+
+ +

Example 2:

+ +
Input: stones = [0,1,2,3,4,8,9,11]
+Output: false
+Explanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= stones.length <= 2000
  • +
  • 0 <= stones[i] <= 231 - 1
  • +
  • stones[0] == 0
  • +
  • stones is sorted in a strictly increasing order.
  • +
+
\ No newline at end of file diff --git a/0404-sum-of-left-leaves/0404-sum-of-left-leaves.py b/problems/0404-sum-of-left-leaves/0404-sum-of-left-leaves.py similarity index 100% rename from 0404-sum-of-left-leaves/0404-sum-of-left-leaves.py rename to problems/0404-sum-of-left-leaves/0404-sum-of-left-leaves.py diff --git a/0404-sum-of-left-leaves/NOTES.md b/problems/0404-sum-of-left-leaves/NOTES.md similarity index 100% rename from 0404-sum-of-left-leaves/NOTES.md rename to problems/0404-sum-of-left-leaves/NOTES.md diff --git a/problems/0404-sum-of-left-leaves/README.md b/problems/0404-sum-of-left-leaves/README.md new file mode 100644 index 000000000..34e2f167d --- /dev/null +++ b/problems/0404-sum-of-left-leaves/README.md @@ -0,0 +1,26 @@ +

404. Sum of Left Leaves

Easy


Given the root of a binary tree, return the sum of all left leaves.

+ +

A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

+ +

 

+

Example 1:

+ +
Input: root = [3,9,20,null,null,15,7]
+Output: 24
+Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.
+
+ +

Example 2:

+ +
Input: root = [1]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 1000].
  • +
  • -1000 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0409-longest-palindrome/0409-longest-palindrome.py b/problems/0409-longest-palindrome/0409-longest-palindrome.py similarity index 100% rename from 0409-longest-palindrome/0409-longest-palindrome.py rename to problems/0409-longest-palindrome/0409-longest-palindrome.py diff --git a/0409-longest-palindrome/NOTES.md b/problems/0409-longest-palindrome/NOTES.md similarity index 100% rename from 0409-longest-palindrome/NOTES.md rename to problems/0409-longest-palindrome/NOTES.md diff --git a/problems/0409-longest-palindrome/README.md b/problems/0409-longest-palindrome/README.md new file mode 100644 index 000000000..2d84a7b54 --- /dev/null +++ b/problems/0409-longest-palindrome/README.md @@ -0,0 +1,27 @@ +

409. Longest Palindrome

Easy


Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.

+ +

Letters are case sensitive, for example, "Aa" is not considered a palindrome.

+ +

 

+

Example 1:

+ +
Input: s = "abccccdd"
+Output: 7
+Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7.
+
+ +

Example 2:

+ +
Input: s = "a"
+Output: 1
+Explanation: The longest palindrome that can be built is "a", whose length is 1.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 2000
  • +
  • s consists of lowercase and/or uppercase English letters only.
  • +
+
\ No newline at end of file diff --git a/0416-partition-equal-subset-sum/0416-partition-equal-subset-sum.py b/problems/0416-partition-equal-subset-sum/0416-partition-equal-subset-sum.py similarity index 100% rename from 0416-partition-equal-subset-sum/0416-partition-equal-subset-sum.py rename to problems/0416-partition-equal-subset-sum/0416-partition-equal-subset-sum.py diff --git a/0416-partition-equal-subset-sum/NOTES.md b/problems/0416-partition-equal-subset-sum/NOTES.md similarity index 100% rename from 0416-partition-equal-subset-sum/NOTES.md rename to problems/0416-partition-equal-subset-sum/NOTES.md diff --git a/problems/0416-partition-equal-subset-sum/README.md b/problems/0416-partition-equal-subset-sum/README.md new file mode 100644 index 000000000..91d0d0709 --- /dev/null +++ b/problems/0416-partition-equal-subset-sum/README.md @@ -0,0 +1,25 @@ +

416. Partition Equal Subset Sum

Medium


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:

+ +
Input: nums = [1,5,11,5]
+Output: true
+Explanation: The array can be partitioned as [1, 5, 5] and [11].
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,5]
+Output: false
+Explanation: The array cannot be partitioned into equal sum subsets.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 200
  • +
  • 1 <= nums[i] <= 100
  • +
+
\ No newline at end of file diff --git a/0438-find-all-anagrams-in-a-string/0438-find-all-anagrams-in-a-string.py b/problems/0438-find-all-anagrams-in-a-string/0438-find-all-anagrams-in-a-string.py similarity index 100% rename from 0438-find-all-anagrams-in-a-string/0438-find-all-anagrams-in-a-string.py rename to problems/0438-find-all-anagrams-in-a-string/0438-find-all-anagrams-in-a-string.py diff --git a/0438-find-all-anagrams-in-a-string/NOTES.md b/problems/0438-find-all-anagrams-in-a-string/NOTES.md similarity index 100% rename from 0438-find-all-anagrams-in-a-string/NOTES.md rename to problems/0438-find-all-anagrams-in-a-string/NOTES.md diff --git a/problems/0438-find-all-anagrams-in-a-string/README.md b/problems/0438-find-all-anagrams-in-a-string/README.md new file mode 100644 index 000000000..0a32c05eb --- /dev/null +++ b/problems/0438-find-all-anagrams-in-a-string/README.md @@ -0,0 +1,32 @@ +

438. Find All Anagrams in a String

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.

+ +

 

+

Example 1:

+ +
Input: s = "cbaebabacd", p = "abc"
+Output: [0,6]
+Explanation:
+The substring with start index = 0 is "cba", which is an anagram of "abc".
+The substring with start index = 6 is "bac", which is an anagram of "abc".
+
+ +

Example 2:

+ +
Input: s = "abab", p = "ab"
+Output: [0,1,2]
+Explanation:
+The substring with start index = 0 is "ab", which is an anagram of "ab".
+The substring with start index = 1 is "ba", which is an anagram of "ab".
+The substring with start index = 2 is "ab", which is an anagram of "ab".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length, p.length <= 3 * 104
  • +
  • s and p consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0439-ternary-expression-parser/0439-ternary-expression-parser.py b/problems/0439-ternary-expression-parser/0439-ternary-expression-parser.py similarity index 100% rename from 0439-ternary-expression-parser/0439-ternary-expression-parser.py rename to problems/0439-ternary-expression-parser/0439-ternary-expression-parser.py diff --git a/0439-ternary-expression-parser/NOTES.md b/problems/0439-ternary-expression-parser/NOTES.md similarity index 100% rename from 0439-ternary-expression-parser/NOTES.md rename to problems/0439-ternary-expression-parser/NOTES.md diff --git a/problems/0439-ternary-expression-parser/README.md b/problems/0439-ternary-expression-parser/README.md new file mode 100644 index 000000000..e52f8cce9 --- /dev/null +++ b/problems/0439-ternary-expression-parser/README.md @@ -0,0 +1,41 @@ +

439. Ternary Expression Parser

Medium


Given a string expression representing arbitrarily nested ternary expressions, evaluate the expression, and return the result of it.

+ +

You can always assume that the given expression is valid and only contains digits, '?', ':', 'T', and 'F' where 'T' is true and 'F' is false. All the numbers in the expression are one-digit numbers (i.e., in the range [0, 9]).

+ +

The conditional expressions group right-to-left (as usual in most languages), and the result of the expression will always evaluate to either a digit, 'T' or 'F'.

+ +

 

+

Example 1:

+ +
Input: expression = "T?2:3"
+Output: "2"
+Explanation: If true, then result is 2; otherwise result is 3.
+
+ +

Example 2:

+ +
Input: expression = "F?1:T?4:5"
+Output: "4"
+Explanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:
+"(F ? 1 : (T ? 4 : 5))" --> "(F ? 1 : 4)" --> "4"
+or "(F ? 1 : (T ? 4 : 5))" --> "(T ? 4 : 5)" --> "4"
+
+ +

Example 3:

+ +
Input: expression = "T?T?F:5:3"
+Output: "F"
+Explanation: The conditional expressions group right-to-left. Using parenthesis, it is read/evaluated as:
+"(T ? (T ? F : 5) : 3)" --> "(T ? F : 3)" --> "F"
+"(T ? (T ? F : 5) : 3)" --> "(T ? F : 5)" --> "F"
+
+ +

 

+

Constraints:

+ +
    +
  • 5 <= expression.length <= 104
  • +
  • expression consists of digits, 'T', 'F', '?', and ':'.
  • +
  • It is guaranteed that expression is a valid ternary expression and that each number is a one-digit number.
  • +
+
\ No newline at end of file diff --git a/0442-find-all-duplicates-in-an-array/0442-find-all-duplicates-in-an-array.py b/problems/0442-find-all-duplicates-in-an-array/0442-find-all-duplicates-in-an-array.py similarity index 100% rename from 0442-find-all-duplicates-in-an-array/0442-find-all-duplicates-in-an-array.py rename to problems/0442-find-all-duplicates-in-an-array/0442-find-all-duplicates-in-an-array.py diff --git a/0442-find-all-duplicates-in-an-array/NOTES.md b/problems/0442-find-all-duplicates-in-an-array/NOTES.md similarity index 100% rename from 0442-find-all-duplicates-in-an-array/NOTES.md rename to problems/0442-find-all-duplicates-in-an-array/NOTES.md diff --git a/problems/0442-find-all-duplicates-in-an-array/README.md b/problems/0442-find-all-duplicates-in-an-array/README.md new file mode 100644 index 000000000..1aaf2301b --- /dev/null +++ b/problems/0442-find-all-duplicates-in-an-array/README.md @@ -0,0 +1,25 @@ +

442. Find All Duplicates in an Array

Medium


Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.

+ +

You must write an algorithm that runs in O(n) time and uses only constant extra space.

+ +

 

+

Example 1:

+
Input: nums = [4,3,2,7,8,2,3,1]
+Output: [2,3]
+

Example 2:

+
Input: nums = [1,1,2]
+Output: [1]
+

Example 3:

+
Input: nums = [1]
+Output: []
+
+

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= nums[i] <= n
  • +
  • Each element in nums appears once or twice.
  • +
+
\ No newline at end of file diff --git a/0446-arithmetic-slices-ii-subsequence/0446-arithmetic-slices-ii-subsequence.py b/problems/0446-arithmetic-slices-ii-subsequence/0446-arithmetic-slices-ii-subsequence.py similarity index 100% rename from 0446-arithmetic-slices-ii-subsequence/0446-arithmetic-slices-ii-subsequence.py rename to problems/0446-arithmetic-slices-ii-subsequence/0446-arithmetic-slices-ii-subsequence.py diff --git a/0446-arithmetic-slices-ii-subsequence/NOTES.md b/problems/0446-arithmetic-slices-ii-subsequence/NOTES.md similarity index 100% rename from 0446-arithmetic-slices-ii-subsequence/NOTES.md rename to problems/0446-arithmetic-slices-ii-subsequence/NOTES.md diff --git a/problems/0446-arithmetic-slices-ii-subsequence/README.md b/problems/0446-arithmetic-slices-ii-subsequence/README.md new file mode 100644 index 000000000..af5ccfdd8 --- /dev/null +++ b/problems/0446-arithmetic-slices-ii-subsequence/README.md @@ -0,0 +1,47 @@ +

446. Arithmetic Slices II - Subsequence

Hard


Given an integer array nums, return the number of all the arithmetic subsequences of nums.

+ +

A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

+ +
    +
  • For example, [1, 3, 5, 7, 9], [7, 7, 7, 7], and [3, -1, -5, -9] are arithmetic sequences.
  • +
  • For example, [1, 1, 2, 5, 7] is not an arithmetic sequence.
  • +
+ +

A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.

+ +
    +
  • For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10].
  • +
+ +

The test cases are generated so that the answer fits in 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: nums = [2,4,6,8,10]
+Output: 7
+Explanation: All arithmetic subsequence slices are:
+[2,4,6]
+[4,6,8]
+[6,8,10]
+[2,4,6,8]
+[4,6,8,10]
+[2,4,6,8,10]
+[2,6,10]
+
+ +

Example 2:

+ +
Input: nums = [7,7,7,7,7]
+Output: 16
+Explanation: Any subsequence of this array is arithmetic.
+
+ +

 

+

Constraints:

+ +
    +
  • 1  <= nums.length <= 1000
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0451-sort-characters-by-frequency/0451-sort-characters-by-frequency.py b/problems/0451-sort-characters-by-frequency/0451-sort-characters-by-frequency.py similarity index 100% rename from 0451-sort-characters-by-frequency/0451-sort-characters-by-frequency.py rename to problems/0451-sort-characters-by-frequency/0451-sort-characters-by-frequency.py diff --git a/0451-sort-characters-by-frequency/NOTES.md b/problems/0451-sort-characters-by-frequency/NOTES.md similarity index 100% rename from 0451-sort-characters-by-frequency/NOTES.md rename to problems/0451-sort-characters-by-frequency/NOTES.md diff --git a/problems/0451-sort-characters-by-frequency/README.md b/problems/0451-sort-characters-by-frequency/README.md new file mode 100644 index 000000000..6eceb8b12 --- /dev/null +++ b/problems/0451-sort-characters-by-frequency/README.md @@ -0,0 +1,37 @@ +

451. Sort Characters By Frequency

Medium


Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.

+ +

Return the sorted string. If there are multiple answers, return any of them.

+ +

 

+

Example 1:

+ +
Input: s = "tree"
+Output: "eert"
+Explanation: 'e' appears twice while 'r' and 't' both appear once.
+So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.
+
+ +

Example 2:

+ +
Input: s = "cccaaa"
+Output: "aaaccc"
+Explanation: Both 'c' and 'a' appear three times, so both "cccaaa" and "aaaccc" are valid answers.
+Note that "cacaca" is incorrect, as the same characters must be together.
+
+ +

Example 3:

+ +
Input: s = "Aabb"
+Output: "bbAa"
+Explanation: "bbaA" is also a valid answer, but "Aabb" is incorrect.
+Note that 'A' and 'a' are treated as two different characters.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 5 * 105
  • +
  • s consists of uppercase and lowercase English letters and digits.
  • +
+
\ No newline at end of file diff --git a/0452-minimum-number-of-arrows-to-burst-balloons/0452-minimum-number-of-arrows-to-burst-balloons.py b/problems/0452-minimum-number-of-arrows-to-burst-balloons/0452-minimum-number-of-arrows-to-burst-balloons.py similarity index 100% rename from 0452-minimum-number-of-arrows-to-burst-balloons/0452-minimum-number-of-arrows-to-burst-balloons.py rename to problems/0452-minimum-number-of-arrows-to-burst-balloons/0452-minimum-number-of-arrows-to-burst-balloons.py diff --git a/0452-minimum-number-of-arrows-to-burst-balloons/NOTES.md b/problems/0452-minimum-number-of-arrows-to-burst-balloons/NOTES.md similarity index 100% rename from 0452-minimum-number-of-arrows-to-burst-balloons/NOTES.md rename to problems/0452-minimum-number-of-arrows-to-burst-balloons/NOTES.md diff --git a/problems/0452-minimum-number-of-arrows-to-burst-balloons/README.md b/problems/0452-minimum-number-of-arrows-to-burst-balloons/README.md new file mode 100644 index 000000000..2223a5e28 --- /dev/null +++ b/problems/0452-minimum-number-of-arrows-to-burst-balloons/README.md @@ -0,0 +1,41 @@ +

452. Minimum Number of Arrows to Burst Balloons

Medium


There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons.

+ +

Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is burst by an arrow shot at x if xstart <= x <= xend. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path.

+ +

Given the array points, return the minimum number of arrows that must be shot to burst all balloons.

+ +

 

+

Example 1:

+ +
Input: points = [[10,16],[2,8],[1,6],[7,12]]
+Output: 2
+Explanation: The balloons can be burst by 2 arrows:
+- Shoot an arrow at x = 6, bursting the balloons [2,8] and [1,6].
+- Shoot an arrow at x = 11, bursting the balloons [10,16] and [7,12].
+
+ +

Example 2:

+ +
Input: points = [[1,2],[3,4],[5,6],[7,8]]
+Output: 4
+Explanation: One arrow needs to be shot for each balloon for a total of 4 arrows.
+
+ +

Example 3:

+ +
Input: points = [[1,2],[2,3],[3,4],[4,5]]
+Output: 2
+Explanation: The balloons can be burst by 2 arrows:
+- Shoot an arrow at x = 2, bursting the balloons [1,2] and [2,3].
+- Shoot an arrow at x = 4, bursting the balloons [3,4] and [4,5].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= points.length <= 105
  • +
  • points[i].length == 2
  • +
  • -231 <= xstart < xend <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0455-assign-cookies/0455-assign-cookies.py b/problems/0455-assign-cookies/0455-assign-cookies.py similarity index 100% rename from 0455-assign-cookies/0455-assign-cookies.py rename to problems/0455-assign-cookies/0455-assign-cookies.py diff --git a/0455-assign-cookies/NOTES.md b/problems/0455-assign-cookies/NOTES.md similarity index 100% rename from 0455-assign-cookies/NOTES.md rename to problems/0455-assign-cookies/NOTES.md diff --git a/problems/0455-assign-cookies/README.md b/problems/0455-assign-cookies/README.md new file mode 100644 index 000000000..9387f6b5b --- /dev/null +++ b/problems/0455-assign-cookies/README.md @@ -0,0 +1,32 @@ +

455. Assign Cookies

Easy


Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.

+ +

Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.

+ +

 

+

Example 1:

+ +
Input: g = [1,2,3], s = [1,1]
+Output: 1
+Explanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3. 
+And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.
+You need to output 1.
+
+ +

Example 2:

+ +
Input: g = [1,2], s = [1,2,3]
+Output: 2
+Explanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2. 
+You have 3 cookies and their sizes are big enough to gratify all of the children, 
+You need to output 2.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= g.length <= 3 * 104
  • +
  • 0 <= s.length <= 3 * 104
  • +
  • 1 <= g[i], s[j] <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0456-132-pattern/0456-132-pattern.py b/problems/0456-132-pattern/0456-132-pattern.py similarity index 100% rename from 0456-132-pattern/0456-132-pattern.py rename to problems/0456-132-pattern/0456-132-pattern.py diff --git a/0456-132-pattern/NOTES.md b/problems/0456-132-pattern/NOTES.md similarity index 100% rename from 0456-132-pattern/NOTES.md rename to problems/0456-132-pattern/NOTES.md diff --git a/problems/0456-132-pattern/README.md b/problems/0456-132-pattern/README.md new file mode 100644 index 000000000..049ce47c1 --- /dev/null +++ b/problems/0456-132-pattern/README.md @@ -0,0 +1,35 @@ +

456. 132 Pattern

Medium


Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].

+ +

Return true if there is a 132 pattern in nums, otherwise, return false.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4]
+Output: false
+Explanation: There is no 132 pattern in the sequence.
+
+ +

Example 2:

+ +
Input: nums = [3,1,4,2]
+Output: true
+Explanation: There is a 132 pattern in the sequence: [1, 4, 2].
+
+ +

Example 3:

+ +
Input: nums = [-1,3,2,0]
+Output: true
+Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 2 * 105
  • +
  • -109 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/0458-poor-pigs/0458-poor-pigs.py b/problems/0458-poor-pigs/0458-poor-pigs.py similarity index 100% rename from 0458-poor-pigs/0458-poor-pigs.py rename to problems/0458-poor-pigs/0458-poor-pigs.py diff --git a/0458-poor-pigs/NOTES.md b/problems/0458-poor-pigs/NOTES.md similarity index 100% rename from 0458-poor-pigs/NOTES.md rename to problems/0458-poor-pigs/NOTES.md diff --git a/problems/0458-poor-pigs/README.md b/problems/0458-poor-pigs/README.md new file mode 100644 index 000000000..efa631afc --- /dev/null +++ b/problems/0458-poor-pigs/README.md @@ -0,0 +1,48 @@ +

458. Poor Pigs

Hard


There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.

+ +

You can feed the pigs according to these steps:

+ +
    +
  1. Choose some live pigs to feed.
  2. +
  3. For each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time. Each pig can feed from any number of buckets, and each bucket can be fed from by any number of pigs.
  4. +
  5. Wait for minutesToDie minutes. You may not feed any other pigs during this time.
  6. +
  7. After minutesToDie minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.
  8. +
  9. Repeat this process until you run out of time.
  10. +
+ +

Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.

+ +

 

+

Example 1:

+ +
Input: buckets = 4, minutesToDie = 15, minutesToTest = 15
+Output: 2
+Explanation: We can determine the poisonous bucket as follows:
+At time 0, feed the first pig buckets 1 and 2, and feed the second pig buckets 2 and 3.
+At time 15, there are 4 possible outcomes:
+- If only the first pig dies, then bucket 1 must be poisonous.
+- If only the second pig dies, then bucket 3 must be poisonous.
+- If both pigs die, then bucket 2 must be poisonous.
+- If neither pig dies, then bucket 4 must be poisonous.
+
+ +

Example 2:

+ +
Input: buckets = 4, minutesToDie = 15, minutesToTest = 30
+Output: 2
+Explanation: We can determine the poisonous bucket as follows:
+At time 0, feed the first pig bucket 1, and feed the second pig bucket 2.
+At time 15, there are 2 possible outcomes:
+- If either pig dies, then the poisonous bucket is the one it was fed.
+- If neither pig dies, then feed the first pig bucket 3, and feed the second pig bucket 4.
+At time 30, one of the two pigs must die, and the poisonous bucket is the one it was fed.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= buckets <= 1000
  • +
  • 1 <= minutesToDie <= minutesToTest <= 100
  • +
+
\ No newline at end of file diff --git a/0459-repeated-substring-pattern/0459-repeated-substring-pattern.py b/problems/0459-repeated-substring-pattern/0459-repeated-substring-pattern.py similarity index 100% rename from 0459-repeated-substring-pattern/0459-repeated-substring-pattern.py rename to problems/0459-repeated-substring-pattern/0459-repeated-substring-pattern.py diff --git a/0459-repeated-substring-pattern/NOTES.md b/problems/0459-repeated-substring-pattern/NOTES.md similarity index 100% rename from 0459-repeated-substring-pattern/NOTES.md rename to problems/0459-repeated-substring-pattern/NOTES.md diff --git a/problems/0459-repeated-substring-pattern/README.md b/problems/0459-repeated-substring-pattern/README.md new file mode 100644 index 000000000..9ed1b9712 --- /dev/null +++ b/problems/0459-repeated-substring-pattern/README.md @@ -0,0 +1,31 @@ +

459. Repeated Substring Pattern

Easy


Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.

+ +

 

+

Example 1:

+ +
Input: s = "abab"
+Output: true
+Explanation: It is the substring "ab" twice.
+
+ +

Example 2:

+ +
Input: s = "aba"
+Output: false
+
+ +

Example 3:

+ +
Input: s = "abcabcabcabc"
+Output: true
+Explanation: It is the substring "abc" four times or the substring "abcabc" twice.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 104
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0463-island-perimeter/0463-island-perimeter.py b/problems/0463-island-perimeter/0463-island-perimeter.py similarity index 100% rename from 0463-island-perimeter/0463-island-perimeter.py rename to problems/0463-island-perimeter/0463-island-perimeter.py diff --git a/0463-island-perimeter/NOTES.md b/problems/0463-island-perimeter/NOTES.md similarity index 100% rename from 0463-island-perimeter/NOTES.md rename to problems/0463-island-perimeter/NOTES.md diff --git a/problems/0463-island-perimeter/README.md b/problems/0463-island-perimeter/README.md new file mode 100644 index 000000000..b6359e2b9 --- /dev/null +++ b/problems/0463-island-perimeter/README.md @@ -0,0 +1,37 @@ +

463. Island Perimeter

Easy


You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water.

+ +

Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).

+ +

The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.

+ +

 

+

Example 1:

+ +
Input: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]
+Output: 16
+Explanation: The perimeter is the 16 yellow stripes in the image above.
+
+ +

Example 2:

+ +
Input: grid = [[1]]
+Output: 4
+
+ +

Example 3:

+ +
Input: grid = [[1,0]]
+Output: 4
+
+ +

 

+

Constraints:

+ +
    +
  • row == grid.length
  • +
  • col == grid[i].length
  • +
  • 1 <= row, col <= 100
  • +
  • grid[i][j] is 0 or 1.
  • +
  • There is exactly one island in grid.
  • +
+
\ No newline at end of file diff --git a/0476-number-complement/0476-number-complement.py b/problems/0476-number-complement/0476-number-complement.py similarity index 100% rename from 0476-number-complement/0476-number-complement.py rename to problems/0476-number-complement/0476-number-complement.py diff --git a/problems/0476-number-complement/README.md b/problems/0476-number-complement/README.md new file mode 100644 index 000000000..b46eec80a --- /dev/null +++ b/problems/0476-number-complement/README.md @@ -0,0 +1,33 @@ +

476. Number Complement

Easy


The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.

+ +
    +
  • For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2.
  • +
+ +

Given an integer num, return its complement.

+ +

 

+

Example 1:

+ +
Input: num = 5
+Output: 2
+Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
+
+ +

Example 2:

+ +
Input: num = 1
+Output: 0
+Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= num < 231
  • +
+ +

 

+

Note: This question is the same as 1009: https://leetcode.com/problems/complement-of-base-10-integer/

+
\ No newline at end of file diff --git a/0486-predict-the-winner/0486-predict-the-winner.py b/problems/0486-predict-the-winner/0486-predict-the-winner.py similarity index 100% rename from 0486-predict-the-winner/0486-predict-the-winner.py rename to problems/0486-predict-the-winner/0486-predict-the-winner.py diff --git a/0486-predict-the-winner/NOTES.md b/problems/0486-predict-the-winner/NOTES.md similarity index 100% rename from 0486-predict-the-winner/NOTES.md rename to problems/0486-predict-the-winner/NOTES.md diff --git a/0487-max-consecutive-ones-ii/0487-max-consecutive-ones-ii.py b/problems/0487-max-consecutive-ones-ii/0487-max-consecutive-ones-ii.py similarity index 100% rename from 0487-max-consecutive-ones-ii/0487-max-consecutive-ones-ii.py rename to problems/0487-max-consecutive-ones-ii/0487-max-consecutive-ones-ii.py diff --git a/0487-max-consecutive-ones-ii/NOTES.md b/problems/0487-max-consecutive-ones-ii/NOTES.md similarity index 100% rename from 0487-max-consecutive-ones-ii/NOTES.md rename to problems/0487-max-consecutive-ones-ii/NOTES.md diff --git a/problems/0487-max-consecutive-ones-ii/README.md b/problems/0487-max-consecutive-ones-ii/README.md new file mode 100644 index 000000000..b7de2bb88 --- /dev/null +++ b/problems/0487-max-consecutive-ones-ii/README.md @@ -0,0 +1,34 @@ +

487. Max Consecutive Ones II

Medium


Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0.

+ +

 

+

Example 1:

+ +
Input: nums = [1,0,1,1,0]
+Output: 4
+Explanation: 
+- If we flip the first zero, nums becomes [1,1,1,1,0] and we have 4 consecutive ones.
+- If we flip the second zero, nums becomes [1,0,1,1,1] and we have 3 consecutive ones.
+The max number of consecutive ones is 4.
+
+ +

Example 2:

+ +
Input: nums = [1,0,1,1,0,1]
+Output: 4
+Explanation: 
+- If we flip the first zero, nums becomes [1,1,1,1,0,1] and we have 4 consecutive ones.
+- If we flip the second zero, nums becomes [1,0,1,1,1,1] and we have 4 consecutive ones.
+The max number of consecutive ones is 4.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • nums[i] is either 0 or 1.
  • +
+ +

 

+

Follow up: What if the input numbers come in one by one as an infinite stream? In other words, you can't store all numbers coming from the stream as it's too large to hold in memory. Could you solve it efficiently?

+
\ No newline at end of file diff --git a/0490-the-maze/0490-the-maze.py b/problems/0490-the-maze/0490-the-maze.py similarity index 100% rename from 0490-the-maze/0490-the-maze.py rename to problems/0490-the-maze/0490-the-maze.py diff --git a/0490-the-maze/NOTES.md b/problems/0490-the-maze/NOTES.md similarity index 100% rename from 0490-the-maze/NOTES.md rename to problems/0490-the-maze/NOTES.md diff --git a/problems/0490-the-maze/README.md b/problems/0490-the-maze/README.md new file mode 100644 index 000000000..7a9535fdc --- /dev/null +++ b/problems/0490-the-maze/README.md @@ -0,0 +1,43 @@ +

490. The Maze

Medium


There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.

+ +

Given the m x n maze, the ball's start position and the destination, where start = [startrow, startcol] and destination = [destinationrow, destinationcol], return true if the ball can stop at the destination, otherwise return false.

+ +

You may assume that the borders of the maze are all walls (see examples).

+ +

 

+

Example 1:

+ +
Input: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]
+Output: true
+Explanation: One possible way is : left -> down -> left -> down -> right -> down -> right.
+
+ +

Example 2:

+ +
Input: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]
+Output: false
+Explanation: There is no way for the ball to stop at the destination. Notice that you can pass through the destination but you cannot stop there.
+
+ +

Example 3:

+ +
Input: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • m == maze.length
  • +
  • n == maze[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • maze[i][j] is 0 or 1.
  • +
  • start.length == 2
  • +
  • destination.length == 2
  • +
  • 0 <= startrow, destinationrow <= m
  • +
  • 0 <= startcol, destinationcol <= n
  • +
  • Both the ball and the destination exist in an empty space, and they will not be in the same position initially.
  • +
  • The maze contains at least 2 empty spaces.
  • +
+
\ No newline at end of file diff --git a/0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.py b/problems/0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.py similarity index 100% rename from 0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.py rename to problems/0501-find-mode-in-binary-search-tree/0501-find-mode-in-binary-search-tree.py diff --git a/0501-find-mode-in-binary-search-tree/NOTES.md b/problems/0501-find-mode-in-binary-search-tree/NOTES.md similarity index 100% rename from 0501-find-mode-in-binary-search-tree/NOTES.md rename to problems/0501-find-mode-in-binary-search-tree/NOTES.md diff --git a/problems/0501-find-mode-in-binary-search-tree/README.md b/problems/0501-find-mode-in-binary-search-tree/README.md new file mode 100644 index 000000000..eaf7c94dd --- /dev/null +++ b/problems/0501-find-mode-in-binary-search-tree/README.md @@ -0,0 +1,35 @@ +

501. Find Mode in Binary Search Tree

Easy


Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it.

+ +

If the tree has more than one mode, return them in any order.

+ +

Assume a BST is defined as follows:

+ +
    +
  • The left subtree of a node contains only nodes with keys less than or equal to the node's key.
  • +
  • The right subtree of a node contains only nodes with keys greater than or equal to the node's key.
  • +
  • Both the left and right subtrees must also be binary search trees.
  • +
+ +

 

+

Example 1:

+ +
Input: root = [1,null,2,2]
+Output: [2]
+
+ +

Example 2:

+ +
Input: root = [0]
+Output: [0]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • -105 <= Node.val <= 105
  • +
+ +

 

+Follow up: Could you do that without using any extra space? (Assume that the implicit stack space incurred due to recursion does not count).
\ No newline at end of file diff --git a/0502-ipo/0502-ipo.py b/problems/0502-ipo/0502-ipo.py similarity index 100% rename from 0502-ipo/0502-ipo.py rename to problems/0502-ipo/0502-ipo.py diff --git a/0502-ipo/NOTES.md b/problems/0502-ipo/NOTES.md similarity index 100% rename from 0502-ipo/NOTES.md rename to problems/0502-ipo/NOTES.md diff --git a/problems/0502-ipo/README.md b/problems/0502-ipo/README.md new file mode 100644 index 000000000..80db493de --- /dev/null +++ b/problems/0502-ipo/README.md @@ -0,0 +1,41 @@ +

502. IPO

Hard


Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects to increase its capital before the IPO. Since it has limited resources, it can only finish at most k distinct projects before the IPO. Help LeetCode design the best way to maximize its total capital after finishing at most k distinct projects.

+ +

You are given n projects where the ith project has a pure profit profits[i] and a minimum capital of capital[i] is needed to start it.

+ +

Initially, you have w capital. When you finish a project, you will obtain its pure profit and the profit will be added to your total capital.

+ +

Pick a list of at most k distinct projects from given projects to maximize your final capital, and return the final maximized capital.

+ +

The answer is guaranteed to fit in a 32-bit signed integer.

+ +

 

+

Example 1:

+ +
Input: k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]
+Output: 4
+Explanation: Since your initial capital is 0, you can only start the project indexed 0.
+After finishing it you will obtain profit 1 and your capital becomes 1.
+With capital 1, you can either start the project indexed 1 or the project indexed 2.
+Since you can choose at most 2 projects, you need to finish the project indexed 2 to get the maximum capital.
+Therefore, output the final maximized capital, which is 0 + 1 + 3 = 4.
+
+ +

Example 2:

+ +
Input: k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]
+Output: 6
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= 105
  • +
  • 0 <= w <= 109
  • +
  • n == profits.length
  • +
  • n == capital.length
  • +
  • 1 <= n <= 105
  • +
  • 0 <= profits[i] <= 104
  • +
  • 0 <= capital[i] <= 109
  • +
+
\ No newline at end of file diff --git a/0505-the-maze-ii/0505-the-maze-ii.py b/problems/0505-the-maze-ii/0505-the-maze-ii.py similarity index 100% rename from 0505-the-maze-ii/0505-the-maze-ii.py rename to problems/0505-the-maze-ii/0505-the-maze-ii.py diff --git a/0505-the-maze-ii/NOTES.md b/problems/0505-the-maze-ii/NOTES.md similarity index 100% rename from 0505-the-maze-ii/NOTES.md rename to problems/0505-the-maze-ii/NOTES.md diff --git a/problems/0505-the-maze-ii/README.md b/problems/0505-the-maze-ii/README.md new file mode 100644 index 000000000..136e659e7 --- /dev/null +++ b/problems/0505-the-maze-ii/README.md @@ -0,0 +1,46 @@ +

505. The Maze II

Medium


There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.

+ +

Given the m x n maze, the ball's start position and the destination, where start = [startrow, startcol] and destination = [destinationrow, destinationcol], return the shortest distance for the ball to stop at the destination. If the ball cannot stop at destination, return -1.

+ +

The distance is the number of empty spaces traveled by the ball from the start position (excluded) to the destination (included).

+ +

You may assume that the borders of the maze are all walls (see examples).

+ +

 

+

Example 1:

+ +
Input: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]
+Output: 12
+Explanation: One possible way is : left -> down -> left -> down -> right -> down -> right.
+The length of the path is 1 + 1 + 3 + 1 + 2 + 2 + 2 = 12.
+
+ +

Example 2:

+ +
Input: maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]
+Output: -1
+Explanation: There is no way for the ball to stop at the destination. Notice that you can pass through the destination but you cannot stop there.
+
+ +

Example 3:

+ +
Input: maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], start = [4,3], destination = [0,1]
+Output: -1
+
+ +

 

+

Constraints:

+ +
    +
  • m == maze.length
  • +
  • n == maze[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • maze[i][j] is 0 or 1.
  • +
  • start.length == 2
  • +
  • destination.length == 2
  • +
  • 0 <= startrow, destinationrow < m
  • +
  • 0 <= startcol, destinationcol < n
  • +
  • Both the ball and the destination exist in an empty space, and they will not be in the same position initially.
  • +
  • The maze contains at least 2 empty spaces.
  • +
+
\ No newline at end of file diff --git a/0506-relative-ranks/0506-relative-ranks.py b/problems/0506-relative-ranks/0506-relative-ranks.py similarity index 100% rename from 0506-relative-ranks/0506-relative-ranks.py rename to problems/0506-relative-ranks/0506-relative-ranks.py diff --git a/0506-relative-ranks/NOTES.md b/problems/0506-relative-ranks/NOTES.md similarity index 100% rename from 0506-relative-ranks/NOTES.md rename to problems/0506-relative-ranks/NOTES.md diff --git a/problems/0506-relative-ranks/README.md b/problems/0506-relative-ranks/README.md new file mode 100644 index 000000000..45077e6c4 --- /dev/null +++ b/problems/0506-relative-ranks/README.md @@ -0,0 +1,38 @@ +

506. Relative Ranks

Easy


You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique.

+ +

The athletes are placed based on their scores, where the 1st place athlete has the highest score, the 2nd place athlete has the 2nd highest score, and so on. The placement of each athlete determines their rank:

+ +
    +
  • The 1st place athlete's rank is "Gold Medal".
  • +
  • The 2nd place athlete's rank is "Silver Medal".
  • +
  • The 3rd place athlete's rank is "Bronze Medal".
  • +
  • For the 4th place to the nth place athlete, their rank is their placement number (i.e., the xth place athlete's rank is "x").
  • +
+ +

Return an array answer of size n where answer[i] is the rank of the ith athlete.

+ +

 

+

Example 1:

+ +
Input: score = [5,4,3,2,1]
+Output: ["Gold Medal","Silver Medal","Bronze Medal","4","5"]
+Explanation: The placements are [1st, 2nd, 3rd, 4th, 5th].
+ +

Example 2:

+ +
Input: score = [10,3,8,9,4]
+Output: ["Gold Medal","5","Bronze Medal","Silver Medal","4"]
+Explanation: The placements are [1st, 5th, 3rd, 2nd, 4th].
+
+
+ +

 

+

Constraints:

+ +
    +
  • n == score.length
  • +
  • 1 <= n <= 104
  • +
  • 0 <= score[i] <= 106
  • +
  • All the values in score are unique.
  • +
+
\ No newline at end of file diff --git a/0509-fibonacci-number/0509-fibonacci-number.cpp b/problems/0509-fibonacci-number/0509-fibonacci-number.cpp similarity index 100% rename from 0509-fibonacci-number/0509-fibonacci-number.cpp rename to problems/0509-fibonacci-number/0509-fibonacci-number.cpp diff --git a/0509-fibonacci-number/NOTES.md b/problems/0509-fibonacci-number/NOTES.md similarity index 100% rename from 0509-fibonacci-number/NOTES.md rename to problems/0509-fibonacci-number/NOTES.md diff --git a/problems/0509-fibonacci-number/README.md b/problems/0509-fibonacci-number/README.md new file mode 100644 index 000000000..328aa5723 --- /dev/null +++ b/problems/0509-fibonacci-number/README.md @@ -0,0 +1,37 @@ +

509. Fibonacci Number

Easy


The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

+ +
F(0) = 0, F(1) = 1
+F(n) = F(n - 1) + F(n - 2), for n > 1.
+
+ +

Given n, calculate F(n).

+ +

 

+

Example 1:

+ +
Input: n = 2
+Output: 1
+Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1.
+
+ +

Example 2:

+ +
Input: n = 3
+Output: 2
+Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2.
+
+ +

Example 3:

+ +
Input: n = 4
+Output: 3
+Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= n <= 30
  • +
+
\ No newline at end of file diff --git a/0513-find-bottom-left-tree-value/0513-find-bottom-left-tree-value.py b/problems/0513-find-bottom-left-tree-value/0513-find-bottom-left-tree-value.py similarity index 100% rename from 0513-find-bottom-left-tree-value/0513-find-bottom-left-tree-value.py rename to problems/0513-find-bottom-left-tree-value/0513-find-bottom-left-tree-value.py diff --git a/0513-find-bottom-left-tree-value/NOTES.md b/problems/0513-find-bottom-left-tree-value/NOTES.md similarity index 100% rename from 0513-find-bottom-left-tree-value/NOTES.md rename to problems/0513-find-bottom-left-tree-value/NOTES.md diff --git a/problems/0513-find-bottom-left-tree-value/README.md b/problems/0513-find-bottom-left-tree-value/README.md new file mode 100644 index 000000000..a733cb600 --- /dev/null +++ b/problems/0513-find-bottom-left-tree-value/README.md @@ -0,0 +1,23 @@ +

513. Find Bottom Left Tree Value

Medium


Given the root of a binary tree, return the leftmost value in the last row of the tree.

+ +

 

+

Example 1:

+ +
Input: root = [2,1,3]
+Output: 1
+
+ +

Example 2:

+ +
Input: root = [1,2,3,4,null,5,6,null,null,7]
+Output: 7
+
+ +

 

+

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 diff --git a/0514-freedom-trail/0514-freedom-trail.py b/problems/0514-freedom-trail/0514-freedom-trail.py similarity index 100% rename from 0514-freedom-trail/0514-freedom-trail.py rename to problems/0514-freedom-trail/0514-freedom-trail.py diff --git a/problems/0514-freedom-trail/README.md b/problems/0514-freedom-trail/README.md new file mode 100644 index 000000000..7f40ba560 --- /dev/null +++ b/problems/0514-freedom-trail/README.md @@ -0,0 +1,40 @@ +

514. Freedom Trail

Hard


In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to spell a specific keyword to open the door.

+ +

Given a string ring that represents the code engraved on the outer ring and another string key that represents the keyword that needs to be spelled, return the minimum number of steps to spell all the characters in the keyword.

+ +

Initially, the first character of the ring is aligned at the "12:00" direction. You should spell all the characters in key one by one by rotating ring clockwise or anticlockwise to make each character of the string key aligned at the "12:00" direction and then by pressing the center button.

+ +

At the stage of rotating the ring to spell the key character key[i]:

+ +
    +
  1. You can rotate the ring clockwise or anticlockwise by one place, which counts as one step. The final purpose of the rotation is to align one of ring's characters at the "12:00" direction, where this character must equal key[i].
  2. +
  3. If the character key[i] has been aligned at the "12:00" direction, press the center button to spell, which also counts as one step. After the pressing, you could begin to spell the next character in the key (next stage). Otherwise, you have finished all the spelling.
  4. +
+ +

 

+

Example 1:

+ +
Input: ring = "godding", key = "gd"
+Output: 4
+Explanation:
+For the first key character 'g', since it is already in place, we just need 1 step to spell this character. 
+For the second key character 'd', we need to rotate the ring "godding" anticlockwise by two steps to make it become "ddinggo".
+Also, we need 1 more step for spelling.
+So the final output is 4.
+
+ +

Example 2:

+ +
Input: ring = "godding", key = "godding"
+Output: 13
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= ring.length, key.length <= 100
  • +
  • ring and key consist of only lower case English letters.
  • +
  • It is guaranteed that key could always be spelled by rotating ring.
  • +
+
\ No newline at end of file diff --git a/0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.py b/problems/0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.py similarity index 100% rename from 0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.py rename to problems/0515-find-largest-value-in-each-tree-row/0515-find-largest-value-in-each-tree-row.py diff --git a/0515-find-largest-value-in-each-tree-row/NOTES.md b/problems/0515-find-largest-value-in-each-tree-row/NOTES.md similarity index 100% rename from 0515-find-largest-value-in-each-tree-row/NOTES.md rename to problems/0515-find-largest-value-in-each-tree-row/NOTES.md diff --git a/problems/0515-find-largest-value-in-each-tree-row/README.md b/problems/0515-find-largest-value-in-each-tree-row/README.md new file mode 100644 index 000000000..95bb431d5 --- /dev/null +++ b/problems/0515-find-largest-value-in-each-tree-row/README.md @@ -0,0 +1,23 @@ +

515. Find Largest Value in Each Tree Row

Medium


Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).

+ +

 

+

Example 1:

+ +
Input: root = [1,3,2,5,3,null,9]
+Output: [1,3,9]
+
+ +

Example 2:

+ +
Input: root = [1,2,3]
+Output: [1,3]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree will be in the range [0, 104].
  • +
  • -231 <= Node.val <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0518-coin-change-ii/0518-coin-change-ii.py b/problems/0518-coin-change-ii/0518-coin-change-ii.py similarity index 100% rename from 0518-coin-change-ii/0518-coin-change-ii.py rename to problems/0518-coin-change-ii/0518-coin-change-ii.py diff --git a/0518-coin-change-ii/NOTES.md b/problems/0518-coin-change-ii/NOTES.md similarity index 100% rename from 0518-coin-change-ii/NOTES.md rename to problems/0518-coin-change-ii/NOTES.md diff --git a/problems/0518-coin-change-ii/README.md b/problems/0518-coin-change-ii/README.md new file mode 100644 index 000000000..d7f159727 --- /dev/null +++ b/problems/0518-coin-change-ii/README.md @@ -0,0 +1,43 @@ +

518. Coin Change II

Medium


You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

+ +

Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.

+ +

You may assume that you have an infinite number of each kind of coin.

+ +

The answer is guaranteed to fit into a signed 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: amount = 5, coins = [1,2,5]
+Output: 4
+Explanation: there are four ways to make up the amount:
+5=5
+5=2+2+1
+5=2+1+1+1
+5=1+1+1+1+1
+
+ +

Example 2:

+ +
Input: amount = 3, coins = [2]
+Output: 0
+Explanation: the amount of 3 cannot be made up just with coins of 2.
+
+ +

Example 3:

+ +
Input: amount = 10, coins = [10]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= coins.length <= 300
  • +
  • 1 <= coins[i] <= 5000
  • +
  • All the values of coins are unique.
  • +
  • 0 <= amount <= 5000
  • +
+
\ No newline at end of file diff --git a/0523-continuous-subarray-sum/0523-continuous-subarray-sum.py b/problems/0523-continuous-subarray-sum/0523-continuous-subarray-sum.py similarity index 100% rename from 0523-continuous-subarray-sum/0523-continuous-subarray-sum.py rename to problems/0523-continuous-subarray-sum/0523-continuous-subarray-sum.py diff --git a/0523-continuous-subarray-sum/NOTES.md b/problems/0523-continuous-subarray-sum/NOTES.md similarity index 100% rename from 0523-continuous-subarray-sum/NOTES.md rename to problems/0523-continuous-subarray-sum/NOTES.md diff --git a/problems/0523-continuous-subarray-sum/README.md b/problems/0523-continuous-subarray-sum/README.md new file mode 100644 index 000000000..0bf5d8e1d --- /dev/null +++ b/problems/0523-continuous-subarray-sum/README.md @@ -0,0 +1,48 @@ +

523. Continuous Subarray Sum

Medium


Given an integer array nums and an integer k, return true if nums has a good subarray or false otherwise.

+ +

A good subarray is a subarray where:

+ +
    +
  • its length is at least two, and
  • +
  • the sum of the elements of the subarray is a multiple of k.
  • +
+ +

Note that:

+ +
    +
  • A subarray is a contiguous part of the array.
  • +
  • An integer x is a multiple of k if there exists an integer n such that x = n * k. 0 is always a multiple of k.
  • +
+ +

 

+

Example 1:

+ +
Input: nums = [23,2,4,6,7], k = 6
+Output: true
+Explanation: [2, 4] is a continuous subarray of size 2 whose elements sum up to 6.
+
+ +

Example 2:

+ +
Input: nums = [23,2,6,4,7], k = 6
+Output: true
+Explanation: [23, 2, 6, 4, 7] is an continuous subarray of size 5 whose elements sum up to 42.
+42 is a multiple of 6 because 42 = 7 * 6 and 7 is an integer.
+
+ +

Example 3:

+ +
Input: nums = [23,2,6,4,7], k = 13
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 109
  • +
  • 0 <= sum(nums[i]) <= 231 - 1
  • +
  • 1 <= k <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0525-contiguous-array/0525-contiguous-array.py b/problems/0525-contiguous-array/0525-contiguous-array.py similarity index 100% rename from 0525-contiguous-array/0525-contiguous-array.py rename to problems/0525-contiguous-array/0525-contiguous-array.py diff --git a/0525-contiguous-array/NOTES.md b/problems/0525-contiguous-array/NOTES.md similarity index 100% rename from 0525-contiguous-array/NOTES.md rename to problems/0525-contiguous-array/NOTES.md diff --git a/problems/0525-contiguous-array/README.md b/problems/0525-contiguous-array/README.md new file mode 100644 index 000000000..20b1a72d9 --- /dev/null +++ b/problems/0525-contiguous-array/README.md @@ -0,0 +1,25 @@ +

525. Contiguous Array

Medium


Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.

+ +

 

+

Example 1:

+ +
Input: nums = [0,1]
+Output: 2
+Explanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.
+
+ +

Example 2:

+ +
Input: nums = [0,1,0]
+Output: 2
+Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • nums[i] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/0532-k-diff-pairs-in-an-array/0532-k-diff-pairs-in-an-array.py b/problems/0532-k-diff-pairs-in-an-array/0532-k-diff-pairs-in-an-array.py similarity index 100% rename from 0532-k-diff-pairs-in-an-array/0532-k-diff-pairs-in-an-array.py rename to problems/0532-k-diff-pairs-in-an-array/0532-k-diff-pairs-in-an-array.py diff --git a/0532-k-diff-pairs-in-an-array/NOTES.md b/problems/0532-k-diff-pairs-in-an-array/NOTES.md similarity index 100% rename from 0532-k-diff-pairs-in-an-array/NOTES.md rename to problems/0532-k-diff-pairs-in-an-array/NOTES.md diff --git a/problems/0532-k-diff-pairs-in-an-array/README.md b/problems/0532-k-diff-pairs-in-an-array/README.md new file mode 100644 index 000000000..fd44bfa14 --- /dev/null +++ b/problems/0532-k-diff-pairs-in-an-array/README.md @@ -0,0 +1,44 @@ +

532. K-diff Pairs in an Array

Medium


Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.

+ +

A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:

+ +
    +
  • 0 <= i, j < nums.length
  • +
  • i != j
  • +
  • |nums[i] - nums[j]| == k
  • +
+ +

Notice that |val| denotes the absolute value of val.

+ +

 

+

Example 1:

+ +
Input: nums = [3,1,4,1,5], k = 2
+Output: 2
+Explanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5).
+Although we have two 1s in the input, we should only return the number of unique pairs.
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,4,5], k = 1
+Output: 4
+Explanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5).
+
+ +

Example 3:

+ +
Input: nums = [1,3,1,5,4], k = 0
+Output: 1
+Explanation: There is one 0-diff pair in the array, (1, 1).
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 104
  • +
  • -107 <= nums[i] <= 107
  • +
  • 0 <= k <= 107
  • +
+
\ No newline at end of file diff --git a/0540-single-element-in-a-sorted-array/0540-single-element-in-a-sorted-array.py b/problems/0540-single-element-in-a-sorted-array/0540-single-element-in-a-sorted-array.py similarity index 100% rename from 0540-single-element-in-a-sorted-array/0540-single-element-in-a-sorted-array.py rename to problems/0540-single-element-in-a-sorted-array/0540-single-element-in-a-sorted-array.py diff --git a/0540-single-element-in-a-sorted-array/NOTES.md b/problems/0540-single-element-in-a-sorted-array/NOTES.md similarity index 100% rename from 0540-single-element-in-a-sorted-array/NOTES.md rename to problems/0540-single-element-in-a-sorted-array/NOTES.md diff --git a/problems/0540-single-element-in-a-sorted-array/README.md b/problems/0540-single-element-in-a-sorted-array/README.md new file mode 100644 index 000000000..41726f966 --- /dev/null +++ b/problems/0540-single-element-in-a-sorted-array/README.md @@ -0,0 +1,22 @@ +

540. Single Element in a Sorted Array

Medium


You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.

+ +

Return the single element that appears only once.

+ +

Your solution must run in O(log n) time and O(1) space.

+ +

 

+

Example 1:

+
Input: nums = [1,1,2,3,3,4,4,8,8]
+Output: 2
+

Example 2:

+
Input: nums = [3,3,7,7,10,11,11]
+Output: 10
+
+

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/0542-01-matrix/0542-01-matrix.cpp b/problems/0542-01-matrix/0542-01-matrix.cpp similarity index 100% rename from 0542-01-matrix/0542-01-matrix.cpp rename to problems/0542-01-matrix/0542-01-matrix.cpp diff --git a/0542-01-matrix/0542-01-matrix.py b/problems/0542-01-matrix/0542-01-matrix.py similarity index 100% rename from 0542-01-matrix/0542-01-matrix.py rename to problems/0542-01-matrix/0542-01-matrix.py diff --git a/0542-01-matrix/NOTES.md b/problems/0542-01-matrix/NOTES.md similarity index 100% rename from 0542-01-matrix/NOTES.md rename to problems/0542-01-matrix/NOTES.md diff --git a/problems/0542-01-matrix/README.md b/problems/0542-01-matrix/README.md new file mode 100644 index 000000000..931bf9a29 --- /dev/null +++ b/problems/0542-01-matrix/README.md @@ -0,0 +1,29 @@ +

542. 01 Matrix

Medium


Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.

+ +

The distance between two adjacent cells is 1.

+ +

 

+

Example 1:

+ +
Input: mat = [[0,0,0],[0,1,0],[0,0,0]]
+Output: [[0,0,0],[0,1,0],[0,0,0]]
+
+ +

Example 2:

+ +
Input: mat = [[0,0,0],[0,1,0],[1,1,1]]
+Output: [[0,0,0],[0,1,0],[1,2,1]]
+
+ +

 

+

Constraints:

+ +
    +
  • m == mat.length
  • +
  • n == mat[i].length
  • +
  • 1 <= m, n <= 104
  • +
  • 1 <= m * n <= 104
  • +
  • mat[i][j] is either 0 or 1.
  • +
  • There is at least one 0 in mat.
  • +
+
\ No newline at end of file diff --git a/0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.py b/problems/0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.py similarity index 100% rename from 0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.py rename to problems/0543-diameter-of-binary-tree/0543-diameter-of-binary-tree.py diff --git a/0543-diameter-of-binary-tree/NOTES.md b/problems/0543-diameter-of-binary-tree/NOTES.md similarity index 100% rename from 0543-diameter-of-binary-tree/NOTES.md rename to problems/0543-diameter-of-binary-tree/NOTES.md diff --git a/problems/0543-diameter-of-binary-tree/README.md b/problems/0543-diameter-of-binary-tree/README.md new file mode 100644 index 000000000..26e6fc348 --- /dev/null +++ b/problems/0543-diameter-of-binary-tree/README.md @@ -0,0 +1,28 @@ +

543. Diameter of Binary Tree

Easy


Given the root of a binary tree, return the length of the diameter of the tree.

+ +

The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

+ +

The length of a path between two nodes is represented by the number of edges between them.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,4,5]
+Output: 3
+Explanation: 3 is the length of the path [4,2,1,3] or [5,2,1,3].
+
+ +

Example 2:

+ +
Input: root = [1,2]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • -100 <= Node.val <= 100
  • +
+
\ No newline at end of file diff --git a/0552-student-attendance-record-ii/0552-student-attendance-record-ii.py b/problems/0552-student-attendance-record-ii/0552-student-attendance-record-ii.py similarity index 100% rename from 0552-student-attendance-record-ii/0552-student-attendance-record-ii.py rename to problems/0552-student-attendance-record-ii/0552-student-attendance-record-ii.py diff --git a/0552-student-attendance-record-ii/NOTES.md b/problems/0552-student-attendance-record-ii/NOTES.md similarity index 100% rename from 0552-student-attendance-record-ii/NOTES.md rename to problems/0552-student-attendance-record-ii/NOTES.md diff --git a/problems/0552-student-attendance-record-ii/README.md b/problems/0552-student-attendance-record-ii/README.md new file mode 100644 index 000000000..9dca9bf81 --- /dev/null +++ b/problems/0552-student-attendance-record-ii/README.md @@ -0,0 +1,46 @@ +

552. Student Attendance Record II

Hard


An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:

+ +
    +
  • 'A': Absent.
  • +
  • 'L': Late.
  • +
  • 'P': Present.
  • +
+ +

Any student is eligible for an attendance award if they meet both of the following criteria:

+ +
    +
  • The student was absent ('A') for strictly fewer than 2 days total.
  • +
  • The student was never late ('L') for 3 or more consecutive days.
  • +
+ +

Given an integer n, return the number of possible attendance records of length n that make a student eligible for an attendance award. The answer may be very large, so return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 2
+Output: 8
+Explanation: There are 8 records with length 2 that are eligible for an award:
+"PP", "AP", "PA", "LP", "PL", "AL", "LA", "LL"
+Only "AA" is not eligible because there are 2 absences (there need to be fewer than 2).
+
+ +

Example 2:

+ +
Input: n = 1
+Output: 3
+
+ +

Example 3:

+ +
Input: n = 10101
+Output: 183236316
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 105
  • +
+
\ No newline at end of file diff --git a/0557-reverse-words-in-a-string-iii/0557-reverse-words-in-a-string-iii.cpp b/problems/0557-reverse-words-in-a-string-iii/0557-reverse-words-in-a-string-iii.cpp similarity index 100% rename from 0557-reverse-words-in-a-string-iii/0557-reverse-words-in-a-string-iii.cpp rename to problems/0557-reverse-words-in-a-string-iii/0557-reverse-words-in-a-string-iii.cpp diff --git a/0557-reverse-words-in-a-string-iii/NOTES.md b/problems/0557-reverse-words-in-a-string-iii/NOTES.md similarity index 100% rename from 0557-reverse-words-in-a-string-iii/NOTES.md rename to problems/0557-reverse-words-in-a-string-iii/NOTES.md diff --git a/problems/0557-reverse-words-in-a-string-iii/README.md b/problems/0557-reverse-words-in-a-string-iii/README.md new file mode 100644 index 000000000..cdc6104ce --- /dev/null +++ b/problems/0557-reverse-words-in-a-string-iii/README.md @@ -0,0 +1,21 @@ +

557. Reverse Words in a String III

Easy


Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

+ +

 

+

Example 1:

+
Input: s = "Let's take LeetCode contest"
+Output: "s'teL ekat edoCteeL tsetnoc"
+

Example 2:

+
Input: s = "God Ding"
+Output: "doG gniD"
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 5 * 104
  • +
  • s contains printable ASCII characters.
  • +
  • s does not contain any leading or trailing spaces.
  • +
  • There is at least one word in s.
  • +
  • All the words in s are separated by a single space.
  • +
+
\ No newline at end of file diff --git a/0561-array-partition/0561-array-partition.py b/problems/0561-array-partition/0561-array-partition.py similarity index 100% rename from 0561-array-partition/0561-array-partition.py rename to problems/0561-array-partition/0561-array-partition.py diff --git a/0561-array-partition/NOTES.md b/problems/0561-array-partition/NOTES.md similarity index 100% rename from 0561-array-partition/NOTES.md rename to problems/0561-array-partition/NOTES.md diff --git a/problems/0561-array-partition/README.md b/problems/0561-array-partition/README.md new file mode 100644 index 000000000..62dafee98 --- /dev/null +++ b/problems/0561-array-partition/README.md @@ -0,0 +1,29 @@ +

561. Array Partition

Easy


Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum.

+ +

 

+

Example 1:

+ +
Input: nums = [1,4,3,2]
+Output: 4
+Explanation: All possible pairings (ignoring the ordering of elements) are:
+1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3
+2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3
+3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4
+So the maximum possible sum is 4.
+ +

Example 2:

+ +
Input: nums = [6,2,6,5,1,2]
+Output: 9
+Explanation: The optimal pairing is (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 104
  • +
  • nums.length == 2 * n
  • +
  • -104 <= nums[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0564-find-the-closest-palindrome/0564-find-the-closest-palindrome.py b/problems/0564-find-the-closest-palindrome/0564-find-the-closest-palindrome.py similarity index 100% rename from 0564-find-the-closest-palindrome/0564-find-the-closest-palindrome.py rename to problems/0564-find-the-closest-palindrome/0564-find-the-closest-palindrome.py diff --git a/0564-find-the-closest-palindrome/NOTES.md b/problems/0564-find-the-closest-palindrome/NOTES.md similarity index 100% rename from 0564-find-the-closest-palindrome/NOTES.md rename to problems/0564-find-the-closest-palindrome/NOTES.md diff --git a/problems/0564-find-the-closest-palindrome/README.md b/problems/0564-find-the-closest-palindrome/README.md new file mode 100644 index 000000000..a5b4ec140 --- /dev/null +++ b/problems/0564-find-the-closest-palindrome/README.md @@ -0,0 +1,28 @@ +

564. Find the Closest Palindrome

Hard


Given a string n representing an integer, return the closest integer (not including itself), which is a palindrome. If there is a tie, return the smaller one.

+ +

The closest is defined as the absolute difference minimized between two integers.

+ +

 

+

Example 1:

+ +
Input: n = "123"
+Output: "121"
+
+ +

Example 2:

+ +
Input: n = "1"
+Output: "0"
+Explanation: 0 and 2 are the closest palindromes but we return the smallest which is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n.length <= 18
  • +
  • n consists of only digits.
  • +
  • n does not have leading zeros.
  • +
  • n is representing an integer in the range [1, 1018 - 1].
  • +
+
\ No newline at end of file diff --git a/0566-reshape-the-matrix/0566-reshape-the-matrix.cpp b/problems/0566-reshape-the-matrix/0566-reshape-the-matrix.cpp similarity index 100% rename from 0566-reshape-the-matrix/0566-reshape-the-matrix.cpp rename to problems/0566-reshape-the-matrix/0566-reshape-the-matrix.cpp diff --git a/0566-reshape-the-matrix/NOTES.md b/problems/0566-reshape-the-matrix/NOTES.md similarity index 100% rename from 0566-reshape-the-matrix/NOTES.md rename to problems/0566-reshape-the-matrix/NOTES.md diff --git a/problems/0566-reshape-the-matrix/README.md b/problems/0566-reshape-the-matrix/README.md new file mode 100644 index 000000000..3c30dfb89 --- /dev/null +++ b/problems/0566-reshape-the-matrix/README.md @@ -0,0 +1,32 @@ +

566. Reshape the Matrix

Easy


In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.

+ +

You are given an m x n matrix mat and two integers r and c representing the number of rows and the number of columns of the wanted reshaped matrix.

+ +

The reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were.

+ +

If the reshape operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.

+ +

 

+

Example 1:

+ +
Input: mat = [[1,2],[3,4]], r = 1, c = 4
+Output: [[1,2,3,4]]
+
+ +

Example 2:

+ +
Input: mat = [[1,2],[3,4]], r = 2, c = 4
+Output: [[1,2],[3,4]]
+
+ +

 

+

Constraints:

+ +
    +
  • m == mat.length
  • +
  • n == mat[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • -1000 <= mat[i][j] <= 1000
  • +
  • 1 <= r, c <= 300
  • +
+
\ No newline at end of file diff --git a/0567-permutation-in-string/0567-permutation-in-string.cpp b/problems/0567-permutation-in-string/0567-permutation-in-string.cpp similarity index 100% rename from 0567-permutation-in-string/0567-permutation-in-string.cpp rename to problems/0567-permutation-in-string/0567-permutation-in-string.cpp diff --git a/0567-permutation-in-string/NOTES.md b/problems/0567-permutation-in-string/NOTES.md similarity index 100% rename from 0567-permutation-in-string/NOTES.md rename to problems/0567-permutation-in-string/NOTES.md diff --git a/problems/0567-permutation-in-string/README.md b/problems/0567-permutation-in-string/README.md new file mode 100644 index 000000000..095f65265 --- /dev/null +++ b/problems/0567-permutation-in-string/README.md @@ -0,0 +1,26 @@ +

567. Permutation in String

Medium


Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

+ +

In other words, return true if one of s1's permutations is the substring of s2.

+ +

 

+

Example 1:

+ +
Input: s1 = "ab", s2 = "eidbaooo"
+Output: true
+Explanation: s2 contains one permutation of s1 ("ba").
+
+ +

Example 2:

+ +
Input: s1 = "ab", s2 = "eidboaoo"
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s1.length, s2.length <= 104
  • +
  • s1 and s2 consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0572-subtree-of-another-tree/0572-subtree-of-another-tree.js b/problems/0572-subtree-of-another-tree/0572-subtree-of-another-tree.js similarity index 100% rename from 0572-subtree-of-another-tree/0572-subtree-of-another-tree.js rename to problems/0572-subtree-of-another-tree/0572-subtree-of-another-tree.js diff --git a/0572-subtree-of-another-tree/0572-subtree-of-another-tree.py b/problems/0572-subtree-of-another-tree/0572-subtree-of-another-tree.py similarity index 100% rename from 0572-subtree-of-another-tree/0572-subtree-of-another-tree.py rename to problems/0572-subtree-of-another-tree/0572-subtree-of-another-tree.py diff --git a/0572-subtree-of-another-tree/NOTES.md b/problems/0572-subtree-of-another-tree/NOTES.md similarity index 100% rename from 0572-subtree-of-another-tree/NOTES.md rename to problems/0572-subtree-of-another-tree/NOTES.md diff --git a/problems/0572-subtree-of-another-tree/README.md b/problems/0572-subtree-of-another-tree/README.md new file mode 100644 index 000000000..7a67b3710 --- /dev/null +++ b/problems/0572-subtree-of-another-tree/README.md @@ -0,0 +1,27 @@ +

572. Subtree of Another Tree

Easy


Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.

+ +

A subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be considered as a subtree of itself.

+ +

 

+

Example 1:

+ +
Input: root = [3,4,5,1,2], subRoot = [4,1,2]
+Output: true
+
+ +

Example 2:

+ +
Input: root = [3,4,5,1,2,null,null,null,null,0], subRoot = [4,1,2]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the root tree is in the range [1, 2000].
  • +
  • The number of nodes in the subRoot tree is in the range [1, 1000].
  • +
  • -104 <= root.val <= 104
  • +
  • -104 <= subRoot.val <= 104
  • +
+
\ No newline at end of file diff --git a/0573-squirrel-simulation/0573-squirrel-simulation.py b/problems/0573-squirrel-simulation/0573-squirrel-simulation.py similarity index 100% rename from 0573-squirrel-simulation/0573-squirrel-simulation.py rename to problems/0573-squirrel-simulation/0573-squirrel-simulation.py diff --git a/0573-squirrel-simulation/NOTES.md b/problems/0573-squirrel-simulation/NOTES.md similarity index 100% rename from 0573-squirrel-simulation/NOTES.md rename to problems/0573-squirrel-simulation/NOTES.md diff --git a/problems/0573-squirrel-simulation/README.md b/problems/0573-squirrel-simulation/README.md new file mode 100644 index 000000000..44248ee32 --- /dev/null +++ b/problems/0573-squirrel-simulation/README.md @@ -0,0 +1,41 @@ +

573. Squirrel Simulation

Medium


You are given two integers height and width representing a garden of size height x width. You are also given:

+ +
    +
  • an array tree where tree = [treer, treec] is the position of the tree in the garden,
  • +
  • an array squirrel where squirrel = [squirrelr, squirrelc] is the position of the squirrel in the garden,
  • +
  • and an array nuts where nuts[i] = [nutir, nutic] is the position of the ith nut in the garden.
  • +
+ +

The squirrel can only take at most one nut at one time and can move in four directions: up, down, left, and right, to the adjacent cell.

+ +

Return the minimal distance for the squirrel to collect all the nuts and put them under the tree one by one.

+ +

The distance is the number of moves.

+ +

 

+

Example 1:

+ +
Input: height = 5, width = 7, tree = [2,2], squirrel = [4,4], nuts = [[3,0], [2,5]]
+Output: 12
+Explanation: The squirrel should go to the nut at [2, 5] first to achieve a minimal distance.
+
+ +

Example 2:

+ +
Input: height = 1, width = 3, tree = [0,1], squirrel = [0,0], nuts = [[0,2]]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= height, width <= 100
  • +
  • tree.length == 2
  • +
  • squirrel.length == 2
  • +
  • 1 <= nuts.length <= 5000
  • +
  • nuts[i].length == 2
  • +
  • 0 <= treer, squirrelr, nutir <= height
  • +
  • 0 <= treec, squirrelc, nutic <= width
  • +
+
\ No newline at end of file diff --git a/0576-out-of-boundary-paths/0576-out-of-boundary-paths.py b/problems/0576-out-of-boundary-paths/0576-out-of-boundary-paths.py similarity index 100% rename from 0576-out-of-boundary-paths/0576-out-of-boundary-paths.py rename to problems/0576-out-of-boundary-paths/0576-out-of-boundary-paths.py diff --git a/0576-out-of-boundary-paths/NOTES.md b/problems/0576-out-of-boundary-paths/NOTES.md similarity index 100% rename from 0576-out-of-boundary-paths/NOTES.md rename to problems/0576-out-of-boundary-paths/NOTES.md diff --git a/problems/0576-out-of-boundary-paths/README.md b/problems/0576-out-of-boundary-paths/README.md new file mode 100644 index 000000000..25a688e2e --- /dev/null +++ b/problems/0576-out-of-boundary-paths/README.md @@ -0,0 +1,27 @@ +

576. Out of Boundary Paths

Medium


There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent cells in the grid (possibly out of the grid crossing the grid boundary). You can apply at most maxMove moves to the ball.

+ +

Given the five integers m, n, maxMove, startRow, startColumn, return the number of paths to move the ball out of the grid boundary. Since the answer can be very large, return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0
+Output: 6
+
+ +

Example 2:

+ +
Input: m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1
+Output: 12
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= m, n <= 50
  • +
  • 0 <= maxMove <= 50
  • +
  • 0 <= startRow < m
  • +
  • 0 <= startColumn < n
  • +
+
\ No newline at end of file diff --git a/0584-find-customer-referee/0584-find-customer-referee.sql b/problems/0584-find-customer-referee/0584-find-customer-referee.sql similarity index 100% rename from 0584-find-customer-referee/0584-find-customer-referee.sql rename to problems/0584-find-customer-referee/0584-find-customer-referee.sql diff --git a/0584-find-customer-referee/NOTES.md b/problems/0584-find-customer-referee/NOTES.md similarity index 100% rename from 0584-find-customer-referee/NOTES.md rename to problems/0584-find-customer-referee/NOTES.md diff --git a/problems/0584-find-customer-referee/README.md b/problems/0584-find-customer-referee/README.md new file mode 100644 index 000000000..372be3cf4 --- /dev/null +++ b/problems/0584-find-customer-referee/README.md @@ -0,0 +1,47 @@ +

584. Find Customer Referee

Easy


Table: Customer

+ +
+-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| id          | int     |
+| name        | varchar |
+| referee_id  | int     |
++-------------+---------+
+In SQL, id is the primary key column for this table.
+Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them.
+
+ +

 

+ +

Find the names of the customer that are not referred by the customer with id = 2.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
Input: 
+Customer table:
++----+------+------------+
+| id | name | referee_id |
++----+------+------------+
+| 1  | Will | null       |
+| 2  | Jane | null       |
+| 3  | Alex | 2          |
+| 4  | Bill | null       |
+| 5  | Zack | 1          |
+| 6  | Mark | 2          |
++----+------+------------+
+Output: 
++------+
+| name |
++------+
+| Will |
+| Jane |
+| Bill |
+| Zack |
++------+
+
+
\ No newline at end of file diff --git a/0590-n-ary-tree-postorder-traversal/0590-n-ary-tree-postorder-traversal.py b/problems/0590-n-ary-tree-postorder-traversal/0590-n-ary-tree-postorder-traversal.py similarity index 100% rename from 0590-n-ary-tree-postorder-traversal/0590-n-ary-tree-postorder-traversal.py rename to problems/0590-n-ary-tree-postorder-traversal/0590-n-ary-tree-postorder-traversal.py diff --git a/0590-n-ary-tree-postorder-traversal/NOTES.md b/problems/0590-n-ary-tree-postorder-traversal/NOTES.md similarity index 100% rename from 0590-n-ary-tree-postorder-traversal/NOTES.md rename to problems/0590-n-ary-tree-postorder-traversal/NOTES.md diff --git a/problems/0590-n-ary-tree-postorder-traversal/README.md b/problems/0590-n-ary-tree-postorder-traversal/README.md new file mode 100644 index 000000000..cee6f44dd --- /dev/null +++ b/problems/0590-n-ary-tree-postorder-traversal/README.md @@ -0,0 +1,29 @@ +

590. N-ary Tree Postorder Traversal

Easy


Given the root of an n-ary tree, return the postorder traversal of its nodes' values.

+ +

Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)

+ +

 

+

Example 1:

+ +
Input: root = [1,null,3,2,4,null,5,6]
+Output: [5,6,3,2,4,1]
+
+ +

Example 2:

+ +
Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
+Output: [2,6,14,11,7,3,12,8,4,13,9,10,5,1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [0, 104].
  • +
  • 0 <= Node.val <= 104
  • +
  • The height of the n-ary tree is less than or equal to 1000.
  • +
+ +

 

+

Follow up: Recursive solution is trivial, could you do it iteratively?

+
\ No newline at end of file diff --git a/0592-fraction-addition-and-subtraction/0592-fraction-addition-and-subtraction.py b/problems/0592-fraction-addition-and-subtraction/0592-fraction-addition-and-subtraction.py similarity index 100% rename from 0592-fraction-addition-and-subtraction/0592-fraction-addition-and-subtraction.py rename to problems/0592-fraction-addition-and-subtraction/0592-fraction-addition-and-subtraction.py diff --git a/0592-fraction-addition-and-subtraction/NOTES.md b/problems/0592-fraction-addition-and-subtraction/NOTES.md similarity index 100% rename from 0592-fraction-addition-and-subtraction/NOTES.md rename to problems/0592-fraction-addition-and-subtraction/NOTES.md diff --git a/problems/0592-fraction-addition-and-subtraction/README.md b/problems/0592-fraction-addition-and-subtraction/README.md new file mode 100644 index 000000000..5d1558c52 --- /dev/null +++ b/problems/0592-fraction-addition-and-subtraction/README.md @@ -0,0 +1,34 @@ +

592. Fraction Addition and Subtraction

Medium


Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.

+ +

The final result should be an irreducible fraction. If your final result is an integer, change it to the format of a fraction that has a denominator 1. So in this case, 2 should be converted to 2/1.

+ +

 

+

Example 1:

+ +
Input: expression = "-1/2+1/2"
+Output: "0/1"
+
+ +

Example 2:

+ +
Input: expression = "-1/2+1/2+1/3"
+Output: "1/3"
+
+ +

Example 3:

+ +
Input: expression = "1/3-1/2"
+Output: "-1/6"
+
+ +

 

+

Constraints:

+ +
    +
  • The input string only contains '0' to '9', '/', '+' and '-'. So does the output.
  • +
  • Each fraction (input and output) has the format ±numerator/denominator. If the first input fraction or the output is positive, then '+' will be omitted.
  • +
  • The input only contains valid irreducible fractions, where the numerator and denominator of each fraction will always be in the range [1, 10]. If the denominator is 1, it means this fraction is actually an integer in a fraction format defined above.
  • +
  • The number of given fractions will be in the range [1, 10].
  • +
  • The numerator and denominator of the final result are guaranteed to be valid and in the range of 32-bit int.
  • +
+
\ No newline at end of file diff --git a/0595-big-countries/0595-big-countries.sql b/problems/0595-big-countries/0595-big-countries.sql similarity index 100% rename from 0595-big-countries/0595-big-countries.sql rename to problems/0595-big-countries/0595-big-countries.sql diff --git a/0595-big-countries/NOTES.md b/problems/0595-big-countries/NOTES.md similarity index 100% rename from 0595-big-countries/NOTES.md rename to problems/0595-big-countries/NOTES.md diff --git a/problems/0595-big-countries/README.md b/problems/0595-big-countries/README.md new file mode 100644 index 000000000..b80a49d9b --- /dev/null +++ b/problems/0595-big-countries/README.md @@ -0,0 +1,53 @@ +

595. Big Countries

Easy


Table: World

+ +
+-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| name        | varchar |
+| continent   | varchar |
+| area        | int     |
+| population  | int     |
+| gdp         | bigint  |
++-------------+---------+
+name is the primary key (column with unique values) for this table.
+Each row of this table gives information about the name of a country, the continent to which it belongs, its area, the population, and its GDP value.
+
+ +

 

+ +

A country is big if:

+ +
    +
  • it has an area of at least three million (i.e., 3000000 km2), or
  • +
  • it has a population of at least twenty-five million (i.e., 25000000).
  • +
+ +

Write a solution to find the name, population, and area of the big countries.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
Input: 
+World table:
++-------------+-----------+---------+------------+--------------+
+| name        | continent | area    | population | gdp          |
++-------------+-----------+---------+------------+--------------+
+| Afghanistan | Asia      | 652230  | 25500100   | 20343000000  |
+| Albania     | Europe    | 28748   | 2831741    | 12960000000  |
+| Algeria     | Africa    | 2381741 | 37100000   | 188681000000 |
+| Andorra     | Europe    | 468     | 78115      | 3712000000   |
+| Angola      | Africa    | 1246700 | 20609294   | 100990000000 |
++-------------+-----------+---------+------------+--------------+
+Output: 
++-------------+------------+---------+
+| name        | population | area    |
++-------------+------------+---------+
+| Afghanistan | 25500100   | 652230  |
+| Algeria     | 37100000   | 2381741 |
++-------------+------------+---------+
+
+
\ No newline at end of file diff --git a/0606-construct-string-from-binary-tree/0606-construct-string-from-binary-tree.py b/problems/0606-construct-string-from-binary-tree/0606-construct-string-from-binary-tree.py similarity index 100% rename from 0606-construct-string-from-binary-tree/0606-construct-string-from-binary-tree.py rename to problems/0606-construct-string-from-binary-tree/0606-construct-string-from-binary-tree.py diff --git a/0606-construct-string-from-binary-tree/NOTES.md b/problems/0606-construct-string-from-binary-tree/NOTES.md similarity index 100% rename from 0606-construct-string-from-binary-tree/NOTES.md rename to problems/0606-construct-string-from-binary-tree/NOTES.md diff --git a/problems/0606-construct-string-from-binary-tree/README.md b/problems/0606-construct-string-from-binary-tree/README.md new file mode 100644 index 000000000..d304033ff --- /dev/null +++ b/problems/0606-construct-string-from-binary-tree/README.md @@ -0,0 +1,27 @@ +

606. Construct String from Binary Tree

Easy


Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it.

+ +

Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,4]
+Output: "1(2(4))(3)"
+Explanation: Originally, it needs to be "1(2(4)())(3()())", but you need to omit all the unnecessary empty parenthesis pairs. And it will be "1(2(4))(3)"
+
+ +

Example 2:

+ +
Input: root = [1,2,3,null,4]
+Output: "1(2()(4))(3)"
+Explanation: Almost the same as the first example, except we cannot omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • -1000 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/0617-merge-two-binary-trees/0617-merge-two-binary-trees.cpp b/problems/0617-merge-two-binary-trees/0617-merge-two-binary-trees.cpp similarity index 100% rename from 0617-merge-two-binary-trees/0617-merge-two-binary-trees.cpp rename to problems/0617-merge-two-binary-trees/0617-merge-two-binary-trees.cpp diff --git a/0617-merge-two-binary-trees/NOTES.md b/problems/0617-merge-two-binary-trees/NOTES.md similarity index 100% rename from 0617-merge-two-binary-trees/NOTES.md rename to problems/0617-merge-two-binary-trees/NOTES.md diff --git a/problems/0617-merge-two-binary-trees/README.md b/problems/0617-merge-two-binary-trees/README.md new file mode 100644 index 000000000..0d7c87bb9 --- /dev/null +++ b/problems/0617-merge-two-binary-trees/README.md @@ -0,0 +1,29 @@ +

617. Merge Two Binary Trees

Easy


You are given two binary trees root1 and root2.

+ +

Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree.

+ +

Return the merged tree.

+ +

Note: The merging process must start from the root nodes of both trees.

+ +

 

+

Example 1:

+ +
Input: root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7]
+Output: [3,4,5,5,4,null,7]
+
+ +

Example 2:

+ +
Input: root1 = [1], root2 = [1,2]
+Output: [2,2]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in both trees is in the range [0, 2000].
  • +
  • -104 <= Node.val <= 104
  • +
+
\ No newline at end of file diff --git a/0621-task-scheduler/0621-task-scheduler.py b/problems/0621-task-scheduler/0621-task-scheduler.py similarity index 100% rename from 0621-task-scheduler/0621-task-scheduler.py rename to problems/0621-task-scheduler/0621-task-scheduler.py diff --git a/0621-task-scheduler/NOTES.md b/problems/0621-task-scheduler/NOTES.md similarity index 100% rename from 0621-task-scheduler/NOTES.md rename to problems/0621-task-scheduler/NOTES.md diff --git a/problems/0621-task-scheduler/README.md b/problems/0621-task-scheduler/README.md new file mode 100644 index 000000000..a449ed32f --- /dev/null +++ b/problems/0621-task-scheduler/README.md @@ -0,0 +1,95 @@ +

621. Task Scheduler

Medium


You are given an array of CPU tasks, each represented by letters A to Z, and a cooling time, n. Each cycle or interval allows the completion of one task. Tasks can be completed in any order, but there's a constraint: identical tasks must be separated by at least n intervals due to cooling time.

+ +

​Return the minimum number of intervals required to complete all tasks.

+ +

 

+

Example 1:

+ +
+

Input: tasks = ["A","A","A","B","B","B"], n = 2

+ +

Output: 8

+ +

Explanation: A possible sequence is: A -> B -> idle -> A -> B -> idle -> A -> B.

+ +

After completing task A, you must wait two cycles before doing A again. The same applies to task B. In the 3rd interval, neither A nor B can be done, so you idle. By the 4th cycle, you can do A again as 2 intervals have passed.

+
+ +

Example 2:

+ +
+

Input: tasks = ["A","C","A","B","D","B"], n = 1

+ +

Output: 6

+ +

Explanation: A possible sequence is: A -> B -> C -> D -> A -> B.

+ +

With a cooling interval of 1, you can repeat a task after just one other task.

+
+ +

Example 3:

+ +
+

Input: tasks = ["A","A","A", "B","B","B"], n = 3

+ +

Output: 10

+ +

Explanation: A possible sequence is: A -> B -> idle -> idle -> A -> B -> idle -> idle -> A -> B.

+ +

There are only two types of tasks, A and B, which need to be separated by 3 intervals. This leads to idling twice between repetitions of these tasks.

+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= tasks.length <= 104
  • +
  • tasks[i] is an uppercase English letter.
  • +
  • 0 <= n <= 100
  • +
+
\ No newline at end of file diff --git a/0623-add-one-row-to-tree/0623-add-one-row-to-tree.py b/problems/0623-add-one-row-to-tree/0623-add-one-row-to-tree.py similarity index 100% rename from 0623-add-one-row-to-tree/0623-add-one-row-to-tree.py rename to problems/0623-add-one-row-to-tree/0623-add-one-row-to-tree.py diff --git a/0623-add-one-row-to-tree/NOTES.md b/problems/0623-add-one-row-to-tree/NOTES.md similarity index 100% rename from 0623-add-one-row-to-tree/NOTES.md rename to problems/0623-add-one-row-to-tree/NOTES.md diff --git a/problems/0623-add-one-row-to-tree/README.md b/problems/0623-add-one-row-to-tree/README.md new file mode 100644 index 000000000..c1f4b23ec --- /dev/null +++ b/problems/0623-add-one-row-to-tree/README.md @@ -0,0 +1,37 @@ +

623. Add One Row to Tree

Medium


Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth.

+ +

Note that the root node is at depth 1.

+ +

The adding rule is:

+ +
    +
  • Given the integer depth, for each not null tree node cur at the depth depth - 1, create two tree nodes with value val as cur's left subtree root and right subtree root.
  • +
  • cur's original left subtree should be the left subtree of the new left subtree root.
  • +
  • cur's original right subtree should be the right subtree of the new right subtree root.
  • +
  • If depth == 1 that means there is no depth depth - 1 at all, then create a tree node with value val as the new root of the whole original tree, and the original tree is the new root's left subtree.
  • +
+ +

 

+

Example 1:

+ +
Input: root = [4,2,6,3,1,5], val = 1, depth = 2
+Output: [4,1,1,2,null,null,6,3,1,5]
+
+ +

Example 2:

+ +
Input: root = [4,2,null,3,1], val = 1, depth = 3
+Output: [4,2,null,1,1,3,null,null,1]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • The depth of the tree is in the range [1, 104].
  • +
  • -100 <= Node.val <= 100
  • +
  • -105 <= val <= 105
  • +
  • 1 <= depth <= the depth of tree + 1
  • +
+
\ No newline at end of file diff --git a/0624-maximum-distance-in-arrays/0624-maximum-distance-in-arrays.py b/problems/0624-maximum-distance-in-arrays/0624-maximum-distance-in-arrays.py similarity index 100% rename from 0624-maximum-distance-in-arrays/0624-maximum-distance-in-arrays.py rename to problems/0624-maximum-distance-in-arrays/0624-maximum-distance-in-arrays.py diff --git a/0624-maximum-distance-in-arrays/NOTES.md b/problems/0624-maximum-distance-in-arrays/NOTES.md similarity index 100% rename from 0624-maximum-distance-in-arrays/NOTES.md rename to problems/0624-maximum-distance-in-arrays/NOTES.md diff --git a/problems/0624-maximum-distance-in-arrays/README.md b/problems/0624-maximum-distance-in-arrays/README.md new file mode 100644 index 000000000..77b7a756f --- /dev/null +++ b/problems/0624-maximum-distance-in-arrays/README.md @@ -0,0 +1,32 @@ +

624. Maximum Distance in Arrays

Medium


You are given m arrays, where each array is sorted in ascending order.

+ +

You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|.

+ +

Return the maximum distance.

+ +

 

+

Example 1:

+ +
Input: arrays = [[1,2,3],[4,5],[1,2,3]]
+Output: 4
+Explanation: One way to reach the maximum distance 4 is to pick 1 in the first or third array and pick 5 in the second array.
+
+ +

Example 2:

+ +
Input: arrays = [[1],[1]]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • m == arrays.length
  • +
  • 2 <= m <= 105
  • +
  • 1 <= arrays[i].length <= 500
  • +
  • -104 <= arrays[i][j] <= 104
  • +
  • arrays[i] is sorted in ascending order.
  • +
  • There will be at most 105 integers in all the arrays.
  • +
+
\ No newline at end of file diff --git a/0629-k-inverse-pairs-array/0629-k-inverse-pairs-array.py b/problems/0629-k-inverse-pairs-array/0629-k-inverse-pairs-array.py similarity index 100% rename from 0629-k-inverse-pairs-array/0629-k-inverse-pairs-array.py rename to problems/0629-k-inverse-pairs-array/0629-k-inverse-pairs-array.py diff --git a/0629-k-inverse-pairs-array/NOTES.md b/problems/0629-k-inverse-pairs-array/NOTES.md similarity index 100% rename from 0629-k-inverse-pairs-array/NOTES.md rename to problems/0629-k-inverse-pairs-array/NOTES.md diff --git a/problems/0629-k-inverse-pairs-array/README.md b/problems/0629-k-inverse-pairs-array/README.md new file mode 100644 index 000000000..b9c1e1ffa --- /dev/null +++ b/problems/0629-k-inverse-pairs-array/README.md @@ -0,0 +1,27 @@ +

629. K Inverse Pairs Array

Hard


For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j].

+ +

Given two integers n and k, return the number of different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. Since the answer can be huge, return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 3, k = 0
+Output: 1
+Explanation: Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.
+
+ +

Example 2:

+ +
Input: n = 3, k = 1
+Output: 2
+Explanation: The array [1,3,2] and [2,1,3] have exactly 1 inverse pair.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1000
  • +
  • 0 <= k <= 1000
  • +
+
\ No newline at end of file diff --git a/0633-sum-of-square-numbers/0633-sum-of-square-numbers.py b/problems/0633-sum-of-square-numbers/0633-sum-of-square-numbers.py similarity index 100% rename from 0633-sum-of-square-numbers/0633-sum-of-square-numbers.py rename to problems/0633-sum-of-square-numbers/0633-sum-of-square-numbers.py diff --git a/0633-sum-of-square-numbers/NOTES.md b/problems/0633-sum-of-square-numbers/NOTES.md similarity index 100% rename from 0633-sum-of-square-numbers/NOTES.md rename to problems/0633-sum-of-square-numbers/NOTES.md diff --git a/problems/0633-sum-of-square-numbers/README.md b/problems/0633-sum-of-square-numbers/README.md new file mode 100644 index 000000000..efeadaa1f --- /dev/null +++ b/problems/0633-sum-of-square-numbers/README.md @@ -0,0 +1,23 @@ +

633. Sum of Square Numbers

Medium


Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.

+ +

 

+

Example 1:

+ +
Input: c = 5
+Output: true
+Explanation: 1 * 1 + 2 * 2 = 5
+
+ +

Example 2:

+ +
Input: c = 3
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= c <= 231 - 1
  • +
+
\ No newline at end of file diff --git a/0645-set-mismatch/0645-set-mismatch.py b/problems/0645-set-mismatch/0645-set-mismatch.py similarity index 100% rename from 0645-set-mismatch/0645-set-mismatch.py rename to problems/0645-set-mismatch/0645-set-mismatch.py diff --git a/0645-set-mismatch/NOTES.md b/problems/0645-set-mismatch/NOTES.md similarity index 100% rename from 0645-set-mismatch/NOTES.md rename to problems/0645-set-mismatch/NOTES.md diff --git a/problems/0645-set-mismatch/README.md b/problems/0645-set-mismatch/README.md new file mode 100644 index 000000000..786996129 --- /dev/null +++ b/problems/0645-set-mismatch/README.md @@ -0,0 +1,22 @@ +

645. Set Mismatch

Easy


You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.

+ +

You are given an integer array nums representing the data status of this set after the error.

+ +

Find the number that occurs twice and the number that is missing and return them in the form of an array.

+ +

 

+

Example 1:

+
Input: nums = [1,2,2,4]
+Output: [2,3]
+

Example 2:

+
Input: nums = [1,1]
+Output: [1,2]
+
+

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 104
  • +
  • 1 <= nums[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0646-maximum-length-of-pair-chain/0646-maximum-length-of-pair-chain.py b/problems/0646-maximum-length-of-pair-chain/0646-maximum-length-of-pair-chain.py similarity index 100% rename from 0646-maximum-length-of-pair-chain/0646-maximum-length-of-pair-chain.py rename to problems/0646-maximum-length-of-pair-chain/0646-maximum-length-of-pair-chain.py diff --git a/0646-maximum-length-of-pair-chain/NOTES.md b/problems/0646-maximum-length-of-pair-chain/NOTES.md similarity index 100% rename from 0646-maximum-length-of-pair-chain/NOTES.md rename to problems/0646-maximum-length-of-pair-chain/NOTES.md diff --git a/problems/0646-maximum-length-of-pair-chain/README.md b/problems/0646-maximum-length-of-pair-chain/README.md new file mode 100644 index 000000000..0537ff055 --- /dev/null +++ b/problems/0646-maximum-length-of-pair-chain/README.md @@ -0,0 +1,32 @@ +

646. Maximum Length of Pair Chain

Medium


You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.

+ +

A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.

+ +

Return the length longest chain which can be formed.

+ +

You do not need to use up all the given intervals. You can select pairs in any order.

+ +

 

+

Example 1:

+ +
Input: pairs = [[1,2],[2,3],[3,4]]
+Output: 2
+Explanation: The longest chain is [1,2] -> [3,4].
+
+ +

Example 2:

+ +
Input: pairs = [[1,2],[7,8],[4,5]]
+Output: 3
+Explanation: The longest chain is [1,2] -> [4,5] -> [7,8].
+
+ +

 

+

Constraints:

+ +
    +
  • n == pairs.length
  • +
  • 1 <= n <= 1000
  • +
  • -1000 <= lefti < righti <= 1000
  • +
+
\ No newline at end of file diff --git a/0647-palindromic-substrings/0647-palindromic-substrings.py b/problems/0647-palindromic-substrings/0647-palindromic-substrings.py similarity index 100% rename from 0647-palindromic-substrings/0647-palindromic-substrings.py rename to problems/0647-palindromic-substrings/0647-palindromic-substrings.py diff --git a/0647-palindromic-substrings/NOTES.md b/problems/0647-palindromic-substrings/NOTES.md similarity index 100% rename from 0647-palindromic-substrings/NOTES.md rename to problems/0647-palindromic-substrings/NOTES.md diff --git a/problems/0647-palindromic-substrings/README.md b/problems/0647-palindromic-substrings/README.md new file mode 100644 index 000000000..f833b17ee --- /dev/null +++ b/problems/0647-palindromic-substrings/README.md @@ -0,0 +1,29 @@ +

647. Palindromic Substrings

Medium


Given a string s, return the number of palindromic substrings in it.

+ +

A string is a palindrome when it reads the same backward as forward.

+ +

A substring is a contiguous sequence of characters within the string.

+ +

 

+

Example 1:

+ +
Input: s = "abc"
+Output: 3
+Explanation: Three palindromic strings: "a", "b", "c".
+
+ +

Example 2:

+ +
Input: s = "aaa"
+Output: 6
+Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0648-replace-words/0648-replace-words.py b/problems/0648-replace-words/0648-replace-words.py similarity index 100% rename from 0648-replace-words/0648-replace-words.py rename to problems/0648-replace-words/0648-replace-words.py diff --git a/0648-replace-words/NOTES.md b/problems/0648-replace-words/NOTES.md similarity index 100% rename from 0648-replace-words/NOTES.md rename to problems/0648-replace-words/NOTES.md diff --git a/problems/0648-replace-words/README.md b/problems/0648-replace-words/README.md new file mode 100644 index 000000000..aed11e374 --- /dev/null +++ b/problems/0648-replace-words/README.md @@ -0,0 +1,34 @@ +

648. Replace Words

Medium


In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative. For example, when the root "help" is followed by the word "ful", we can form a derivative "helpful".

+ +

Given a dictionary consisting of many roots and a sentence consisting of words separated by spaces, replace all the derivatives in the sentence with the root forming it. If a derivative can be replaced by more than one root, replace it with the root that has the shortest length.

+ +

Return the sentence after the replacement.

+ +

 

+

Example 1:

+ +
Input: dictionary = ["cat","bat","rat"], sentence = "the cattle was rattled by the battery"
+Output: "the cat was rat by the bat"
+
+ +

Example 2:

+ +
Input: dictionary = ["a","b","c"], sentence = "aadsfasf absbs bbab cadsfafs"
+Output: "a a b c"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= dictionary.length <= 1000
  • +
  • 1 <= dictionary[i].length <= 100
  • +
  • dictionary[i] consists of only lower-case letters.
  • +
  • 1 <= sentence.length <= 106
  • +
  • sentence consists of only lower-case letters and spaces.
  • +
  • The number of words in sentence is in the range [1, 1000]
  • +
  • The length of each word in sentence is in the range [1, 1000]
  • +
  • Every two consecutive words in sentence will be separated by exactly one space.
  • +
  • sentence does not have leading or trailing spaces.
  • +
+
\ No newline at end of file diff --git a/0650-2-keys-keyboard/0650-2-keys-keyboard.py b/problems/0650-2-keys-keyboard/0650-2-keys-keyboard.py similarity index 100% rename from 0650-2-keys-keyboard/0650-2-keys-keyboard.py rename to problems/0650-2-keys-keyboard/0650-2-keys-keyboard.py diff --git a/problems/0650-2-keys-keyboard/README.md b/problems/0650-2-keys-keyboard/README.md new file mode 100644 index 000000000..4d7785490 --- /dev/null +++ b/problems/0650-2-keys-keyboard/README.md @@ -0,0 +1,33 @@ +

650. 2 Keys Keyboard

Medium


There is only one character 'A' on the screen of a notepad. You can perform one of two operations on this notepad for each step:

+ +
    +
  • Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).
  • +
  • Paste: You can paste the characters which are copied last time.
  • +
+ +

Given an integer n, return the minimum number of operations to get the character 'A' exactly n times on the screen.

+ +

 

+

Example 1:

+ +
Input: n = 3
+Output: 3
+Explanation: Initially, we have one character 'A'.
+In step 1, we use Copy All operation.
+In step 2, we use Paste operation to get 'AA'.
+In step 3, we use Paste operation to get 'AAA'.
+
+ +

Example 2:

+ +
Input: n = 1
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1000
  • +
+
\ No newline at end of file diff --git a/0653-two-sum-iv-input-is-a-bst/0653-two-sum-iv-input-is-a-bst.cpp b/problems/0653-two-sum-iv-input-is-a-bst/0653-two-sum-iv-input-is-a-bst.cpp similarity index 100% rename from 0653-two-sum-iv-input-is-a-bst/0653-two-sum-iv-input-is-a-bst.cpp rename to problems/0653-two-sum-iv-input-is-a-bst/0653-two-sum-iv-input-is-a-bst.cpp diff --git a/0653-two-sum-iv-input-is-a-bst/NOTES.md b/problems/0653-two-sum-iv-input-is-a-bst/NOTES.md similarity index 100% rename from 0653-two-sum-iv-input-is-a-bst/NOTES.md rename to problems/0653-two-sum-iv-input-is-a-bst/NOTES.md diff --git a/problems/0653-two-sum-iv-input-is-a-bst/README.md b/problems/0653-two-sum-iv-input-is-a-bst/README.md new file mode 100644 index 000000000..1e202ab42 --- /dev/null +++ b/problems/0653-two-sum-iv-input-is-a-bst/README.md @@ -0,0 +1,25 @@ +

653. Two Sum IV - Input is a BST

Easy


Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.

+ +

 

+

Example 1:

+ +
Input: root = [5,3,6,2,4,null,7], k = 9
+Output: true
+
+ +

Example 2:

+ +
Input: root = [5,3,6,2,4,null,7], k = 28
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • -104 <= Node.val <= 104
  • +
  • root is guaranteed to be a valid binary search tree.
  • +
  • -105 <= k <= 105
  • +
+
\ No newline at end of file diff --git a/0658-find-k-closest-elements/0658-find-k-closest-elements.py b/problems/0658-find-k-closest-elements/0658-find-k-closest-elements.py similarity index 100% rename from 0658-find-k-closest-elements/0658-find-k-closest-elements.py rename to problems/0658-find-k-closest-elements/0658-find-k-closest-elements.py diff --git a/0658-find-k-closest-elements/NOTES.md b/problems/0658-find-k-closest-elements/NOTES.md similarity index 100% rename from 0658-find-k-closest-elements/NOTES.md rename to problems/0658-find-k-closest-elements/NOTES.md diff --git a/0661-image-smoother/0661-image-smoother.py b/problems/0661-image-smoother/0661-image-smoother.py similarity index 100% rename from 0661-image-smoother/0661-image-smoother.py rename to problems/0661-image-smoother/0661-image-smoother.py diff --git a/0661-image-smoother/NOTES.md b/problems/0661-image-smoother/NOTES.md similarity index 100% rename from 0661-image-smoother/NOTES.md rename to problems/0661-image-smoother/NOTES.md diff --git a/problems/0661-image-smoother/README.md b/problems/0661-image-smoother/README.md new file mode 100644 index 000000000..6bd8ee844 --- /dev/null +++ b/problems/0661-image-smoother/README.md @@ -0,0 +1,35 @@ +

661. Image Smoother

Easy


An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the surrounding cells of a cell is not present, we do not consider it in the average (i.e., the average of the four cells in the red smoother).

+ +

Given an m x n integer matrix img representing the grayscale of an image, return the image after applying the smoother on each cell of it.

+ +

 

+

Example 1:

+ +
Input: img = [[1,1,1],[1,0,1],[1,1,1]]
+Output: [[0,0,0],[0,0,0],[0,0,0]]
+Explanation:
+For the points (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0
+For the points (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0
+For the point (1,1): floor(8/9) = floor(0.88888889) = 0
+
+ +

Example 2:

+ +
Input: img = [[100,200,100],[200,50,200],[100,200,100]]
+Output: [[137,141,137],[141,138,141],[137,141,137]]
+Explanation:
+For the points (0,0), (0,2), (2,0), (2,2): floor((100+200+200+50)/4) = floor(137.5) = 137
+For the points (0,1), (1,0), (1,2), (2,1): floor((200+200+50+200+100+100)/6) = floor(141.666667) = 141
+For the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138.888889) = 138
+
+ +

 

+

Constraints:

+ +
    +
  • m == img.length
  • +
  • n == img[i].length
  • +
  • 1 <= m, n <= 200
  • +
  • 0 <= img[i][j] <= 255
  • +
+
\ No newline at end of file diff --git a/0664-strange-printer/0664-strange-printer.py b/problems/0664-strange-printer/0664-strange-printer.py similarity index 100% rename from 0664-strange-printer/0664-strange-printer.py rename to problems/0664-strange-printer/0664-strange-printer.py diff --git a/0664-strange-printer/NOTES.md b/problems/0664-strange-printer/NOTES.md similarity index 100% rename from 0664-strange-printer/NOTES.md rename to problems/0664-strange-printer/NOTES.md diff --git a/problems/0664-strange-printer/README.md b/problems/0664-strange-printer/README.md new file mode 100644 index 000000000..0a0cb3542 --- /dev/null +++ b/problems/0664-strange-printer/README.md @@ -0,0 +1,32 @@ +

664. Strange Printer

Hard


There is a strange printer with the following two special properties:

+ +
    +
  • The printer can only print a sequence of the same character each time.
  • +
  • At each turn, the printer can print new characters starting from and ending at any place and will cover the original existing characters.
  • +
+ +

Given a string s, return the minimum number of turns the printer needed to print it.

+ +

 

+

Example 1:

+ +
Input: s = "aaabbb"
+Output: 2
+Explanation: Print "aaa" first and then print "bbb".
+
+ +

Example 2:

+ +
Input: s = "aba"
+Output: 2
+Explanation: Print "aaa" first and then print "b" from the second place of the string, which will cover the existing character 'a'.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0678-valid-parenthesis-string/0678-valid-parenthesis-string.py b/problems/0678-valid-parenthesis-string/0678-valid-parenthesis-string.py similarity index 100% rename from 0678-valid-parenthesis-string/0678-valid-parenthesis-string.py rename to problems/0678-valid-parenthesis-string/0678-valid-parenthesis-string.py diff --git a/0678-valid-parenthesis-string/NOTES.md b/problems/0678-valid-parenthesis-string/NOTES.md similarity index 100% rename from 0678-valid-parenthesis-string/NOTES.md rename to problems/0678-valid-parenthesis-string/NOTES.md diff --git a/problems/0678-valid-parenthesis-string/README.md b/problems/0678-valid-parenthesis-string/README.md new file mode 100644 index 000000000..26a61d266 --- /dev/null +++ b/problems/0678-valid-parenthesis-string/README.md @@ -0,0 +1,30 @@ +

678. Valid Parenthesis String

Medium


Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid.

+ +

The following rules define a valid string:

+ +
    +
  • Any left parenthesis '(' must have a corresponding right parenthesis ')'.
  • +
  • Any right parenthesis ')' must have a corresponding left parenthesis '('.
  • +
  • Left parenthesis '(' must go before the corresponding right parenthesis ')'.
  • +
  • '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string "".
  • +
+ +

 

+

Example 1:

+
Input: s = "()"
+Output: true
+

Example 2:

+
Input: s = "(*)"
+Output: true
+

Example 3:

+
Input: s = "(*))"
+Output: true
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s[i] is '(', ')' or '*'.
  • +
+
\ No newline at end of file diff --git a/0695-max-area-of-island/0695-max-area-of-island.cpp b/problems/0695-max-area-of-island/0695-max-area-of-island.cpp similarity index 100% rename from 0695-max-area-of-island/0695-max-area-of-island.cpp rename to problems/0695-max-area-of-island/0695-max-area-of-island.cpp diff --git a/0695-max-area-of-island/NOTES.md b/problems/0695-max-area-of-island/NOTES.md similarity index 100% rename from 0695-max-area-of-island/NOTES.md rename to problems/0695-max-area-of-island/NOTES.md diff --git a/problems/0695-max-area-of-island/README.md b/problems/0695-max-area-of-island/README.md new file mode 100644 index 000000000..c31891e0a --- /dev/null +++ b/problems/0695-max-area-of-island/README.md @@ -0,0 +1,30 @@ +

695. Max Area of Island

Medium


You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

+ +

The area of an island is the number of cells with a value 1 in the island.

+ +

Return the maximum area of an island in grid. If there is no island, return 0.

+ +

 

+

Example 1:

+ +
Input: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]
+Output: 6
+Explanation: The answer is not 11, because the island must be connected 4-directionally.
+
+ +

Example 2:

+ +
Input: grid = [[0,0,0,0,0,0,0,0]]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 50
  • +
  • grid[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/0700-search-in-a-binary-search-tree/0700-search-in-a-binary-search-tree.cpp b/problems/0700-search-in-a-binary-search-tree/0700-search-in-a-binary-search-tree.cpp similarity index 100% rename from 0700-search-in-a-binary-search-tree/0700-search-in-a-binary-search-tree.cpp rename to problems/0700-search-in-a-binary-search-tree/0700-search-in-a-binary-search-tree.cpp diff --git a/0700-search-in-a-binary-search-tree/NOTES.md b/problems/0700-search-in-a-binary-search-tree/NOTES.md similarity index 100% rename from 0700-search-in-a-binary-search-tree/NOTES.md rename to problems/0700-search-in-a-binary-search-tree/NOTES.md diff --git a/problems/0700-search-in-a-binary-search-tree/README.md b/problems/0700-search-in-a-binary-search-tree/README.md new file mode 100644 index 000000000..9aa08b2ef --- /dev/null +++ b/problems/0700-search-in-a-binary-search-tree/README.md @@ -0,0 +1,27 @@ +

700. Search in a Binary Search Tree

Easy


You are given the root of a binary search tree (BST) and an integer val.

+ +

Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.

+ +

 

+

Example 1:

+ +
Input: root = [4,2,7,1,3], val = 2
+Output: [2,1,3]
+
+ +

Example 2:

+ +
Input: root = [4,2,7,1,3], val = 5
+Output: []
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 5000].
  • +
  • 1 <= Node.val <= 107
  • +
  • root is a binary search tree.
  • +
  • 1 <= val <= 107
  • +
+
\ No newline at end of file diff --git a/0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp b/problems/0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp similarity index 100% rename from 0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp rename to problems/0701-insert-into-a-binary-search-tree/0701-insert-into-a-binary-search-tree.cpp diff --git a/0701-insert-into-a-binary-search-tree/NOTES.md b/problems/0701-insert-into-a-binary-search-tree/NOTES.md similarity index 100% rename from 0701-insert-into-a-binary-search-tree/NOTES.md rename to problems/0701-insert-into-a-binary-search-tree/NOTES.md diff --git a/problems/0701-insert-into-a-binary-search-tree/README.md b/problems/0701-insert-into-a-binary-search-tree/README.md new file mode 100644 index 000000000..e065dfec4 --- /dev/null +++ b/problems/0701-insert-into-a-binary-search-tree/README.md @@ -0,0 +1,36 @@ +

701. Insert into a Binary Search Tree

Medium


You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.

+ +

Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.

+ +

 

+

Example 1:

+ +
Input: root = [4,2,7,1,3], val = 5
+Output: [4,2,7,1,3,5]
+Explanation: Another accepted tree is:
+
+
+ +

Example 2:

+ +
Input: root = [40,20,60,10,30,50,70], val = 25
+Output: [40,20,60,10,30,50,70,null,null,25]
+
+ +

Example 3:

+ +
Input: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5
+Output: [4,2,7,1,3,5]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree will be in the range [0, 104].
  • +
  • -108 <= Node.val <= 108
  • +
  • All the values Node.val are unique.
  • +
  • -108 <= val <= 108
  • +
  • It's guaranteed that val does not exist in the original BST.
  • +
+
\ No newline at end of file diff --git a/0703-kth-largest-element-in-a-stream/0703-kth-largest-element-in-a-stream.py b/problems/0703-kth-largest-element-in-a-stream/0703-kth-largest-element-in-a-stream.py similarity index 100% rename from 0703-kth-largest-element-in-a-stream/0703-kth-largest-element-in-a-stream.py rename to problems/0703-kth-largest-element-in-a-stream/0703-kth-largest-element-in-a-stream.py diff --git a/0703-kth-largest-element-in-a-stream/NOTES.md b/problems/0703-kth-largest-element-in-a-stream/NOTES.md similarity index 100% rename from 0703-kth-largest-element-in-a-stream/NOTES.md rename to problems/0703-kth-largest-element-in-a-stream/NOTES.md diff --git a/problems/0703-kth-largest-element-in-a-stream/README.md b/problems/0703-kth-largest-element-in-a-stream/README.md new file mode 100644 index 000000000..009d56ff9 --- /dev/null +++ b/problems/0703-kth-largest-element-in-a-stream/README.md @@ -0,0 +1,39 @@ +

703. Kth Largest Element in a Stream

Easy


Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.

+ +

Implement KthLargest class:

+ +
    +
  • KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums.
  • +
  • int add(int val) Appends the integer val to the stream and returns the element representing the kth largest element in the stream.
  • +
+ +

 

+

Example 1:

+ +
Input
+["KthLargest", "add", "add", "add", "add", "add"]
+[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]
+Output
+[null, 4, 5, 5, 8, 8]
+
+Explanation
+KthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);
+kthLargest.add(3);   // return 4
+kthLargest.add(5);   // return 5
+kthLargest.add(10);  // return 5
+kthLargest.add(9);   // return 8
+kthLargest.add(4);   // return 8
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= 104
  • +
  • 0 <= nums.length <= 104
  • +
  • -104 <= nums[i] <= 104
  • +
  • -104 <= val <= 104
  • +
  • At most 104 calls will be made to add.
  • +
  • It is guaranteed that there will be at least k elements in the array when you search for the kth element.
  • +
+
\ No newline at end of file diff --git a/0704-binary-search/0704-binary-search.cpp b/problems/0704-binary-search/0704-binary-search.cpp similarity index 100% rename from 0704-binary-search/0704-binary-search.cpp rename to problems/0704-binary-search/0704-binary-search.cpp diff --git a/0704-binary-search/0704-binary-search.js b/problems/0704-binary-search/0704-binary-search.js similarity index 100% rename from 0704-binary-search/0704-binary-search.js rename to problems/0704-binary-search/0704-binary-search.js diff --git a/0704-binary-search/0704-binary-search.py b/problems/0704-binary-search/0704-binary-search.py similarity index 100% rename from 0704-binary-search/0704-binary-search.py rename to problems/0704-binary-search/0704-binary-search.py diff --git a/0704-binary-search/NOTES.md b/problems/0704-binary-search/NOTES.md similarity index 100% rename from 0704-binary-search/NOTES.md rename to problems/0704-binary-search/NOTES.md diff --git a/problems/0704-binary-search/README.md b/problems/0704-binary-search/README.md new file mode 100644 index 000000000..2a0b66375 --- /dev/null +++ b/problems/0704-binary-search/README.md @@ -0,0 +1,29 @@ +

704. Binary Search

Easy


Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

+ +

You must write an algorithm with O(log n) runtime complexity.

+ +

 

+

Example 1:

+ +
Input: nums = [-1,0,3,5,9,12], target = 9
+Output: 4
+Explanation: 9 exists in nums and its index is 4
+
+ +

Example 2:

+ +
Input: nums = [-1,0,3,5,9,12], target = 2
+Output: -1
+Explanation: 2 does not exist in nums so return -1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 104
  • +
  • -104 < nums[i], target < 104
  • +
  • All the integers in nums are unique.
  • +
  • nums is sorted in ascending order.
  • +
+
\ No newline at end of file diff --git a/0706-design-hashmap/0706-design-hashmap.cpp b/problems/0706-design-hashmap/0706-design-hashmap.cpp similarity index 100% rename from 0706-design-hashmap/0706-design-hashmap.cpp rename to problems/0706-design-hashmap/0706-design-hashmap.cpp diff --git a/0706-design-hashmap/0706-design-hashmap.py b/problems/0706-design-hashmap/0706-design-hashmap.py similarity index 100% rename from 0706-design-hashmap/0706-design-hashmap.py rename to problems/0706-design-hashmap/0706-design-hashmap.py diff --git a/0706-design-hashmap/NOTES.md b/problems/0706-design-hashmap/NOTES.md similarity index 100% rename from 0706-design-hashmap/NOTES.md rename to problems/0706-design-hashmap/NOTES.md diff --git a/problems/0706-design-hashmap/README.md b/problems/0706-design-hashmap/README.md new file mode 100644 index 000000000..830381e2a --- /dev/null +++ b/problems/0706-design-hashmap/README.md @@ -0,0 +1,40 @@ +

706. Design HashMap

Easy


Design a HashMap without using any built-in hash table libraries.

+ +

Implement the MyHashMap class:

+ +
    +
  • MyHashMap() initializes the object with an empty map.
  • +
  • void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.
  • +
  • int get(int key) returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.
  • +
  • void remove(key) removes the key and its corresponding value if the map contains the mapping for the key.
  • +
+ +

 

+

Example 1:

+ +
Input
+["MyHashMap", "put", "put", "get", "get", "put", "get", "remove", "get"]
+[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]
+Output
+[null, null, null, 1, -1, null, 1, null, -1]
+
+Explanation
+MyHashMap myHashMap = new MyHashMap();
+myHashMap.put(1, 1); // The map is now [[1,1]]
+myHashMap.put(2, 2); // The map is now [[1,1], [2,2]]
+myHashMap.get(1);    // return 1, The map is now [[1,1], [2,2]]
+myHashMap.get(3);    // return -1 (i.e., not found), The map is now [[1,1], [2,2]]
+myHashMap.put(2, 1); // The map is now [[1,1], [2,1]] (i.e., update the existing value)
+myHashMap.get(2);    // return 1, The map is now [[1,1], [2,1]]
+myHashMap.remove(2); // remove the mapping for 2, The map is now [[1,1]]
+myHashMap.get(2);    // return -1 (i.e., not found), The map is now [[1,1]]
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= key, value <= 106
  • +
  • At most 104 calls will be made to put, get, and remove.
  • +
+
\ No newline at end of file diff --git a/0712-minimum-ascii-delete-sum-for-two-strings/0712-minimum-ascii-delete-sum-for-two-strings.py b/problems/0712-minimum-ascii-delete-sum-for-two-strings/0712-minimum-ascii-delete-sum-for-two-strings.py similarity index 100% rename from 0712-minimum-ascii-delete-sum-for-two-strings/0712-minimum-ascii-delete-sum-for-two-strings.py rename to problems/0712-minimum-ascii-delete-sum-for-two-strings/0712-minimum-ascii-delete-sum-for-two-strings.py diff --git a/0712-minimum-ascii-delete-sum-for-two-strings/NOTES.md b/problems/0712-minimum-ascii-delete-sum-for-two-strings/NOTES.md similarity index 100% rename from 0712-minimum-ascii-delete-sum-for-two-strings/NOTES.md rename to problems/0712-minimum-ascii-delete-sum-for-two-strings/NOTES.md diff --git a/problems/0712-minimum-ascii-delete-sum-for-two-strings/README.md b/problems/0712-minimum-ascii-delete-sum-for-two-strings/README.md new file mode 100644 index 000000000..4bc11e8d3 --- /dev/null +++ b/problems/0712-minimum-ascii-delete-sum-for-two-strings/README.md @@ -0,0 +1,31 @@ +

712. Minimum ASCII Delete Sum for Two Strings

Medium


Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal.

+ +

 

+

Example 1:

+ +
Input: s1 = "sea", s2 = "eat"
+Output: 231
+Explanation: Deleting "s" from "sea" adds the ASCII value of "s" (115) to the sum.
+Deleting "t" from "eat" adds 116 to the sum.
+At the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.
+
+ +

Example 2:

+ +
Input: s1 = "delete", s2 = "leet"
+Output: 403
+Explanation: Deleting "dee" from "delete" to turn the string into "let",
+adds 100[d] + 101[e] + 101[e] to the sum.
+Deleting "e" from "leet" adds 101[e] to the sum.
+At the end, both strings are equal to "let", and the answer is 100+101+101+101 = 403.
+If instead we turned both strings into "lee" or "eet", we would get answers of 433 or 417, which are higher.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s1.length, s2.length <= 1000
  • +
  • s1 and s2 consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0713-subarray-product-less-than-k/0713-subarray-product-less-than-k.py b/problems/0713-subarray-product-less-than-k/0713-subarray-product-less-than-k.py similarity index 100% rename from 0713-subarray-product-less-than-k/0713-subarray-product-less-than-k.py rename to problems/0713-subarray-product-less-than-k/0713-subarray-product-less-than-k.py diff --git a/0713-subarray-product-less-than-k/NOTES.md b/problems/0713-subarray-product-less-than-k/NOTES.md similarity index 100% rename from 0713-subarray-product-less-than-k/NOTES.md rename to problems/0713-subarray-product-less-than-k/NOTES.md diff --git a/problems/0713-subarray-product-less-than-k/README.md b/problems/0713-subarray-product-less-than-k/README.md new file mode 100644 index 000000000..92b81e11f --- /dev/null +++ b/problems/0713-subarray-product-less-than-k/README.md @@ -0,0 +1,27 @@ +

713. Subarray Product Less Than K

Medium


Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.

+ +

 

+

Example 1:

+ +
Input: nums = [10,5,2,6], k = 100
+Output: 8
+Explanation: The 8 subarrays that have product less than 100 are:
+[10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]
+Note that [10, 5, 2] is not included as the product of 100 is not strictly less than k.
+
+ +

Example 2:

+ +
Input: nums = [1,2,3], k = 0
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • 1 <= nums[i] <= 1000
  • +
  • 0 <= k <= 106
  • +
+
\ No newline at end of file diff --git a/0719-find-k-th-smallest-pair-distance/0719-find-k-th-smallest-pair-distance.py b/problems/0719-find-k-th-smallest-pair-distance/0719-find-k-th-smallest-pair-distance.py similarity index 100% rename from 0719-find-k-th-smallest-pair-distance/0719-find-k-th-smallest-pair-distance.py rename to problems/0719-find-k-th-smallest-pair-distance/0719-find-k-th-smallest-pair-distance.py diff --git a/0719-find-k-th-smallest-pair-distance/NOTES.md b/problems/0719-find-k-th-smallest-pair-distance/NOTES.md similarity index 100% rename from 0719-find-k-th-smallest-pair-distance/NOTES.md rename to problems/0719-find-k-th-smallest-pair-distance/NOTES.md diff --git a/0721-accounts-merge/0721-accounts-merge.py b/problems/0721-accounts-merge/0721-accounts-merge.py similarity index 100% rename from 0721-accounts-merge/0721-accounts-merge.py rename to problems/0721-accounts-merge/0721-accounts-merge.py diff --git a/0721-accounts-merge/NOTES.md b/problems/0721-accounts-merge/NOTES.md similarity index 100% rename from 0721-accounts-merge/NOTES.md rename to problems/0721-accounts-merge/NOTES.md diff --git a/problems/0721-accounts-merge/README.md b/problems/0721-accounts-merge/README.md new file mode 100644 index 000000000..3304916c6 --- /dev/null +++ b/problems/0721-accounts-merge/README.md @@ -0,0 +1,35 @@ +

721. Accounts Merge

Medium


Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account.

+ +

Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.

+ +

After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.

+ +

 

+

Example 1:

+ +
Input: accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
+Output: [["John","john00@mail.com","john_newyork@mail.com","johnsmith@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
+Explanation:
+The first and second John's are the same person as they have the common email "johnsmith@mail.com".
+The third John and Mary are different people as none of their email addresses are used by other accounts.
+We could return these lists in any order, for example the answer [['Mary', 'mary@mail.com'], ['John', 'johnnybravo@mail.com'], 
+['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.
+
+ +

Example 2:

+ +
Input: accounts = [["Gabe","Gabe0@m.co","Gabe3@m.co","Gabe1@m.co"],["Kevin","Kevin3@m.co","Kevin5@m.co","Kevin0@m.co"],["Ethan","Ethan5@m.co","Ethan4@m.co","Ethan0@m.co"],["Hanzo","Hanzo3@m.co","Hanzo1@m.co","Hanzo0@m.co"],["Fern","Fern5@m.co","Fern1@m.co","Fern0@m.co"]]
+Output: [["Ethan","Ethan0@m.co","Ethan4@m.co","Ethan5@m.co"],["Gabe","Gabe0@m.co","Gabe1@m.co","Gabe3@m.co"],["Hanzo","Hanzo0@m.co","Hanzo1@m.co","Hanzo3@m.co"],["Kevin","Kevin0@m.co","Kevin3@m.co","Kevin5@m.co"],["Fern","Fern0@m.co","Fern1@m.co","Fern5@m.co"]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= accounts.length <= 1000
  • +
  • 2 <= accounts[i].length <= 10
  • +
  • 1 <= accounts[i][j].length <= 30
  • +
  • accounts[i][0] consists of English letters.
  • +
  • accounts[i][j] (for j > 0) is a valid email.
  • +
+
\ No newline at end of file diff --git a/0723-candy-crush/0723-candy-crush.py b/problems/0723-candy-crush/0723-candy-crush.py similarity index 100% rename from 0723-candy-crush/0723-candy-crush.py rename to problems/0723-candy-crush/0723-candy-crush.py diff --git a/0723-candy-crush/NOTES.md b/problems/0723-candy-crush/NOTES.md similarity index 100% rename from 0723-candy-crush/NOTES.md rename to problems/0723-candy-crush/NOTES.md diff --git a/problems/0723-candy-crush/README.md b/problems/0723-candy-crush/README.md new file mode 100644 index 000000000..601710668 --- /dev/null +++ b/problems/0723-candy-crush/README.md @@ -0,0 +1,38 @@ +

723. Candy Crush

Medium


This question is about implementing a basic elimination algorithm for Candy Crush.

+ +

Given an m x n integer array board representing the grid of candy where board[i][j] represents the type of candy. A value of board[i][j] == 0 represents that the cell is empty.

+ +

The given board represents the state of the game following the player's move. Now, you need to restore the board to a stable state by crushing candies according to the following rules:

+ +
    +
  • If three or more candies of the same type are adjacent vertically or horizontally, crush them all at the same time - these positions become empty.
  • +
  • After crushing all candies simultaneously, if an empty space on the board has candies on top of itself, then these candies will drop until they hit a candy or bottom at the same time. No new candies will drop outside the top boundary.
  • +
  • After the above steps, there may exist more candies that can be crushed. If so, you need to repeat the above steps.
  • +
  • If there does not exist more candies that can be crushed (i.e., the board is stable), then return the current board.
  • +
+ +

You need to perform the above rules until the board becomes stable, then return the stable board.

+ +

 

+

Example 1:

+ +
Input: board = [[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]]
+Output: [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0,0,113,314],[410,0,0,213,414],[610,211,112,313,614],[710,311,412,613,714],[810,411,512,713,1014]]
+
+ +

Example 2:

+ +
Input: board = [[1,3,5,5,2],[3,4,3,3,1],[3,2,4,5,2],[2,4,4,5,5],[1,4,4,1,1]]
+Output: [[1,3,0,0,0],[3,4,0,5,2],[3,2,0,3,1],[2,4,0,5,2],[1,4,3,1,1]]
+
+ +

 

+

Constraints:

+ +
    +
  • m == board.length
  • +
  • n == board[i].length
  • +
  • 3 <= m, n <= 50
  • +
  • 1 <= board[i][j] <= 2000
  • +
+
\ No newline at end of file diff --git a/0725-split-linked-list-in-parts/0725-split-linked-list-in-parts.py b/problems/0725-split-linked-list-in-parts/0725-split-linked-list-in-parts.py similarity index 100% rename from 0725-split-linked-list-in-parts/0725-split-linked-list-in-parts.py rename to problems/0725-split-linked-list-in-parts/0725-split-linked-list-in-parts.py diff --git a/0725-split-linked-list-in-parts/NOTES.md b/problems/0725-split-linked-list-in-parts/NOTES.md similarity index 100% rename from 0725-split-linked-list-in-parts/NOTES.md rename to problems/0725-split-linked-list-in-parts/NOTES.md diff --git a/problems/0725-split-linked-list-in-parts/README.md b/problems/0725-split-linked-list-in-parts/README.md new file mode 100644 index 000000000..45b552072 --- /dev/null +++ b/problems/0725-split-linked-list-in-parts/README.md @@ -0,0 +1,35 @@ +

725. Split Linked List in Parts

Medium


Given the head of a singly linked list and an integer k, split the linked list into k consecutive linked list parts.

+ +

The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null.

+ +

The parts should be in the order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal to parts occurring later.

+ +

Return an array of the k parts.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3], k = 5
+Output: [[1],[2],[3],[],[]]
+Explanation:
+The first element output[0] has output[0].val = 1, output[0].next = null.
+The last element output[4] is null, but its string representation as a ListNode is [].
+
+ +

Example 2:

+ +
Input: head = [1,2,3,4,5,6,7,8,9,10], k = 3
+Output: [[1,2,3,4],[5,6,7],[8,9,10]]
+Explanation:
+The input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [0, 1000].
  • +
  • 0 <= Node.val <= 1000
  • +
  • 1 <= k <= 50
  • +
+
\ No newline at end of file diff --git a/0726-number-of-atoms/0726-number-of-atoms.py b/problems/0726-number-of-atoms/0726-number-of-atoms.py similarity index 100% rename from 0726-number-of-atoms/0726-number-of-atoms.py rename to problems/0726-number-of-atoms/0726-number-of-atoms.py diff --git a/problems/0726-number-of-atoms/README.md b/problems/0726-number-of-atoms/README.md new file mode 100644 index 000000000..a2aece23a --- /dev/null +++ b/problems/0726-number-of-atoms/README.md @@ -0,0 +1,57 @@ +

726. Number of Atoms

Hard


Given a string formula representing a chemical formula, return the count of each atom.

+ +

The atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.

+ +

One or more digits representing that element's count may follow if the count is greater than 1. If the count is 1, no digits will follow.

+ +
    +
  • For example, "H2O" and "H2O2" are possible, but "H1O2" is impossible.
  • +
+ +

Two formulas are concatenated together to produce another formula.

+ +
    +
  • For example, "H2O2He3Mg4" is also a formula.
  • +
+ +

A formula placed in parentheses, and a count (optionally added) is also a formula.

+ +
    +
  • For example, "(H2O2)" and "(H2O2)3" are formulas.
  • +
+ +

Return the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.

+ +

The test cases are generated so that all the values in the output fit in a 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: formula = "H2O"
+Output: "H2O"
+Explanation: The count of elements are {'H': 2, 'O': 1}.
+
+ +

Example 2:

+ +
Input: formula = "Mg(OH)2"
+Output: "H2MgO2"
+Explanation: The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.
+
+ +

Example 3:

+ +
Input: formula = "K4(ON(SO3)2)2"
+Output: "K4N2O14S4"
+Explanation: The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= formula.length <= 1000
  • +
  • formula consists of English letters, digits, '(', and ')'.
  • +
  • formula is always valid.
  • +
+
\ No newline at end of file diff --git a/0733-flood-fill/0733-flood-fill.cpp b/problems/0733-flood-fill/0733-flood-fill.cpp similarity index 100% rename from 0733-flood-fill/0733-flood-fill.cpp rename to problems/0733-flood-fill/0733-flood-fill.cpp diff --git a/0733-flood-fill/0733-flood-fill.py b/problems/0733-flood-fill/0733-flood-fill.py similarity index 100% rename from 0733-flood-fill/0733-flood-fill.py rename to problems/0733-flood-fill/0733-flood-fill.py diff --git a/0733-flood-fill/NOTES.md b/problems/0733-flood-fill/NOTES.md similarity index 100% rename from 0733-flood-fill/NOTES.md rename to problems/0733-flood-fill/NOTES.md diff --git a/problems/0733-flood-fill/README.md b/problems/0733-flood-fill/README.md new file mode 100644 index 000000000..d3742aa08 --- /dev/null +++ b/problems/0733-flood-fill/README.md @@ -0,0 +1,36 @@ +

733. Flood Fill

Easy


An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image.

+ +

You are also given three integers sr, sc, and color. You should perform a flood fill on the image starting from the pixel image[sr][sc].

+ +

To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color), and so on. Replace the color of all of the aforementioned pixels with color.

+ +

Return the modified image after performing the flood fill.

+ +

 

+

Example 1:

+ +
Input: image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
+Output: [[2,2,2],[2,2,0],[2,0,1]]
+Explanation: From the center of the image with position (sr, sc) = (1, 1) (i.e., the red pixel), all pixels connected by a path of the same color as the starting pixel (i.e., the blue pixels) are colored with the new color.
+Note the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel.
+
+ +

Example 2:

+ +
Input: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
+Output: [[0,0,0],[0,0,0]]
+Explanation: The starting pixel is already colored 0, so no changes are made to the image.
+
+ +

 

+

Constraints:

+ +
    +
  • m == image.length
  • +
  • n == image[i].length
  • +
  • 1 <= m, n <= 50
  • +
  • 0 <= image[i][j], color < 216
  • +
  • 0 <= sr < m
  • +
  • 0 <= sc < n
  • +
+
\ No newline at end of file diff --git a/0739-daily-temperatures/0739-daily-temperatures.py b/problems/0739-daily-temperatures/0739-daily-temperatures.py similarity index 100% rename from 0739-daily-temperatures/0739-daily-temperatures.py rename to problems/0739-daily-temperatures/0739-daily-temperatures.py diff --git a/0739-daily-temperatures/NOTES.md b/problems/0739-daily-temperatures/NOTES.md similarity index 100% rename from 0739-daily-temperatures/NOTES.md rename to problems/0739-daily-temperatures/NOTES.md diff --git a/problems/0739-daily-temperatures/README.md b/problems/0739-daily-temperatures/README.md new file mode 100644 index 000000000..cb144a23b --- /dev/null +++ b/problems/0739-daily-temperatures/README.md @@ -0,0 +1,21 @@ +

739. Daily Temperatures

Medium


Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

+ +

 

+

Example 1:

+
Input: temperatures = [73,74,75,71,69,72,76,73]
+Output: [1,1,4,2,1,1,0,0]
+

Example 2:

+
Input: temperatures = [30,40,50,60]
+Output: [1,1,1,0]
+

Example 3:

+
Input: temperatures = [30,60,90]
+Output: [1,1,0]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= temperatures.length <= 105
  • +
  • 30 <= temperatures[i] <= 100
  • +
+
\ No newline at end of file diff --git a/0741-cherry-pickup/0741-cherry-pickup.py b/problems/0741-cherry-pickup/0741-cherry-pickup.py similarity index 100% rename from 0741-cherry-pickup/0741-cherry-pickup.py rename to problems/0741-cherry-pickup/0741-cherry-pickup.py diff --git a/0741-cherry-pickup/NOTES.md b/problems/0741-cherry-pickup/NOTES.md similarity index 100% rename from 0741-cherry-pickup/NOTES.md rename to problems/0741-cherry-pickup/NOTES.md diff --git a/problems/0741-cherry-pickup/README.md b/problems/0741-cherry-pickup/README.md new file mode 100644 index 000000000..b9ebff137 --- /dev/null +++ b/problems/0741-cherry-pickup/README.md @@ -0,0 +1,46 @@ +

741. Cherry Pickup

Hard


You are given an n x n grid representing a field of cherries, each cell is one of three possible integers.

+ +
    +
  • 0 means the cell is empty, so you can pass through,
  • +
  • 1 means the cell contains a cherry that you can pick up and pass through, or
  • +
  • -1 means the cell contains a thorn that blocks your way.
  • +
+ +

Return the maximum number of cherries you can collect by following the rules below:

+ +
    +
  • Starting at the position (0, 0) and reaching (n - 1, n - 1) by moving right or down through valid path cells (cells with value 0 or 1).
  • +
  • After reaching (n - 1, n - 1), returning to (0, 0) by moving left or up through valid path cells.
  • +
  • When passing through a path cell containing a cherry, you pick it up, and the cell becomes an empty cell 0.
  • +
  • If there is no valid path between (0, 0) and (n - 1, n - 1), then no cherries can be collected.
  • +
+ +

 

+

Example 1:

+ +
Input: grid = [[0,1,-1],[1,0,-1],[1,1,1]]
+Output: 5
+Explanation: The player started at (0, 0) and went down, down, right right to reach (2, 2).
+4 cherries were picked up during this single trip, and the matrix becomes [[0,1,-1],[0,0,-1],[0,0,0]].
+Then, the player went left, up, up, left to return home, picking up one more cherry.
+The total number of cherries picked up is 5, and this is the maximum possible.
+
+ +

Example 2:

+ +
Input: grid = [[1,1,-1],[1,-1,1],[-1,1,1]]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • n == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= n <= 50
  • +
  • grid[i][j] is -1, 0, or 1.
  • +
  • grid[0][0] != -1
  • +
  • grid[n - 1][n - 1] != -1
  • +
+
\ No newline at end of file diff --git a/0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.cpp b/problems/0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.cpp similarity index 100% rename from 0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.cpp rename to problems/0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.cpp diff --git a/0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.py b/problems/0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.py similarity index 100% rename from 0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.py rename to problems/0746-min-cost-climbing-stairs/0746-min-cost-climbing-stairs.py diff --git a/0746-min-cost-climbing-stairs/NOTES.md b/problems/0746-min-cost-climbing-stairs/NOTES.md similarity index 100% rename from 0746-min-cost-climbing-stairs/NOTES.md rename to problems/0746-min-cost-climbing-stairs/NOTES.md diff --git a/problems/0746-min-cost-climbing-stairs/README.md b/problems/0746-min-cost-climbing-stairs/README.md new file mode 100644 index 000000000..c810b720d --- /dev/null +++ b/problems/0746-min-cost-climbing-stairs/README.md @@ -0,0 +1,38 @@ +

746. Min Cost Climbing Stairs

Easy


You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.

+ +

You can either start from the step with index 0, or the step with index 1.

+ +

Return the minimum cost to reach the top of the floor.

+ +

 

+

Example 1:

+ +
Input: cost = [10,15,20]
+Output: 15
+Explanation: You will start at index 1.
+- Pay 15 and climb two steps to reach the top.
+The total cost is 15.
+
+ +

Example 2:

+ +
Input: cost = [1,100,1,1,1,100,1,1,100,1]
+Output: 6
+Explanation: You will start at index 0.
+- Pay 1 and climb two steps to reach index 2.
+- Pay 1 and climb two steps to reach index 4.
+- Pay 1 and climb two steps to reach index 6.
+- Pay 1 and climb one step to reach index 7.
+- Pay 1 and climb two steps to reach index 9.
+- Pay 1 and climb one step to reach the top.
+The total cost is 6.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= cost.length <= 1000
  • +
  • 0 <= cost[i] <= 999
  • +
+
\ No newline at end of file diff --git a/0752-open-the-lock/0752-open-the-lock.py b/problems/0752-open-the-lock/0752-open-the-lock.py similarity index 100% rename from 0752-open-the-lock/0752-open-the-lock.py rename to problems/0752-open-the-lock/0752-open-the-lock.py diff --git a/0752-open-the-lock/NOTES.md b/problems/0752-open-the-lock/NOTES.md similarity index 100% rename from 0752-open-the-lock/NOTES.md rename to problems/0752-open-the-lock/NOTES.md diff --git a/problems/0752-open-the-lock/README.md b/problems/0752-open-the-lock/README.md new file mode 100644 index 000000000..36cb276f0 --- /dev/null +++ b/problems/0752-open-the-lock/README.md @@ -0,0 +1,44 @@ +

752. Open the Lock

Medium


You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning one wheel one slot.

+ +

The lock initially starts at '0000', a string representing the state of the 4 wheels.

+ +

You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it.

+ +

Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.

+ +

 

+

Example 1:

+ +
Input: deadends = ["0201","0101","0102","1212","2002"], target = "0202"
+Output: 6
+Explanation: 
+A sequence of valid moves would be "0000" -> "1000" -> "1100" -> "1200" -> "1201" -> "1202" -> "0202".
+Note that a sequence like "0000" -> "0001" -> "0002" -> "0102" -> "0202" would be invalid,
+because the wheels of the lock become stuck after the display becomes the dead end "0102".
+
+ +

Example 2:

+ +
Input: deadends = ["8888"], target = "0009"
+Output: 1
+Explanation: We can turn the last wheel in reverse to move from "0000" -> "0009".
+
+ +

Example 3:

+ +
Input: deadends = ["8887","8889","8878","8898","8788","8988","7888","9888"], target = "8888"
+Output: -1
+Explanation: We cannot reach the target without getting stuck.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= deadends.length <= 500
  • +
  • deadends[i].length == 4
  • +
  • target.length == 4
  • +
  • target will not be in the list deadends.
  • +
  • target and deadends[i] consist of digits only.
  • +
+
\ No newline at end of file diff --git a/0767-reorganize-string/0767-reorganize-string.py b/problems/0767-reorganize-string/0767-reorganize-string.py similarity index 100% rename from 0767-reorganize-string/0767-reorganize-string.py rename to problems/0767-reorganize-string/0767-reorganize-string.py diff --git a/0767-reorganize-string/NOTES.md b/problems/0767-reorganize-string/NOTES.md similarity index 100% rename from 0767-reorganize-string/NOTES.md rename to problems/0767-reorganize-string/NOTES.md diff --git a/problems/0767-reorganize-string/README.md b/problems/0767-reorganize-string/README.md new file mode 100644 index 000000000..5ae1df969 --- /dev/null +++ b/problems/0767-reorganize-string/README.md @@ -0,0 +1,20 @@ +

767. Reorganize String

Medium


Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

+ +

Return any possible rearrangement of s or return "" if not possible.

+ +

 

+

Example 1:

+
Input: s = "aab"
+Output: "aba"
+

Example 2:

+
Input: s = "aaab"
+Output: ""
+
+

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 500
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/0776-split-bst/0776-split-bst.py b/problems/0776-split-bst/0776-split-bst.py similarity index 100% rename from 0776-split-bst/0776-split-bst.py rename to problems/0776-split-bst/0776-split-bst.py diff --git a/problems/0776-split-bst/README.md b/problems/0776-split-bst/README.md new file mode 100644 index 000000000..429efeeda --- /dev/null +++ b/problems/0776-split-bst/README.md @@ -0,0 +1,27 @@ +

776. Split BST

Medium


Given the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where the first subtree has nodes that are all smaller or equal to the target value, while the second subtree has all nodes that are greater than the target value. It is not necessarily the case that the tree contains a node with the value target.

+ +

Additionally, most of the structure of the original tree should remain. Formally, for any child c with parent p in the original tree, if they are both in the same subtree after the split, then node c should still have the parent p.

+ +

Return an array of the two roots of the two subtrees in order.

+ +

 

+

Example 1:

+ +
Input: root = [4,2,6,1,3,5,7], target = 2
+Output: [[2,1],[4,3,6,null,null,5,7]]
+
+ +

Example 2:

+ +
Input: root = [1], target = 1
+Output: [[1],[]]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 50].
  • +
  • 0 <= Node.val, target <= 1000
  • +
+
\ No newline at end of file diff --git a/0779-k-th-symbol-in-grammar/0779-k-th-symbol-in-grammar.py b/problems/0779-k-th-symbol-in-grammar/0779-k-th-symbol-in-grammar.py similarity index 100% rename from 0779-k-th-symbol-in-grammar/0779-k-th-symbol-in-grammar.py rename to problems/0779-k-th-symbol-in-grammar/0779-k-th-symbol-in-grammar.py diff --git a/0779-k-th-symbol-in-grammar/NOTES.md b/problems/0779-k-th-symbol-in-grammar/NOTES.md similarity index 100% rename from 0779-k-th-symbol-in-grammar/NOTES.md rename to problems/0779-k-th-symbol-in-grammar/NOTES.md diff --git a/problems/0779-k-th-symbol-in-grammar/README.md b/problems/0779-k-th-symbol-in-grammar/README.md new file mode 100644 index 000000000..e3cac27c0 --- /dev/null +++ b/problems/0779-k-th-symbol-in-grammar/README.md @@ -0,0 +1,42 @@ +

779. K-th Symbol in Grammar

Medium


We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.

+ +
    +
  • For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.
  • +
+ +

Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.

+ +

 

+

Example 1:

+ +
Input: n = 1, k = 1
+Output: 0
+Explanation: row 1: 0
+
+ +

Example 2:

+ +
Input: n = 2, k = 1
+Output: 0
+Explanation: 
+row 1: 0
+row 2: 01
+
+ +

Example 3:

+ +
Input: n = 2, k = 2
+Output: 1
+Explanation: 
+row 1: 0
+row 2: 01
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 30
  • +
  • 1 <= k <= 2n - 1
  • +
+
\ No newline at end of file diff --git a/0784-letter-case-permutation/0784-letter-case-permutation.cpp b/problems/0784-letter-case-permutation/0784-letter-case-permutation.cpp similarity index 100% rename from 0784-letter-case-permutation/0784-letter-case-permutation.cpp rename to problems/0784-letter-case-permutation/0784-letter-case-permutation.cpp diff --git a/0784-letter-case-permutation/NOTES.md b/problems/0784-letter-case-permutation/NOTES.md similarity index 100% rename from 0784-letter-case-permutation/NOTES.md rename to problems/0784-letter-case-permutation/NOTES.md diff --git a/problems/0784-letter-case-permutation/README.md b/problems/0784-letter-case-permutation/README.md new file mode 100644 index 000000000..d36160cda --- /dev/null +++ b/problems/0784-letter-case-permutation/README.md @@ -0,0 +1,25 @@ +

784. Letter Case Permutation

Medium


Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string.

+ +

Return a list of all possible strings we could create. Return the output in any order.

+ +

 

+

Example 1:

+ +
Input: s = "a1b2"
+Output: ["a1b2","a1B2","A1b2","A1B2"]
+
+ +

Example 2:

+ +
Input: s = "3z4"
+Output: ["3z4","3Z4"]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 12
  • +
  • s consists of lowercase English letters, uppercase English letters, and digits.
  • +
+
\ No newline at end of file diff --git a/0786-k-th-smallest-prime-fraction/0786-k-th-smallest-prime-fraction.py b/problems/0786-k-th-smallest-prime-fraction/0786-k-th-smallest-prime-fraction.py similarity index 100% rename from 0786-k-th-smallest-prime-fraction/0786-k-th-smallest-prime-fraction.py rename to problems/0786-k-th-smallest-prime-fraction/0786-k-th-smallest-prime-fraction.py diff --git a/problems/0786-k-th-smallest-prime-fraction/README.md b/problems/0786-k-th-smallest-prime-fraction/README.md new file mode 100644 index 000000000..819e01048 --- /dev/null +++ b/problems/0786-k-th-smallest-prime-fraction/README.md @@ -0,0 +1,36 @@ +

786. K-th Smallest Prime Fraction

Medium


You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.

+ +

For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].

+ +

Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].

+ +

 

+

Example 1:

+ +
Input: arr = [1,2,3,5], k = 3
+Output: [2,5]
+Explanation: The fractions to be considered in sorted order are:
+1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.
+The third fraction is 2/5.
+
+ +

Example 2:

+ +
Input: arr = [1,7], k = 1
+Output: [1,7]
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= arr.length <= 1000
  • +
  • 1 <= arr[i] <= 3 * 104
  • +
  • arr[0] == 1
  • +
  • arr[i] is a prime number for i > 0.
  • +
  • All the numbers of arr are unique and sorted in strictly increasing order.
  • +
  • 1 <= k <= arr.length * (arr.length - 1) / 2
  • +
+ +

 

+Follow up: Can you solve the problem with better than O(n2) complexity?
\ No newline at end of file diff --git a/0787-cheapest-flights-within-k-stops/0787-cheapest-flights-within-k-stops.py b/problems/0787-cheapest-flights-within-k-stops/0787-cheapest-flights-within-k-stops.py similarity index 100% rename from 0787-cheapest-flights-within-k-stops/0787-cheapest-flights-within-k-stops.py rename to problems/0787-cheapest-flights-within-k-stops/0787-cheapest-flights-within-k-stops.py diff --git a/0787-cheapest-flights-within-k-stops/NOTES.md b/problems/0787-cheapest-flights-within-k-stops/NOTES.md similarity index 100% rename from 0787-cheapest-flights-within-k-stops/NOTES.md rename to problems/0787-cheapest-flights-within-k-stops/NOTES.md diff --git a/problems/0787-cheapest-flights-within-k-stops/README.md b/problems/0787-cheapest-flights-within-k-stops/README.md new file mode 100644 index 000000000..9bd2c6851 --- /dev/null +++ b/problems/0787-cheapest-flights-within-k-stops/README.md @@ -0,0 +1,48 @@ +

787. Cheapest Flights Within K Stops

Medium


There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi to city toi with cost pricei.

+ +

You are also given three integers src, dst, and k, return the cheapest price from src to dst with at most k stops. If there is no such route, return -1.

+ +

 

+

Example 1:

+ +
Input: n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1
+Output: 700
+Explanation:
+The graph is shown above.
+The optimal path with at most 1 stop from city 0 to 3 is marked in red and has cost 100 + 600 = 700.
+Note that the path through cities [0,1,2,3] is cheaper but is invalid because it uses 2 stops.
+
+ +

Example 2:

+ +
Input: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1
+Output: 200
+Explanation:
+The graph is shown above.
+The optimal path with at most 1 stop from city 0 to 2 is marked in red and has cost 100 + 100 = 200.
+
+ +

Example 3:

+ +
Input: n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0
+Output: 500
+Explanation:
+The graph is shown above.
+The optimal path with no stops from city 0 to 2 is marked in red and has cost 500.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 100
  • +
  • 0 <= flights.length <= (n * (n - 1) / 2)
  • +
  • flights[i].length == 3
  • +
  • 0 <= fromi, toi < n
  • +
  • fromi != toi
  • +
  • 1 <= pricei <= 104
  • +
  • There will not be any multiple flights between two cities.
  • +
  • 0 <= src, dst, k < n
  • +
  • src != dst
  • +
+
\ No newline at end of file diff --git a/0791-custom-sort-string/0791-custom-sort-string.py b/problems/0791-custom-sort-string/0791-custom-sort-string.py similarity index 100% rename from 0791-custom-sort-string/0791-custom-sort-string.py rename to problems/0791-custom-sort-string/0791-custom-sort-string.py diff --git a/problems/0791-custom-sort-string/README.md b/problems/0791-custom-sort-string/README.md new file mode 100644 index 000000000..df4199fed --- /dev/null +++ b/problems/0791-custom-sort-string/README.md @@ -0,0 +1,41 @@ +

791. Custom Sort String

Medium


You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.

+ +

Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.

+ +

Return any permutation of s that satisfies this property.

+ +

 

+

Example 1:

+ +
+

Input: order = "cba", s = "abcd"

+ +

Output: "cbad"

+ +

Explanation: "a", "b", "c" appear in order, so the order of "a", "b", "c" should be "c", "b", and "a".

+ +

Since "d" does not appear in order, it can be at any position in the returned string. "dcba", "cdba", "cbda" are also valid outputs.

+
+ +

Example 2:

+ +
+

Input: order = "bcafg", s = "abcd"

+ +

Output: "bcad"

+ +

Explanation: The characters "b", "c", and "a" from order dictate the order for the characters in s. The character "d" in s does not appear in order, so its position is flexible.

+ +

Following the order of appearance in order, "b", "c", and "a" from s should be arranged as "b", "c", "a". "d" can be placed at any position since it's not in order. The output "bcad" correctly follows this rule. Other arrangements like "bacd" or "bcda" would also be valid, as long as "b", "c", "a" maintain their order.

+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= order.length <= 26
  • +
  • 1 <= s.length <= 200
  • +
  • order and s consist of lowercase English letters.
  • +
  • All the characters of order are unique.
  • +
+
\ No newline at end of file diff --git a/0799-champagne-tower/0799-champagne-tower.py b/problems/0799-champagne-tower/0799-champagne-tower.py similarity index 100% rename from 0799-champagne-tower/0799-champagne-tower.py rename to problems/0799-champagne-tower/0799-champagne-tower.py diff --git a/0799-champagne-tower/NOTES.md b/problems/0799-champagne-tower/NOTES.md similarity index 100% rename from 0799-champagne-tower/NOTES.md rename to problems/0799-champagne-tower/NOTES.md diff --git a/problems/0799-champagne-tower/README.md b/problems/0799-champagne-tower/README.md new file mode 100644 index 000000000..0452bb32d --- /dev/null +++ b/problems/0799-champagne-tower/README.md @@ -0,0 +1,38 @@ +

799. Champagne Tower

Medium


We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row.  Each glass holds one cup of champagne.

+ +

Then, some champagne is poured into the first glass at the top.  When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.  When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.  (A glass at the bottom row has its excess champagne fall on the floor.)

+ +

For example, after one cup of champagne is poured, the top most glass is full.  After two cups of champagne are poured, the two glasses on the second row are half full.  After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.  After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.

+ +

+ +

Now after pouring some non-negative integer cups of champagne, return how full the jth glass in the ith row is (both i and j are 0-indexed.)

+ +

 

+

Example 1:

+ +
Input: poured = 1, query_row = 1, query_glass = 1
+Output: 0.00000
+Explanation: We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.
+
+ +

Example 2:

+ +
Input: poured = 2, query_row = 1, query_glass = 1
+Output: 0.50000
+Explanation: We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.
+
+ +

Example 3:

+ +
Input: poured = 100000009, query_row = 33, query_glass = 17
+Output: 1.00000
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= poured <= 109
  • +
  • 0 <= query_glass <= query_row < 100
  • +
\ No newline at end of file diff --git a/0808-soup-servings/0808-soup-servings.py b/problems/0808-soup-servings/0808-soup-servings.py similarity index 100% rename from 0808-soup-servings/0808-soup-servings.py rename to problems/0808-soup-servings/0808-soup-servings.py diff --git a/0808-soup-servings/NOTES.md b/problems/0808-soup-servings/NOTES.md similarity index 100% rename from 0808-soup-servings/NOTES.md rename to problems/0808-soup-servings/NOTES.md diff --git a/problems/0808-soup-servings/README.md b/problems/0808-soup-servings/README.md new file mode 100644 index 000000000..d4e862af9 --- /dev/null +++ b/problems/0808-soup-servings/README.md @@ -0,0 +1,39 @@ +

808. Soup Servings

Medium


There are two types of soup: type A and type B. Initially, we have n ml of each type of soup. There are four kinds of operations:

+ +
    +
  1. Serve 100 ml of soup A and 0 ml of soup B,
  2. +
  3. Serve 75 ml of soup A and 25 ml of soup B,
  4. +
  5. Serve 50 ml of soup A and 50 ml of soup B, and
  6. +
  7. Serve 25 ml of soup A and 75 ml of soup B.
  8. +
+ +

When we serve some soup, we give it to someone, and we no longer have it. Each turn, we will choose from the four operations with an equal probability 0.25. If the remaining volume of soup is not enough to complete the operation, we will serve as much as possible. We stop once we no longer have some quantity of both types of soup.

+ +

Note that we do not have an operation where all 100 ml's of soup B are used first.

+ +

Return the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time. Answers within 10-5 of the actual answer will be accepted.

+ +

 

+

Example 1:

+ +
Input: n = 50
+Output: 0.62500
+Explanation: If we choose the first two operations, A will become empty first.
+For the third operation, A and B will become empty at the same time.
+For the fourth operation, B will become empty first.
+So the total probability of A becoming empty first plus half the probability that A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.
+
+ +

Example 2:

+ +
Input: n = 100
+Output: 0.71875
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= n <= 109
  • +
+
\ No newline at end of file diff --git a/0815-bus-routes/0815-bus-routes.py b/problems/0815-bus-routes/0815-bus-routes.py similarity index 100% rename from 0815-bus-routes/0815-bus-routes.py rename to problems/0815-bus-routes/0815-bus-routes.py diff --git a/0815-bus-routes/NOTES.md b/problems/0815-bus-routes/NOTES.md similarity index 100% rename from 0815-bus-routes/NOTES.md rename to problems/0815-bus-routes/NOTES.md diff --git a/problems/0815-bus-routes/README.md b/problems/0815-bus-routes/README.md new file mode 100644 index 000000000..f4a23892b --- /dev/null +++ b/problems/0815-bus-routes/README.md @@ -0,0 +1,36 @@ +

815. Bus Routes

Hard


You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever.

+ +
    +
  • For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ... forever.
  • +
+ +

You will start at the bus stop source (You are not on any bus initially), and you want to go to the bus stop target. You can travel between bus stops by buses only.

+ +

Return the least number of buses you must take to travel from source to target. Return -1 if it is not possible.

+ +

 

+

Example 1:

+ +
Input: routes = [[1,2,7],[3,6,7]], source = 1, target = 6
+Output: 2
+Explanation: The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.
+
+ +

Example 2:

+ +
Input: routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12
+Output: -1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= routes.length <= 500.
  • +
  • 1 <= routes[i].length <= 105
  • +
  • All the values of routes[i] are unique.
  • +
  • sum(routes[i].length) <= 105
  • +
  • 0 <= routes[i][j] < 106
  • +
  • 0 <= source, target < 106
  • +
+
\ No newline at end of file diff --git a/0823-binary-trees-with-factors/0823-binary-trees-with-factors.py b/problems/0823-binary-trees-with-factors/0823-binary-trees-with-factors.py similarity index 100% rename from 0823-binary-trees-with-factors/0823-binary-trees-with-factors.py rename to problems/0823-binary-trees-with-factors/0823-binary-trees-with-factors.py diff --git a/0823-binary-trees-with-factors/NOTES.md b/problems/0823-binary-trees-with-factors/NOTES.md similarity index 100% rename from 0823-binary-trees-with-factors/NOTES.md rename to problems/0823-binary-trees-with-factors/NOTES.md diff --git a/problems/0823-binary-trees-with-factors/README.md b/problems/0823-binary-trees-with-factors/README.md new file mode 100644 index 000000000..af1c0af62 --- /dev/null +++ b/problems/0823-binary-trees-with-factors/README.md @@ -0,0 +1,28 @@ +

823. Binary Trees With Factors

Medium


Given an array of unique integers, arr, where each integer arr[i] is strictly greater than 1.

+ +

We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of its children.

+ +

Return the number of binary trees we can make. The answer may be too large so return the answer modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: arr = [2,4]
+Output: 3
+Explanation: We can make these trees: [2], [4], [4, 2, 2]
+ +

Example 2:

+ +
Input: arr = [2,4,5,10]
+Output: 7
+Explanation: We can make these trees: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 1000
  • +
  • 2 <= arr[i] <= 109
  • +
  • All the values of arr are unique.
  • +
+
\ No newline at end of file diff --git a/0826-most-profit-assigning-work/0826-most-profit-assigning-work.py b/problems/0826-most-profit-assigning-work/0826-most-profit-assigning-work.py similarity index 100% rename from 0826-most-profit-assigning-work/0826-most-profit-assigning-work.py rename to problems/0826-most-profit-assigning-work/0826-most-profit-assigning-work.py diff --git a/0826-most-profit-assigning-work/NOTES.md b/problems/0826-most-profit-assigning-work/NOTES.md similarity index 100% rename from 0826-most-profit-assigning-work/NOTES.md rename to problems/0826-most-profit-assigning-work/NOTES.md diff --git a/problems/0826-most-profit-assigning-work/README.md b/problems/0826-most-profit-assigning-work/README.md new file mode 100644 index 000000000..150af98dc --- /dev/null +++ b/problems/0826-most-profit-assigning-work/README.md @@ -0,0 +1,40 @@ +

826. Most Profit Assigning Work

Medium


You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where:

+ +
    +
  • difficulty[i] and profit[i] are the difficulty and the profit of the ith job, and
  • +
  • worker[j] is the ability of jth worker (i.e., the jth worker can only complete a job with difficulty at most worker[j]).
  • +
+ +

Every worker can be assigned at most one job, but one job can be completed multiple times.

+ +
    +
  • For example, if three workers attempt the same job that pays $1, then the total profit will be $3. If a worker cannot complete any job, their profit is $0.
  • +
+ +

Return the maximum profit we can achieve after assigning the workers to the jobs.

+ +

 

+

Example 1:

+ +
Input: difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]
+Output: 100
+Explanation: Workers are assigned jobs of difficulty [4,4,6,6] and they get a profit of [20,20,30,30] separately.
+
+ +

Example 2:

+ +
Input: difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • n == difficulty.length
  • +
  • n == profit.length
  • +
  • m == worker.length
  • +
  • 1 <= n, m <= 104
  • +
  • 1 <= difficulty[i], profit[i], worker[i] <= 105
  • +
+
\ No newline at end of file diff --git a/0834-sum-of-distances-in-tree/0834-sum-of-distances-in-tree.py b/problems/0834-sum-of-distances-in-tree/0834-sum-of-distances-in-tree.py similarity index 100% rename from 0834-sum-of-distances-in-tree/0834-sum-of-distances-in-tree.py rename to problems/0834-sum-of-distances-in-tree/0834-sum-of-distances-in-tree.py diff --git a/0834-sum-of-distances-in-tree/NOTES.md b/problems/0834-sum-of-distances-in-tree/NOTES.md similarity index 100% rename from 0834-sum-of-distances-in-tree/NOTES.md rename to problems/0834-sum-of-distances-in-tree/NOTES.md diff --git a/problems/0834-sum-of-distances-in-tree/README.md b/problems/0834-sum-of-distances-in-tree/README.md new file mode 100644 index 000000000..1393c3ede --- /dev/null +++ b/problems/0834-sum-of-distances-in-tree/README.md @@ -0,0 +1,41 @@ +

834. Sum of Distances in Tree

Hard


There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.

+ +

You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.

+ +

Return an array answer of length n where answer[i] is the sum of the distances between the ith node in the tree and all other nodes.

+ +

 

+

Example 1:

+ +
Input: n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]
+Output: [8,12,6,10,10,10]
+Explanation: The tree is shown above.
+We can see that dist(0,1) + dist(0,2) + dist(0,3) + dist(0,4) + dist(0,5)
+equals 1 + 1 + 2 + 2 + 2 = 8.
+Hence, answer[0] = 8, and so on.
+
+ +

Example 2:

+ +
Input: n = 1, edges = []
+Output: [0]
+
+ +

Example 3:

+ +
Input: n = 2, edges = [[1,0]]
+Output: [1,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 3 * 104
  • +
  • edges.length == n - 1
  • +
  • edges[i].length == 2
  • +
  • 0 <= ai, bi < n
  • +
  • ai != bi
  • +
  • The given input represents a valid tree.
  • +
+
\ No newline at end of file diff --git a/0840-magic-squares-in-grid/0840-magic-squares-in-grid.py b/problems/0840-magic-squares-in-grid/0840-magic-squares-in-grid.py similarity index 100% rename from 0840-magic-squares-in-grid/0840-magic-squares-in-grid.py rename to problems/0840-magic-squares-in-grid/0840-magic-squares-in-grid.py diff --git a/0840-magic-squares-in-grid/NOTES.md b/problems/0840-magic-squares-in-grid/NOTES.md similarity index 100% rename from 0840-magic-squares-in-grid/NOTES.md rename to problems/0840-magic-squares-in-grid/NOTES.md diff --git a/problems/0840-magic-squares-in-grid/README.md b/problems/0840-magic-squares-in-grid/README.md new file mode 100644 index 000000000..06ddc8d22 --- /dev/null +++ b/problems/0840-magic-squares-in-grid/README.md @@ -0,0 +1,35 @@ +

840. Magic Squares In Grid

Medium


A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.

+ +

Given a row x col grid of integers, how many 3 x 3 contiguous magic square subgrids are there?

+ +

Note: while a magic square can only contain numbers from 1 to 9, grid may contain numbers up to 15.

+ +

 

+

Example 1:

+ +
Input: grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]]
+Output: 1
+Explanation: 
+The following subgrid is a 3 x 3 magic square:
+
+while this one is not:
+
+In total, there is only one magic square inside the given grid.
+
+ +

Example 2:

+ +
Input: grid = [[8]]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • row == grid.length
  • +
  • col == grid[i].length
  • +
  • 1 <= row, col <= 10
  • +
  • 0 <= grid[i][j] <= 15
  • +
+
\ No newline at end of file diff --git a/0844-backspace-string-compare/0844-backspace-string-compare.py b/problems/0844-backspace-string-compare/0844-backspace-string-compare.py similarity index 100% rename from 0844-backspace-string-compare/0844-backspace-string-compare.py rename to problems/0844-backspace-string-compare/0844-backspace-string-compare.py diff --git a/0844-backspace-string-compare/NOTES.md b/problems/0844-backspace-string-compare/NOTES.md similarity index 100% rename from 0844-backspace-string-compare/NOTES.md rename to problems/0844-backspace-string-compare/NOTES.md diff --git a/problems/0844-backspace-string-compare/README.md b/problems/0844-backspace-string-compare/README.md new file mode 100644 index 000000000..7b43fce18 --- /dev/null +++ b/problems/0844-backspace-string-compare/README.md @@ -0,0 +1,37 @@ +

844. Backspace String Compare

Easy


Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

+ +

Note that after backspacing an empty text, the text will continue empty.

+ +

 

+

Example 1:

+ +
Input: s = "ab#c", t = "ad#c"
+Output: true
+Explanation: Both s and t become "ac".
+
+ +

Example 2:

+ +
Input: s = "ab##", t = "c#d#"
+Output: true
+Explanation: Both s and t become "".
+
+ +

Example 3:

+ +
Input: s = "a#c", t = "b"
+Output: false
+Explanation: s becomes "c" while t becomes "b".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length, t.length <= 200
  • +
  • s and t only contain lowercase letters and '#' characters.
  • +
+ +

 

+

Follow up: Can you solve it in O(n) time and O(1) space?

+
\ No newline at end of file diff --git a/0846-hand-of-straights/0846-hand-of-straights.py b/problems/0846-hand-of-straights/0846-hand-of-straights.py similarity index 100% rename from 0846-hand-of-straights/0846-hand-of-straights.py rename to problems/0846-hand-of-straights/0846-hand-of-straights.py diff --git a/0846-hand-of-straights/NOTES.md b/problems/0846-hand-of-straights/NOTES.md similarity index 100% rename from 0846-hand-of-straights/NOTES.md rename to problems/0846-hand-of-straights/NOTES.md diff --git a/problems/0846-hand-of-straights/README.md b/problems/0846-hand-of-straights/README.md new file mode 100644 index 000000000..fe6ec095e --- /dev/null +++ b/problems/0846-hand-of-straights/README.md @@ -0,0 +1,32 @@ +

846. Hand of Straights

Medium


Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards.

+ +

Given an integer array hand where hand[i] is the value written on the ith card and an integer groupSize, return true if she can rearrange the cards, or false otherwise.

+ +

 

+

Example 1:

+ +
Input: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3
+Output: true
+Explanation: Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]
+
+ +

Example 2:

+ +
Input: hand = [1,2,3,4,5], groupSize = 4
+Output: false
+Explanation: Alice's hand can not be rearranged into groups of 4.
+
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= hand.length <= 104
  • +
  • 0 <= hand[i] <= 109
  • +
  • 1 <= groupSize <= hand.length
  • +
+ +

 

+

Note: This question is the same as 1296: https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/

+
\ No newline at end of file diff --git a/0847-shortest-path-visiting-all-nodes/0847-shortest-path-visiting-all-nodes.py b/problems/0847-shortest-path-visiting-all-nodes/0847-shortest-path-visiting-all-nodes.py similarity index 100% rename from 0847-shortest-path-visiting-all-nodes/0847-shortest-path-visiting-all-nodes.py rename to problems/0847-shortest-path-visiting-all-nodes/0847-shortest-path-visiting-all-nodes.py diff --git a/0847-shortest-path-visiting-all-nodes/NOTES.md b/problems/0847-shortest-path-visiting-all-nodes/NOTES.md similarity index 100% rename from 0847-shortest-path-visiting-all-nodes/NOTES.md rename to problems/0847-shortest-path-visiting-all-nodes/NOTES.md diff --git a/problems/0847-shortest-path-visiting-all-nodes/README.md b/problems/0847-shortest-path-visiting-all-nodes/README.md new file mode 100644 index 000000000..16ac110c2 --- /dev/null +++ b/problems/0847-shortest-path-visiting-all-nodes/README.md @@ -0,0 +1,31 @@ +

847. Shortest Path Visiting All Nodes

Hard


You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.

+ +

Return the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple times, and you may reuse edges.

+ +

 

+

Example 1:

+ +
Input: graph = [[1,2,3],[0],[0],[0]]
+Output: 4
+Explanation: One possible path is [1,0,2,0,3]
+
+ +

Example 2:

+ +
Input: graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]
+Output: 4
+Explanation: One possible path is [0,1,4,2,3]
+
+ +

 

+

Constraints:

+ +
    +
  • n == graph.length
  • +
  • 1 <= n <= 12
  • +
  • 0 <= graph[i].length < n
  • +
  • graph[i] does not contain i.
  • +
  • If graph[a] contains b, then graph[b] contains a.
  • +
  • The input graph is always connected.
  • +
+
\ No newline at end of file diff --git a/0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.py b/problems/0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.py similarity index 100% rename from 0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.py rename to problems/0852-peak-index-in-a-mountain-array/0852-peak-index-in-a-mountain-array.py diff --git a/0852-peak-index-in-a-mountain-array/NOTES.md b/problems/0852-peak-index-in-a-mountain-array/NOTES.md similarity index 100% rename from 0852-peak-index-in-a-mountain-array/NOTES.md rename to problems/0852-peak-index-in-a-mountain-array/NOTES.md diff --git a/problems/0852-peak-index-in-a-mountain-array/README.md b/problems/0852-peak-index-in-a-mountain-array/README.md new file mode 100644 index 000000000..e6e7ee11e --- /dev/null +++ b/problems/0852-peak-index-in-a-mountain-array/README.md @@ -0,0 +1,44 @@ +

852. Peak Index in a Mountain Array

Medium


An array arr a mountain if the following properties hold:

+ +
    +
  • arr.length >= 3
  • +
  • There exists some i with 0 < i < arr.length - 1 such that: +
      +
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • +
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • +
    +
  • +
+ +

Given a mountain array arr, return the index i such that arr[0] < arr[1] < ... < arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

+ +

You must solve it in O(log(arr.length)) time complexity.

+ +

 

+

Example 1:

+ +
Input: arr = [0,1,0]
+Output: 1
+
+ +

Example 2:

+ +
Input: arr = [0,2,1,0]
+Output: 1
+
+ +

Example 3:

+ +
Input: arr = [0,10,5,2]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= arr.length <= 105
  • +
  • 0 <= arr[i] <= 106
  • +
  • arr is guaranteed to be a mountain array.
  • +
+
\ No newline at end of file diff --git a/0857-minimum-cost-to-hire-k-workers/0857-minimum-cost-to-hire-k-workers.py b/problems/0857-minimum-cost-to-hire-k-workers/0857-minimum-cost-to-hire-k-workers.py similarity index 100% rename from 0857-minimum-cost-to-hire-k-workers/0857-minimum-cost-to-hire-k-workers.py rename to problems/0857-minimum-cost-to-hire-k-workers/0857-minimum-cost-to-hire-k-workers.py diff --git a/problems/0857-minimum-cost-to-hire-k-workers/README.md b/problems/0857-minimum-cost-to-hire-k-workers/README.md new file mode 100644 index 000000000..d251e14b9 --- /dev/null +++ b/problems/0857-minimum-cost-to-hire-k-workers/README.md @@ -0,0 +1,35 @@ +

857. Minimum Cost to Hire K Workers

Hard


There are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the ith worker and wage[i] is the minimum wage expectation for the ith worker.

+ +

We want to hire exactly k workers to form a paid group. To hire a group of k workers, we must pay them according to the following rules:

+ +
    +
  1. Every worker in the paid group must be paid at least their minimum wage expectation.
  2. +
  3. In the group, each worker's pay must be directly proportional to their quality. This means if a worker’s quality is double that of another worker in the group, then they must be paid twice as much as the other worker.
  4. +
+ +

Given the integer k, return the least amount of money needed to form a paid group satisfying the above conditions. Answers within 10-5 of the actual answer will be accepted.

+ +

 

+

Example 1:

+ +
Input: quality = [10,20,5], wage = [70,50,30], k = 2
+Output: 105.00000
+Explanation: We pay 70 to 0th worker and 35 to 2nd worker.
+
+ +

Example 2:

+ +
Input: quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3
+Output: 30.66667
+Explanation: We pay 4 to 0th worker, 13.33333 to 2nd and 3rd workers separately.
+
+ +

 

+

Constraints:

+ +
    +
  • n == quality.length == wage.length
  • +
  • 1 <= k <= n <= 104
  • +
  • 1 <= quality[i], wage[i] <= 104
  • +
+
\ No newline at end of file diff --git a/0860-lemonade-change/0860-lemonade-change.py b/problems/0860-lemonade-change/0860-lemonade-change.py similarity index 100% rename from 0860-lemonade-change/0860-lemonade-change.py rename to problems/0860-lemonade-change/0860-lemonade-change.py diff --git a/problems/0860-lemonade-change/README.md b/problems/0860-lemonade-change/README.md new file mode 100644 index 000000000..d3a40735c --- /dev/null +++ b/problems/0860-lemonade-change/README.md @@ -0,0 +1,37 @@ +

860. Lemonade Change

Easy


At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you and order one at a time (in the order specified by bills). Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill. You must provide the correct change to each customer so that the net transaction is that the customer pays $5.

+ +

Note that you do not have any change in hand at first.

+ +

Given an integer array bills where bills[i] is the bill the ith customer pays, return true if you can provide every customer with the correct change, or false otherwise.

+ +

 

+

Example 1:

+ +
Input: bills = [5,5,5,10,20]
+Output: true
+Explanation: 
+From the first 3 customers, we collect three $5 bills in order.
+From the fourth customer, we collect a $10 bill and give back a $5.
+From the fifth customer, we give a $10 bill and a $5 bill.
+Since all customers got correct change, we output true.
+
+ +

Example 2:

+ +
Input: bills = [5,5,10,10,20]
+Output: false
+Explanation: 
+From the first two customers in order, we collect two $5 bills.
+For the next two customers in order, we collect a $10 bill and give back a $5 bill.
+For the last customer, we can not give the change of $15 back because we only have two $10 bills.
+Since not every customer received the correct change, the answer is false.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= bills.length <= 105
  • +
  • bills[i] is either 5, 10, or 20.
  • +
+
\ No newline at end of file diff --git a/0861-score-after-flipping-matrix/0861-score-after-flipping-matrix.py b/problems/0861-score-after-flipping-matrix/0861-score-after-flipping-matrix.py similarity index 100% rename from 0861-score-after-flipping-matrix/0861-score-after-flipping-matrix.py rename to problems/0861-score-after-flipping-matrix/0861-score-after-flipping-matrix.py diff --git a/0861-score-after-flipping-matrix/NOTES.md b/problems/0861-score-after-flipping-matrix/NOTES.md similarity index 100% rename from 0861-score-after-flipping-matrix/NOTES.md rename to problems/0861-score-after-flipping-matrix/NOTES.md diff --git a/problems/0861-score-after-flipping-matrix/README.md b/problems/0861-score-after-flipping-matrix/README.md new file mode 100644 index 000000000..3a139c6f9 --- /dev/null +++ b/problems/0861-score-after-flipping-matrix/README.md @@ -0,0 +1,32 @@ +

861. Score After Flipping Matrix

Medium


You are given an m x n binary matrix grid.

+ +

A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).

+ +

Every row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers.

+ +

Return the highest possible score after making any number of moves (including zero moves).

+ +

 

+

Example 1:

+ +
Input: grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]
+Output: 39
+Explanation: 0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39
+
+ +

Example 2:

+ +
Input: grid = [[0]]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 20
  • +
  • grid[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/0867-transpose-matrix/0867-transpose-matrix.py b/problems/0867-transpose-matrix/0867-transpose-matrix.py similarity index 100% rename from 0867-transpose-matrix/0867-transpose-matrix.py rename to problems/0867-transpose-matrix/0867-transpose-matrix.py diff --git a/0867-transpose-matrix/NOTES.md b/problems/0867-transpose-matrix/NOTES.md similarity index 100% rename from 0867-transpose-matrix/NOTES.md rename to problems/0867-transpose-matrix/NOTES.md diff --git a/problems/0867-transpose-matrix/README.md b/problems/0867-transpose-matrix/README.md new file mode 100644 index 000000000..8eaf9eef9 --- /dev/null +++ b/problems/0867-transpose-matrix/README.md @@ -0,0 +1,30 @@ +

867. Transpose Matrix

Easy


Given a 2D integer array matrix, return the transpose of matrix.

+ +

The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices.

+ +

+ +

 

+

Example 1:

+ +
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
+Output: [[1,4,7],[2,5,8],[3,6,9]]
+
+ +

Example 2:

+ +
Input: matrix = [[1,2,3],[4,5,6]]
+Output: [[1,4],[2,5],[3,6]]
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m, n <= 1000
  • +
  • 1 <= m * n <= 105
  • +
  • -109 <= matrix[i][j] <= 109
  • +
+
\ No newline at end of file diff --git a/0872-leaf-similar-trees/0872-leaf-similar-trees.py b/problems/0872-leaf-similar-trees/0872-leaf-similar-trees.py similarity index 100% rename from 0872-leaf-similar-trees/0872-leaf-similar-trees.py rename to problems/0872-leaf-similar-trees/0872-leaf-similar-trees.py diff --git a/0872-leaf-similar-trees/NOTES.md b/problems/0872-leaf-similar-trees/NOTES.md similarity index 100% rename from 0872-leaf-similar-trees/NOTES.md rename to problems/0872-leaf-similar-trees/NOTES.md diff --git a/problems/0872-leaf-similar-trees/README.md b/problems/0872-leaf-similar-trees/README.md new file mode 100644 index 000000000..71da5fe7b --- /dev/null +++ b/problems/0872-leaf-similar-trees/README.md @@ -0,0 +1,31 @@ +

872. Leaf-Similar Trees

Easy


Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence.

+ +

+ +

For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8).

+ +

Two binary trees are considered leaf-similar if their leaf value sequence is the same.

+ +

Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.

+ +

 

+

Example 1:

+ +
Input: root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 = [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]
+Output: true
+
+ +

Example 2:

+ +
Input: root1 = [1,2,3], root2 = [1,3,2]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in each tree will be in the range [1, 200].
  • +
  • Both of the given trees will have values in the range [0, 200].
  • +
+
\ No newline at end of file diff --git a/0875-koko-eating-bananas/0875-koko-eating-bananas.py b/problems/0875-koko-eating-bananas/0875-koko-eating-bananas.py similarity index 100% rename from 0875-koko-eating-bananas/0875-koko-eating-bananas.py rename to problems/0875-koko-eating-bananas/0875-koko-eating-bananas.py diff --git a/0875-koko-eating-bananas/NOTES.md b/problems/0875-koko-eating-bananas/NOTES.md similarity index 100% rename from 0875-koko-eating-bananas/NOTES.md rename to problems/0875-koko-eating-bananas/NOTES.md diff --git a/problems/0875-koko-eating-bananas/README.md b/problems/0875-koko-eating-bananas/README.md new file mode 100644 index 000000000..c6eea5f5b --- /dev/null +++ b/problems/0875-koko-eating-bananas/README.md @@ -0,0 +1,36 @@ +

875. Koko Eating Bananas

Medium


Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.

+ +

Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.

+ +

Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.

+ +

Return the minimum integer k such that she can eat all the bananas within h hours.

+ +

 

+

Example 1:

+ +
Input: piles = [3,6,7,11], h = 8
+Output: 4
+
+ +

Example 2:

+ +
Input: piles = [30,11,23,4,20], h = 5
+Output: 30
+
+ +

Example 3:

+ +
Input: piles = [30,11,23,4,20], h = 6
+Output: 23
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= piles.length <= 104
  • +
  • piles.length <= h <= 109
  • +
  • 1 <= piles[i] <= 109
  • +
+
\ No newline at end of file diff --git a/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.cpp b/problems/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.cpp similarity index 100% rename from 0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.cpp rename to problems/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.cpp diff --git a/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.py b/problems/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.py similarity index 100% rename from 0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.py rename to problems/0876-middle-of-the-linked-list/0876-middle-of-the-linked-list.py diff --git a/0876-middle-of-the-linked-list/NOTES.md b/problems/0876-middle-of-the-linked-list/NOTES.md similarity index 100% rename from 0876-middle-of-the-linked-list/NOTES.md rename to problems/0876-middle-of-the-linked-list/NOTES.md diff --git a/problems/0876-middle-of-the-linked-list/README.md b/problems/0876-middle-of-the-linked-list/README.md new file mode 100644 index 000000000..bb08722c3 --- /dev/null +++ b/problems/0876-middle-of-the-linked-list/README.md @@ -0,0 +1,27 @@ +

876. Middle of the Linked List

Easy


Given the head of a singly linked list, return the middle node of the linked list.

+ +

If there are two middle nodes, return the second middle node.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4,5]
+Output: [3,4,5]
+Explanation: The middle node of the list is node 3.
+
+ +

Example 2:

+ +
Input: head = [1,2,3,4,5,6]
+Output: [4,5,6]
+Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 100].
  • +
  • 1 <= Node.val <= 100
  • +
+
\ No newline at end of file diff --git a/0880-decoded-string-at-index/0880-decoded-string-at-index.py b/problems/0880-decoded-string-at-index/0880-decoded-string-at-index.py similarity index 100% rename from 0880-decoded-string-at-index/0880-decoded-string-at-index.py rename to problems/0880-decoded-string-at-index/0880-decoded-string-at-index.py diff --git a/0880-decoded-string-at-index/NOTES.md b/problems/0880-decoded-string-at-index/NOTES.md similarity index 100% rename from 0880-decoded-string-at-index/NOTES.md rename to problems/0880-decoded-string-at-index/NOTES.md diff --git a/problems/0880-decoded-string-at-index/README.md b/problems/0880-decoded-string-at-index/README.md new file mode 100644 index 000000000..2831eaa76 --- /dev/null +++ b/problems/0880-decoded-string-at-index/README.md @@ -0,0 +1,46 @@ +

880. Decoded String at Index

Medium


You are given an encoded string s. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:

+ +
    +
  • If the character read is a letter, that letter is written onto the tape.
  • +
  • If the character read is a digit d, the entire current tape is repeatedly written d - 1 more times in total.
  • +
+ +

Given an integer k, return the kth letter (1-indexed) in the decoded string.

+ +

 

+

Example 1:

+ +
Input: s = "leet2code3", k = 10
+Output: "o"
+Explanation: The decoded string is "leetleetcodeleetleetcodeleetleetcode".
+The 10th letter in the string is "o".
+
+ +

Example 2:

+ +
Input: s = "ha22", k = 5
+Output: "h"
+Explanation: The decoded string is "hahahaha".
+The 5th letter is "h".
+
+ +

Example 3:

+ +
Input: s = "a2345678999999999999999", k = 1
+Output: "a"
+Explanation: The decoded string is "a" repeated 8301530446056247680 times.
+The 1st letter is "a".
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= s.length <= 100
  • +
  • s consists of lowercase English letters and digits 2 through 9.
  • +
  • s starts with a letter.
  • +
  • 1 <= k <= 109
  • +
  • It is guaranteed that k is less than or equal to the length of the decoded string.
  • +
  • The decoded string is guaranteed to have less than 263 letters.
  • +
+
\ No newline at end of file diff --git a/0881-boats-to-save-people/0881-boats-to-save-people.py b/problems/0881-boats-to-save-people/0881-boats-to-save-people.py similarity index 100% rename from 0881-boats-to-save-people/0881-boats-to-save-people.py rename to problems/0881-boats-to-save-people/0881-boats-to-save-people.py diff --git a/0881-boats-to-save-people/NOTES.md b/problems/0881-boats-to-save-people/NOTES.md similarity index 100% rename from 0881-boats-to-save-people/NOTES.md rename to problems/0881-boats-to-save-people/NOTES.md diff --git a/problems/0881-boats-to-save-people/README.md b/problems/0881-boats-to-save-people/README.md new file mode 100644 index 000000000..b45da2bea --- /dev/null +++ b/problems/0881-boats-to-save-people/README.md @@ -0,0 +1,34 @@ +

881. Boats to Save People

Medium


You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.

+ +

Return the minimum number of boats to carry every given person.

+ +

 

+

Example 1:

+ +
Input: people = [1,2], limit = 3
+Output: 1
+Explanation: 1 boat (1, 2)
+
+ +

Example 2:

+ +
Input: people = [3,2,2,1], limit = 3
+Output: 3
+Explanation: 3 boats (1, 2), (2) and (3)
+
+ +

Example 3:

+ +
Input: people = [3,5,3,4], limit = 5
+Output: 4
+Explanation: 4 boats (3), (3), (4), (5)
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= people.length <= 5 * 104
  • +
  • 1 <= people[i] <= limit <= 3 * 104
  • +
+
\ No newline at end of file diff --git a/0885-spiral-matrix-iii/0885-spiral-matrix-iii.py b/problems/0885-spiral-matrix-iii/0885-spiral-matrix-iii.py similarity index 100% rename from 0885-spiral-matrix-iii/0885-spiral-matrix-iii.py rename to problems/0885-spiral-matrix-iii/0885-spiral-matrix-iii.py diff --git a/problems/0885-spiral-matrix-iii/README.md b/problems/0885-spiral-matrix-iii/README.md new file mode 100644 index 000000000..721d4ed3e --- /dev/null +++ b/problems/0885-spiral-matrix-iii/README.md @@ -0,0 +1,28 @@ +

885. Spiral Matrix III

Medium


You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.

+ +

You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's boundary, we continue our walk outside the grid (but may return to the grid boundary later.). Eventually, we reach all rows * cols spaces of the grid.

+ +

Return an array of coordinates representing the positions of the grid in the order you visited them.

+ +

 

+

Example 1:

+ +
Input: rows = 1, cols = 4, rStart = 0, cStart = 0
+Output: [[0,0],[0,1],[0,2],[0,3]]
+
+ +

Example 2:

+ +
Input: rows = 5, cols = 6, rStart = 1, cStart = 4
+Output: [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= rows, cols <= 100
  • +
  • 0 <= rStart < rows
  • +
  • 0 <= cStart < cols
  • +
+
\ No newline at end of file diff --git a/0888-fair-candy-swap/0888-fair-candy-swap.py b/problems/0888-fair-candy-swap/0888-fair-candy-swap.py similarity index 100% rename from 0888-fair-candy-swap/0888-fair-candy-swap.py rename to problems/0888-fair-candy-swap/0888-fair-candy-swap.py diff --git a/0888-fair-candy-swap/NOTES.md b/problems/0888-fair-candy-swap/NOTES.md similarity index 100% rename from 0888-fair-candy-swap/NOTES.md rename to problems/0888-fair-candy-swap/NOTES.md diff --git a/problems/0888-fair-candy-swap/README.md b/problems/0888-fair-candy-swap/README.md new file mode 100644 index 000000000..d26bed5ed --- /dev/null +++ b/problems/0888-fair-candy-swap/README.md @@ -0,0 +1,35 @@ +

888. Fair Candy Swap

Easy


Alice and Bob have a different total number of candies. You are given two integer arrays aliceSizes and bobSizes where aliceSizes[i] is the number of candies of the ith box of candy that Alice has and bobSizes[j] is the number of candies of the jth box of candy that Bob has.

+ +

Since they are friends, they would like to exchange one candy box each so that after the exchange, they both have the same total amount of candy. The total amount of candy a person has is the sum of the number of candies in each box they have.

+ +

Return an integer array answer where answer[0] is the number of candies in the box that Alice must exchange, and answer[1] is the number of candies in the box that Bob must exchange. If there are multiple answers, you may return any one of them. It is guaranteed that at least one answer exists.

+ +

 

+

Example 1:

+ +
Input: aliceSizes = [1,1], bobSizes = [2,2]
+Output: [1,2]
+
+ +

Example 2:

+ +
Input: aliceSizes = [1,2], bobSizes = [2,3]
+Output: [1,2]
+
+ +

Example 3:

+ +
Input: aliceSizes = [2], bobSizes = [1,3]
+Output: [2,3]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= aliceSizes.length, bobSizes.length <= 104
  • +
  • 1 <= aliceSizes[i], bobSizes[j] <= 105
  • +
  • Alice and Bob have a different total number of candies.
  • +
  • There will be at least one valid answer for the given input.
  • +
+
\ No newline at end of file diff --git a/0894-all-possible-full-binary-trees/0894-all-possible-full-binary-trees.py b/problems/0894-all-possible-full-binary-trees/0894-all-possible-full-binary-trees.py similarity index 100% rename from 0894-all-possible-full-binary-trees/0894-all-possible-full-binary-trees.py rename to problems/0894-all-possible-full-binary-trees/0894-all-possible-full-binary-trees.py diff --git a/0894-all-possible-full-binary-trees/NOTES.md b/problems/0894-all-possible-full-binary-trees/NOTES.md similarity index 100% rename from 0894-all-possible-full-binary-trees/NOTES.md rename to problems/0894-all-possible-full-binary-trees/NOTES.md diff --git a/problems/0894-all-possible-full-binary-trees/README.md b/problems/0894-all-possible-full-binary-trees/README.md new file mode 100644 index 000000000..6a00abbe6 --- /dev/null +++ b/problems/0894-all-possible-full-binary-trees/README.md @@ -0,0 +1,26 @@ +

894. All Possible Full Binary Trees

Medium


Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0.

+ +

Each element of the answer is the root node of one possible tree. You may return the final list of trees in any order.

+ +

A full binary tree is a binary tree where each node has exactly 0 or 2 children.

+ +

 

+

Example 1:

+ +
Input: n = 7
+Output: [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]
+
+ +

Example 2:

+ +
Input: n = 3
+Output: [[0,0,0]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 20
  • +
+
\ No newline at end of file diff --git a/0896-monotonic-array/0896-monotonic-array.py b/problems/0896-monotonic-array/0896-monotonic-array.py similarity index 100% rename from 0896-monotonic-array/0896-monotonic-array.py rename to problems/0896-monotonic-array/0896-monotonic-array.py diff --git a/0896-monotonic-array/NOTES.md b/problems/0896-monotonic-array/NOTES.md similarity index 100% rename from 0896-monotonic-array/NOTES.md rename to problems/0896-monotonic-array/NOTES.md diff --git a/problems/0896-monotonic-array/README.md b/problems/0896-monotonic-array/README.md new file mode 100644 index 000000000..ce951e0c4 --- /dev/null +++ b/problems/0896-monotonic-array/README.md @@ -0,0 +1,33 @@ +

896. Monotonic Array

Easy


An array is monotonic if it is either monotone increasing or monotone decreasing.

+ +

An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j].

+ +

Given an integer array nums, return true if the given array is monotonic, or false otherwise.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,2,3]
+Output: true
+
+ +

Example 2:

+ +
Input: nums = [6,5,4,4]
+Output: true
+
+ +

Example 3:

+ +
Input: nums = [1,3,2]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -105 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/0905-sort-array-by-parity/0905-sort-array-by-parity.py b/problems/0905-sort-array-by-parity/0905-sort-array-by-parity.py similarity index 100% rename from 0905-sort-array-by-parity/0905-sort-array-by-parity.py rename to problems/0905-sort-array-by-parity/0905-sort-array-by-parity.py diff --git a/0905-sort-array-by-parity/NOTES.md b/problems/0905-sort-array-by-parity/NOTES.md similarity index 100% rename from 0905-sort-array-by-parity/NOTES.md rename to problems/0905-sort-array-by-parity/NOTES.md diff --git a/problems/0905-sort-array-by-parity/README.md b/problems/0905-sort-array-by-parity/README.md new file mode 100644 index 000000000..ed73e0517 --- /dev/null +++ b/problems/0905-sort-array-by-parity/README.md @@ -0,0 +1,26 @@ +

905. Sort Array By Parity

Easy


Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.

+ +

Return any array that satisfies this condition.

+ +

 

+

Example 1:

+ +
Input: nums = [3,1,2,4]
+Output: [2,4,3,1]
+Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
+
+ +

Example 2:

+ +
Input: nums = [0]
+Output: [0]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5000
  • +
  • 0 <= nums[i] <= 5000
  • +
+
\ No newline at end of file diff --git a/0907-sum-of-subarray-minimums/0907-sum-of-subarray-minimums.py b/problems/0907-sum-of-subarray-minimums/0907-sum-of-subarray-minimums.py similarity index 100% rename from 0907-sum-of-subarray-minimums/0907-sum-of-subarray-minimums.py rename to problems/0907-sum-of-subarray-minimums/0907-sum-of-subarray-minimums.py diff --git a/0907-sum-of-subarray-minimums/NOTES.md b/problems/0907-sum-of-subarray-minimums/NOTES.md similarity index 100% rename from 0907-sum-of-subarray-minimums/NOTES.md rename to problems/0907-sum-of-subarray-minimums/NOTES.md diff --git a/problems/0907-sum-of-subarray-minimums/README.md b/problems/0907-sum-of-subarray-minimums/README.md new file mode 100644 index 000000000..6cc631137 --- /dev/null +++ b/problems/0907-sum-of-subarray-minimums/README.md @@ -0,0 +1,27 @@ +

907. Sum of Subarray Minimums

Medium


Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: arr = [3,1,2,4]
+Output: 17
+Explanation: 
+Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]. 
+Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.
+Sum is 17.
+
+ +

Example 2:

+ +
Input: arr = [11,81,94,43,3]
+Output: 444
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 3 * 104
  • +
  • 1 <= arr[i] <= 3 * 104
  • +
+
\ No newline at end of file diff --git a/0912-sort-an-array/0912-sort-an-array.py b/problems/0912-sort-an-array/0912-sort-an-array.py similarity index 100% rename from 0912-sort-an-array/0912-sort-an-array.py rename to problems/0912-sort-an-array/0912-sort-an-array.py diff --git a/0912-sort-an-array/NOTES.md b/problems/0912-sort-an-array/NOTES.md similarity index 100% rename from 0912-sort-an-array/NOTES.md rename to problems/0912-sort-an-array/NOTES.md diff --git a/problems/0912-sort-an-array/README.md b/problems/0912-sort-an-array/README.md new file mode 100644 index 000000000..9b50c6179 --- /dev/null +++ b/problems/0912-sort-an-array/README.md @@ -0,0 +1,27 @@ +

912. Sort an Array

Medium


Given an array of integers nums, sort the array in ascending order and return it.

+ +

You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.

+ +

 

+

Example 1:

+ +
Input: nums = [5,2,3,1]
+Output: [1,2,3,5]
+Explanation: After sorting the array, the positions of some numbers are not changed (for example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).
+
+ +

Example 2:

+ +
Input: nums = [5,1,1,2,0,0]
+Output: [0,0,1,1,2,5]
+Explanation: Note that the values of nums are not necessairly unique.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • -5 * 104 <= nums[i] <= 5 * 104
  • +
+
\ No newline at end of file diff --git a/0920-number-of-music-playlists/0920-number-of-music-playlists.py b/problems/0920-number-of-music-playlists/0920-number-of-music-playlists.py similarity index 100% rename from 0920-number-of-music-playlists/0920-number-of-music-playlists.py rename to problems/0920-number-of-music-playlists/0920-number-of-music-playlists.py diff --git a/0920-number-of-music-playlists/NOTES.md b/problems/0920-number-of-music-playlists/NOTES.md similarity index 100% rename from 0920-number-of-music-playlists/NOTES.md rename to problems/0920-number-of-music-playlists/NOTES.md diff --git a/problems/0920-number-of-music-playlists/README.md b/problems/0920-number-of-music-playlists/README.md new file mode 100644 index 000000000..6d3448211 --- /dev/null +++ b/problems/0920-number-of-music-playlists/README.md @@ -0,0 +1,37 @@ +

920. Number of Music Playlists

Hard


Your music player contains n different songs. You want to listen to goal songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:

+ +
    +
  • Every song is played at least once.
  • +
  • A song can only be played again only if k other songs have been played.
  • +
+ +

Given n, goal, and k, return the number of possible playlists that you can create. Since the answer can be very large, return it modulo 109 + 7.

+

 

+

Example 1:

+ +
Input: n = 3, goal = 3, k = 1
+Output: 6
+Explanation: There are 6 possible playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], and [3, 2, 1].
+
+ +

Example 2:

+ +
Input: n = 2, goal = 3, k = 0
+Output: 6
+Explanation: There are 6 possible playlists: [1, 1, 2], [1, 2, 1], [2, 1, 1], [2, 2, 1], [2, 1, 2], and [1, 2, 2].
+
+ +

Example 3:

+ +
Input: n = 2, goal = 3, k = 1
+Output: 2
+Explanation: There are 2 possible playlists: [1, 2, 1] and [2, 1, 2].
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= k < n <= goal <= 100
  • +
+
\ No newline at end of file diff --git a/0930-binary-subarrays-with-sum/0930-binary-subarrays-with-sum.py b/problems/0930-binary-subarrays-with-sum/0930-binary-subarrays-with-sum.py similarity index 100% rename from 0930-binary-subarrays-with-sum/0930-binary-subarrays-with-sum.py rename to problems/0930-binary-subarrays-with-sum/0930-binary-subarrays-with-sum.py diff --git a/0930-binary-subarrays-with-sum/NOTES.md b/problems/0930-binary-subarrays-with-sum/NOTES.md similarity index 100% rename from 0930-binary-subarrays-with-sum/NOTES.md rename to problems/0930-binary-subarrays-with-sum/NOTES.md diff --git a/problems/0930-binary-subarrays-with-sum/README.md b/problems/0930-binary-subarrays-with-sum/README.md new file mode 100644 index 000000000..63710621b --- /dev/null +++ b/problems/0930-binary-subarrays-with-sum/README.md @@ -0,0 +1,30 @@ +

930. Binary Subarrays With Sum

Medium


Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.

+ +

A subarray is a contiguous part of the array.

+ +

 

+

Example 1:

+ +
Input: nums = [1,0,1,0,1], goal = 2
+Output: 4
+Explanation: The 4 subarrays are bolded and underlined below:
+[1,0,1,0,1]
+[1,0,1,0,1]
+[1,0,1,0,1]
+[1,0,1,0,1]
+
+ +

Example 2:

+ +
Input: nums = [0,0,0,0,0], goal = 0
+Output: 15
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • nums[i] is either 0 or 1.
  • +
  • 0 <= goal <= nums.length
  • +
\ No newline at end of file diff --git a/0931-minimum-falling-path-sum/0931-minimum-falling-path-sum.py b/problems/0931-minimum-falling-path-sum/0931-minimum-falling-path-sum.py similarity index 100% rename from 0931-minimum-falling-path-sum/0931-minimum-falling-path-sum.py rename to problems/0931-minimum-falling-path-sum/0931-minimum-falling-path-sum.py diff --git a/0931-minimum-falling-path-sum/NOTES.md b/problems/0931-minimum-falling-path-sum/NOTES.md similarity index 100% rename from 0931-minimum-falling-path-sum/NOTES.md rename to problems/0931-minimum-falling-path-sum/NOTES.md diff --git a/problems/0931-minimum-falling-path-sum/README.md b/problems/0931-minimum-falling-path-sum/README.md new file mode 100644 index 000000000..64228ea51 --- /dev/null +++ b/problems/0931-minimum-falling-path-sum/README.md @@ -0,0 +1,28 @@ +

931. Minimum Falling Path Sum

Medium


Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.

+ +

A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1).

+ +

 

+

Example 1:

+ +
Input: matrix = [[2,1,3],[6,5,4],[7,8,9]]
+Output: 13
+Explanation: There are two falling paths with a minimum sum as shown.
+
+ +

Example 2:

+ +
Input: matrix = [[-19,57],[-40,-5]]
+Output: -59
+Explanation: The falling path with a minimum sum is shown.
+
+ +

 

+

Constraints:

+ +
    +
  • n == matrix.length == matrix[i].length
  • +
  • 1 <= n <= 100
  • +
  • -100 <= matrix[i][j] <= 100
  • +
+
\ No newline at end of file diff --git a/0935-knight-dialer/0935-knight-dialer.py b/problems/0935-knight-dialer/0935-knight-dialer.py similarity index 100% rename from 0935-knight-dialer/0935-knight-dialer.py rename to problems/0935-knight-dialer/0935-knight-dialer.py diff --git a/0935-knight-dialer/NOTES.md b/problems/0935-knight-dialer/NOTES.md similarity index 100% rename from 0935-knight-dialer/NOTES.md rename to problems/0935-knight-dialer/NOTES.md diff --git a/problems/0935-knight-dialer/README.md b/problems/0935-knight-dialer/README.md new file mode 100644 index 000000000..a4f7bbbdd --- /dev/null +++ b/problems/0935-knight-dialer/README.md @@ -0,0 +1,41 @@ +

935. Knight Dialer

Medium


The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess knight are shown in this diagaram:

+ +

A chess knight can move as indicated in the chess diagram below:

+ +

We have a chess knight and a phone pad as shown below, the knight can only stand on a numeric cell (i.e. blue cell).

+ +

Given an integer n, return how many distinct phone numbers of length n we can dial.

+ +

You are allowed to place the knight on any numeric cell initially and then you should perform n - 1 jumps to dial a number of length n. All jumps should be valid knight jumps.

+ +

As the answer may be very large, return the answer modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 1
+Output: 10
+Explanation: We need to dial a number of length 1, so placing the knight over any numeric cell of the 10 cells is sufficient.
+
+ +

Example 2:

+ +
Input: n = 2
+Output: 20
+Explanation: All the valid number we can dial are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]
+
+ +

Example 3:

+ +
Input: n = 3131
+Output: 136006598
+Explanation: Please take care of the mod.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 5000
  • +
+
\ No newline at end of file diff --git a/0938-range-sum-of-bst/0938-range-sum-of-bst.py b/problems/0938-range-sum-of-bst/0938-range-sum-of-bst.py similarity index 100% rename from 0938-range-sum-of-bst/0938-range-sum-of-bst.py rename to problems/0938-range-sum-of-bst/0938-range-sum-of-bst.py diff --git a/0938-range-sum-of-bst/NOTES.md b/problems/0938-range-sum-of-bst/NOTES.md similarity index 100% rename from 0938-range-sum-of-bst/NOTES.md rename to problems/0938-range-sum-of-bst/NOTES.md diff --git a/problems/0938-range-sum-of-bst/README.md b/problems/0938-range-sum-of-bst/README.md new file mode 100644 index 000000000..25f2c7e69 --- /dev/null +++ b/problems/0938-range-sum-of-bst/README.md @@ -0,0 +1,27 @@ +

938. Range Sum of BST

Easy


Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].

+ +

 

+

Example 1:

+ +
Input: root = [10,5,15,3,7,null,18], low = 7, high = 15
+Output: 32
+Explanation: Nodes 7, 10, and 15 are in the range [7, 15]. 7 + 10 + 15 = 32.
+
+ +

Example 2:

+ +
Input: root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10
+Output: 23
+Explanation: Nodes 6, 7, and 10 are in the range [6, 10]. 6 + 7 + 10 = 23.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 2 * 104].
  • +
  • 1 <= Node.val <= 105
  • +
  • 1 <= low <= high <= 105
  • +
  • All Node.val are unique.
  • +
+
\ No newline at end of file diff --git a/0945-minimum-increment-to-make-array-unique/0945-minimum-increment-to-make-array-unique.py b/problems/0945-minimum-increment-to-make-array-unique/0945-minimum-increment-to-make-array-unique.py similarity index 100% rename from 0945-minimum-increment-to-make-array-unique/0945-minimum-increment-to-make-array-unique.py rename to problems/0945-minimum-increment-to-make-array-unique/0945-minimum-increment-to-make-array-unique.py diff --git a/0945-minimum-increment-to-make-array-unique/NOTES.md b/problems/0945-minimum-increment-to-make-array-unique/NOTES.md similarity index 100% rename from 0945-minimum-increment-to-make-array-unique/NOTES.md rename to problems/0945-minimum-increment-to-make-array-unique/NOTES.md diff --git a/problems/0945-minimum-increment-to-make-array-unique/README.md b/problems/0945-minimum-increment-to-make-array-unique/README.md new file mode 100644 index 000000000..b81b99e4a --- /dev/null +++ b/problems/0945-minimum-increment-to-make-array-unique/README.md @@ -0,0 +1,30 @@ +

945. Minimum Increment to Make Array Unique

Medium


You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.

+ +

Return the minimum number of moves to make every value in nums unique.

+ +

The test cases are generated so that the answer fits in a 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,2]
+Output: 1
+Explanation: After 1 move, the array could be [1, 2, 3].
+
+ +

Example 2:

+ +
Input: nums = [3,2,1,2,1,7]
+Output: 6
+Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
+It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/0948-bag-of-tokens/0948-bag-of-tokens.py b/problems/0948-bag-of-tokens/0948-bag-of-tokens.py similarity index 100% rename from 0948-bag-of-tokens/0948-bag-of-tokens.py rename to problems/0948-bag-of-tokens/0948-bag-of-tokens.py diff --git a/0948-bag-of-tokens/NOTES.md b/problems/0948-bag-of-tokens/NOTES.md similarity index 100% rename from 0948-bag-of-tokens/NOTES.md rename to problems/0948-bag-of-tokens/NOTES.md diff --git a/problems/0948-bag-of-tokens/README.md b/problems/0948-bag-of-tokens/README.md new file mode 100644 index 000000000..968d02c52 --- /dev/null +++ b/problems/0948-bag-of-tokens/README.md @@ -0,0 +1,106 @@ +

948. Bag of Tokens

Medium


You start with an initial power of power, an initial score of 0, and a bag of tokens given as an integer array tokens, where each tokens[i] donates the value of tokeni.

+ +

Your goal is to maximize the total score by strategically playing these tokens. In one move, you can play an unplayed token in one of the two ways (but not both for the same token):

+ +
    +
  • Face-up: If your current power is at least tokens[i], you may play tokeni, losing tokens[i] power and gaining 1 score.
  • +
  • Face-down: If your current score is at least 1, you may play tokeni, gaining tokens[i] power and losing 1 score.
  • +
+ +

Return the maximum possible score you can achieve after playing any number of tokens.

+ +

 

+

Example 1:

+ +
+

Input: tokens = [100], power = 50

+ +

Output: 0

+ +

Explanation: Since your score is 0 initially, you cannot play the token face-down. You also cannot play it face-up since your power (50) is less than tokens[0] (100).

+
+ +

Example 2:

+ +
+

Input: tokens = [200,100], power = 150

+ +

Output: 1

+ +

Explanation: Play token1 (100) face-up, reducing your power to 50 and increasing your score to 1.

+ +

There is no need to play token0, since you cannot play it face-up to add to your score. The maximum score achievable is 1.

+
+ +

Example 3:

+ +
+

Input: tokens = [100,200,300,400], power = 200

+ +

Output: 2

+ +

Explanation: Play the tokens in this order to get a score of 2:

+ +
    +
  1. Play token0 (100) face-up, reducing power to 100 and increasing score to 1.
  2. +
  3. Play token3 (400) face-down, increasing power to 500 and reducing score to 0.
  4. +
  5. Play token1 (200) face-up, reducing power to 300 and increasing score to 1.
  6. +
  7. Play token2 (300) face-up, reducing power to 0 and increasing score to 2.
  8. +
+ +

The maximum score achievable is 2.

+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= tokens.length <= 1000
  • +
  • 0 <= tokens[i], power < 104
  • +
+
\ No newline at end of file diff --git a/0950-reveal-cards-in-increasing-order/0950-reveal-cards-in-increasing-order.py b/problems/0950-reveal-cards-in-increasing-order/0950-reveal-cards-in-increasing-order.py similarity index 100% rename from 0950-reveal-cards-in-increasing-order/0950-reveal-cards-in-increasing-order.py rename to problems/0950-reveal-cards-in-increasing-order/0950-reveal-cards-in-increasing-order.py diff --git a/0950-reveal-cards-in-increasing-order/NOTES.md b/problems/0950-reveal-cards-in-increasing-order/NOTES.md similarity index 100% rename from 0950-reveal-cards-in-increasing-order/NOTES.md rename to problems/0950-reveal-cards-in-increasing-order/NOTES.md diff --git a/problems/0950-reveal-cards-in-increasing-order/README.md b/problems/0950-reveal-cards-in-increasing-order/README.md new file mode 100644 index 000000000..8fd4c765e --- /dev/null +++ b/problems/0950-reveal-cards-in-increasing-order/README.md @@ -0,0 +1,49 @@ +

950. Reveal Cards In Increasing Order

Medium


You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i].

+ +

You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck.

+ +

You will do the following steps repeatedly until all cards are revealed:

+ +
    +
  1. Take the top card of the deck, reveal it, and take it out of the deck.
  2. +
  3. If there are still cards in the deck then put the next top card of the deck at the bottom of the deck.
  4. +
  5. If there are still unrevealed cards, go back to step 1. Otherwise, stop.
  6. +
+ +

Return an ordering of the deck that would reveal the cards in increasing order.

+ +

Note that the first entry in the answer is considered to be the top of the deck.

+ +

 

+

Example 1:

+ +
Input: deck = [17,13,11,2,3,5,7]
+Output: [2,13,3,11,5,17,7]
+Explanation: 
+We get the deck in the order [17,13,11,2,3,5,7] (this order does not matter), and reorder it.
+After reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.
+We reveal 2, and move 13 to the bottom.  The deck is now [3,11,5,17,7,13].
+We reveal 3, and move 11 to the bottom.  The deck is now [5,17,7,13,11].
+We reveal 5, and move 17 to the bottom.  The deck is now [7,13,11,17].
+We reveal 7, and move 13 to the bottom.  The deck is now [11,17,13].
+We reveal 11, and move 17 to the bottom.  The deck is now [13,17].
+We reveal 13, and move 17 to the bottom.  The deck is now [17].
+We reveal 17.
+Since all the cards revealed are in increasing order, the answer is correct.
+
+ +

Example 2:

+ +
Input: deck = [1,1000]
+Output: [1,1000]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= deck.length <= 1000
  • +
  • 1 <= deck[i] <= 106
  • +
  • All the values of deck are unique.
  • +
+
\ No newline at end of file diff --git a/0959-regions-cut-by-slashes/0959-regions-cut-by-slashes.py b/problems/0959-regions-cut-by-slashes/0959-regions-cut-by-slashes.py similarity index 100% rename from 0959-regions-cut-by-slashes/0959-regions-cut-by-slashes.py rename to problems/0959-regions-cut-by-slashes/0959-regions-cut-by-slashes.py diff --git a/problems/0959-regions-cut-by-slashes/README.md b/problems/0959-regions-cut-by-slashes/README.md new file mode 100644 index 000000000..fc2c5d3bc --- /dev/null +++ b/problems/0959-regions-cut-by-slashes/README.md @@ -0,0 +1,35 @@ +

959. Regions Cut By Slashes

Medium


An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions.

+ +

Given the grid grid represented as a string array, return the number of regions.

+ +

Note that backslash characters are escaped, so a '\' is represented as '\\'.

+ +

 

+

Example 1:

+ +
Input: grid = [" /","/ "]
+Output: 2
+
+ +

Example 2:

+ +
Input: grid = [" /","  "]
+Output: 1
+
+ +

Example 3:

+ +
Input: grid = ["/\\","\\/"]
+Output: 5
+Explanation: Recall that because \ characters are escaped, "\\/" refers to \/, and "/\\" refers to /\.
+
+ +

 

+

Constraints:

+ +
    +
  • n == grid.length == grid[i].length
  • +
  • 1 <= n <= 30
  • +
  • grid[i][j] is either '/', '\', or ' '.
  • +
+
\ No newline at end of file diff --git a/0973-k-closest-points-to-origin/0973-k-closest-points-to-origin.py b/problems/0973-k-closest-points-to-origin/0973-k-closest-points-to-origin.py similarity index 100% rename from 0973-k-closest-points-to-origin/0973-k-closest-points-to-origin.py rename to problems/0973-k-closest-points-to-origin/0973-k-closest-points-to-origin.py diff --git a/0973-k-closest-points-to-origin/NOTES.md b/problems/0973-k-closest-points-to-origin/NOTES.md similarity index 100% rename from 0973-k-closest-points-to-origin/NOTES.md rename to problems/0973-k-closest-points-to-origin/NOTES.md diff --git a/problems/0973-k-closest-points-to-origin/README.md b/problems/0973-k-closest-points-to-origin/README.md new file mode 100644 index 000000000..0c45639c6 --- /dev/null +++ b/problems/0973-k-closest-points-to-origin/README.md @@ -0,0 +1,33 @@ +

973. K Closest Points to Origin

Medium


Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).

+ +

The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2).

+ +

You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in).

+ +

 

+

Example 1:

+ +
Input: points = [[1,3],[-2,2]], k = 1
+Output: [[-2,2]]
+Explanation:
+The distance between (1, 3) and the origin is sqrt(10).
+The distance between (-2, 2) and the origin is sqrt(8).
+Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
+We only want the closest k = 1 points from the origin, so the answer is just [[-2,2]].
+
+ +

Example 2:

+ +
Input: points = [[3,3],[5,-1],[-2,4]], k = 2
+Output: [[3,3],[-2,4]]
+Explanation: The answer [[-2,4],[3,3]] would also be accepted.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= points.length <= 104
  • +
  • -104 < xi, yi < 104
  • +
+
\ No newline at end of file diff --git a/0974-subarray-sums-divisible-by-k/0974-subarray-sums-divisible-by-k.py b/problems/0974-subarray-sums-divisible-by-k/0974-subarray-sums-divisible-by-k.py similarity index 100% rename from 0974-subarray-sums-divisible-by-k/0974-subarray-sums-divisible-by-k.py rename to problems/0974-subarray-sums-divisible-by-k/0974-subarray-sums-divisible-by-k.py diff --git a/0974-subarray-sums-divisible-by-k/NOTES.md b/problems/0974-subarray-sums-divisible-by-k/NOTES.md similarity index 100% rename from 0974-subarray-sums-divisible-by-k/NOTES.md rename to problems/0974-subarray-sums-divisible-by-k/NOTES.md diff --git a/problems/0974-subarray-sums-divisible-by-k/README.md b/problems/0974-subarray-sums-divisible-by-k/README.md new file mode 100644 index 000000000..af732be78 --- /dev/null +++ b/problems/0974-subarray-sums-divisible-by-k/README.md @@ -0,0 +1,28 @@ +

974. Subarray Sums Divisible by K

Medium


Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.

+ +

A subarray is a contiguous part of an array.

+ +

 

+

Example 1:

+ +
Input: nums = [4,5,0,-2,-3,1], k = 5
+Output: 7
+Explanation: There are 7 subarrays with a sum divisible by k = 5:
+[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
+
+ +

Example 2:

+ +
Input: nums = [5], k = 9
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • -104 <= nums[i] <= 104
  • +
  • 2 <= k <= 104
  • +
+
\ No newline at end of file diff --git a/0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.cpp b/problems/0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.cpp similarity index 100% rename from 0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.cpp rename to problems/0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.cpp diff --git a/0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.py b/problems/0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.py similarity index 100% rename from 0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.py rename to problems/0977-squares-of-a-sorted-array/0977-squares-of-a-sorted-array.py diff --git a/0977-squares-of-a-sorted-array/NOTES.md b/problems/0977-squares-of-a-sorted-array/NOTES.md similarity index 100% rename from 0977-squares-of-a-sorted-array/NOTES.md rename to problems/0977-squares-of-a-sorted-array/NOTES.md diff --git a/problems/0977-squares-of-a-sorted-array/README.md b/problems/0977-squares-of-a-sorted-array/README.md new file mode 100644 index 000000000..9e0b7c42e --- /dev/null +++ b/problems/0977-squares-of-a-sorted-array/README.md @@ -0,0 +1,28 @@ +

977. Squares of a Sorted Array

Easy


Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

+ +

 

+

Example 1:

+ +
Input: nums = [-4,-1,0,3,10]
+Output: [0,1,9,16,100]
+Explanation: After squaring, the array becomes [16,1,0,9,100].
+After sorting, it becomes [0,1,9,16,100].
+
+ +

Example 2:

+ +
Input: nums = [-7,-3,2,3,11]
+Output: [4,9,9,49,121]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 104
  • +
  • -104 <= nums[i] <= 104
  • +
  • nums is sorted in non-decreasing order.
  • +
+ +

 

+Follow up: Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?
\ No newline at end of file diff --git a/0979-distribute-coins-in-binary-tree/0979-distribute-coins-in-binary-tree.py b/problems/0979-distribute-coins-in-binary-tree/0979-distribute-coins-in-binary-tree.py similarity index 100% rename from 0979-distribute-coins-in-binary-tree/0979-distribute-coins-in-binary-tree.py rename to problems/0979-distribute-coins-in-binary-tree/0979-distribute-coins-in-binary-tree.py diff --git a/0979-distribute-coins-in-binary-tree/NOTES.md b/problems/0979-distribute-coins-in-binary-tree/NOTES.md similarity index 100% rename from 0979-distribute-coins-in-binary-tree/NOTES.md rename to problems/0979-distribute-coins-in-binary-tree/NOTES.md diff --git a/problems/0979-distribute-coins-in-binary-tree/README.md b/problems/0979-distribute-coins-in-binary-tree/README.md new file mode 100644 index 000000000..e7b0415a9 --- /dev/null +++ b/problems/0979-distribute-coins-in-binary-tree/README.md @@ -0,0 +1,31 @@ +

979. Distribute Coins in Binary Tree

Medium


You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree.

+ +

In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent.

+ +

Return the minimum number of moves required to make every node have exactly one coin.

+ +

 

+

Example 1:

+ +
Input: root = [3,0,0]
+Output: 2
+Explanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.
+
+ +

Example 2:

+ +
Input: root = [0,3,0]
+Output: 3
+Explanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is n.
  • +
  • 1 <= n <= 100
  • +
  • 0 <= Node.val <= n
  • +
  • The sum of all Node.val is n.
  • +
+
\ No newline at end of file diff --git a/0981-time-based-key-value-store/0981-time-based-key-value-store.py b/problems/0981-time-based-key-value-store/0981-time-based-key-value-store.py similarity index 100% rename from 0981-time-based-key-value-store/0981-time-based-key-value-store.py rename to problems/0981-time-based-key-value-store/0981-time-based-key-value-store.py diff --git a/0981-time-based-key-value-store/NOTES.md b/problems/0981-time-based-key-value-store/NOTES.md similarity index 100% rename from 0981-time-based-key-value-store/NOTES.md rename to problems/0981-time-based-key-value-store/NOTES.md diff --git a/problems/0981-time-based-key-value-store/README.md b/problems/0981-time-based-key-value-store/README.md new file mode 100644 index 000000000..2aa380da2 --- /dev/null +++ b/problems/0981-time-based-key-value-store/README.md @@ -0,0 +1,40 @@ +

981. Time Based Key-Value Store

Medium


Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.

+ +

Implement the TimeMap class:

+ +
    +
  • TimeMap() Initializes the object of the data structure.
  • +
  • void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp.
  • +
  • String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp. If there are multiple such values, it returns the value associated with the largest timestamp_prev. If there are no values, it returns "".
  • +
+ +

 

+

Example 1:

+ +
Input
+["TimeMap", "set", "get", "get", "set", "get", "get"]
+[[], ["foo", "bar", 1], ["foo", 1], ["foo", 3], ["foo", "bar2", 4], ["foo", 4], ["foo", 5]]
+Output
+[null, null, "bar", "bar", null, "bar2", "bar2"]
+
+Explanation
+TimeMap timeMap = new TimeMap();
+timeMap.set("foo", "bar", 1);  // store the key "foo" and value "bar" along with timestamp = 1.
+timeMap.get("foo", 1);         // return "bar"
+timeMap.get("foo", 3);         // return "bar", since there is no value corresponding to foo at timestamp 3 and timestamp 2, then the only value is at timestamp 1 is "bar".
+timeMap.set("foo", "bar2", 4); // store the key "foo" and value "bar2" along with timestamp = 4.
+timeMap.get("foo", 4);         // return "bar2"
+timeMap.get("foo", 5);         // return "bar2"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= key.length, value.length <= 100
  • +
  • key and value consist of lowercase English letters and digits.
  • +
  • 1 <= timestamp <= 107
  • +
  • All the timestamps timestamp of set are strictly increasing.
  • +
  • At most 2 * 105 calls will be made to set and get.
  • +
+
\ No newline at end of file diff --git a/0988-smallest-string-starting-from-leaf/0988-smallest-string-starting-from-leaf.py b/problems/0988-smallest-string-starting-from-leaf/0988-smallest-string-starting-from-leaf.py similarity index 100% rename from 0988-smallest-string-starting-from-leaf/0988-smallest-string-starting-from-leaf.py rename to problems/0988-smallest-string-starting-from-leaf/0988-smallest-string-starting-from-leaf.py diff --git a/0988-smallest-string-starting-from-leaf/NOTES.md b/problems/0988-smallest-string-starting-from-leaf/NOTES.md similarity index 100% rename from 0988-smallest-string-starting-from-leaf/NOTES.md rename to problems/0988-smallest-string-starting-from-leaf/NOTES.md diff --git a/problems/0988-smallest-string-starting-from-leaf/README.md b/problems/0988-smallest-string-starting-from-leaf/README.md new file mode 100644 index 000000000..2ba3cfedf --- /dev/null +++ b/problems/0988-smallest-string-starting-from-leaf/README.md @@ -0,0 +1,39 @@ +

988. Smallest String Starting From Leaf

Medium


You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'.

+ +

Return the lexicographically smallest string that starts at a leaf of this tree and ends at the root.

+ +

As a reminder, any shorter prefix of a string is lexicographically smaller.

+ +
    +
  • For example, "ab" is lexicographically smaller than "aba".
  • +
+ +

A leaf of a node is a node that has no children.

+ +

 

+

Example 1:

+ +
Input: root = [0,1,2,3,4,3,4]
+Output: "dba"
+
+ +

Example 2:

+ +
Input: root = [25,1,3,1,3,0,2]
+Output: "adz"
+
+ +

Example 3:

+ +
Input: root = [2,2,1,null,1,0,null,0]
+Output: "abc"
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 8500].
  • +
  • 0 <= Node.val <= 25
  • +
+
\ No newline at end of file diff --git a/0992-subarrays-with-k-different-integers/0992-subarrays-with-k-different-integers.py b/problems/0992-subarrays-with-k-different-integers/0992-subarrays-with-k-different-integers.py similarity index 100% rename from 0992-subarrays-with-k-different-integers/0992-subarrays-with-k-different-integers.py rename to problems/0992-subarrays-with-k-different-integers/0992-subarrays-with-k-different-integers.py diff --git a/0992-subarrays-with-k-different-integers/NOTES.md b/problems/0992-subarrays-with-k-different-integers/NOTES.md similarity index 100% rename from 0992-subarrays-with-k-different-integers/NOTES.md rename to problems/0992-subarrays-with-k-different-integers/NOTES.md diff --git a/problems/0992-subarrays-with-k-different-integers/README.md b/problems/0992-subarrays-with-k-different-integers/README.md new file mode 100644 index 000000000..cde878b88 --- /dev/null +++ b/problems/0992-subarrays-with-k-different-integers/README.md @@ -0,0 +1,33 @@ +

992. Subarrays with K Different Integers

Hard


Given an integer array nums and an integer k, return the number of good subarrays of nums.

+ +

A good array is an array where the number of different integers in that array is exactly k.

+ +
    +
  • For example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.
  • +
+ +

A subarray is a contiguous part of an array.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,1,2,3], k = 2
+Output: 7
+Explanation: Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,2], [1,2,1,2]
+
+ +

Example 2:

+ +
Input: nums = [1,2,1,3,4], k = 3
+Output: 3
+Explanation: Subarrays formed with exactly 3 different integers: [1,2,1,3], [2,1,3], [1,3,4].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 2 * 104
  • +
  • 1 <= nums[i], k <= nums.length
  • +
+
\ No newline at end of file diff --git a/0994-rotting-oranges/0994-rotting-oranges.cpp b/problems/0994-rotting-oranges/0994-rotting-oranges.cpp similarity index 100% rename from 0994-rotting-oranges/0994-rotting-oranges.cpp rename to problems/0994-rotting-oranges/0994-rotting-oranges.cpp diff --git a/0994-rotting-oranges/0994-rotting-oranges.py b/problems/0994-rotting-oranges/0994-rotting-oranges.py similarity index 100% rename from 0994-rotting-oranges/0994-rotting-oranges.py rename to problems/0994-rotting-oranges/0994-rotting-oranges.py diff --git a/0994-rotting-oranges/NOTES.md b/problems/0994-rotting-oranges/NOTES.md similarity index 100% rename from 0994-rotting-oranges/NOTES.md rename to problems/0994-rotting-oranges/NOTES.md diff --git a/problems/0994-rotting-oranges/README.md b/problems/0994-rotting-oranges/README.md new file mode 100644 index 000000000..1eb3cfc3c --- /dev/null +++ b/problems/0994-rotting-oranges/README.md @@ -0,0 +1,43 @@ +

994. Rotting Oranges

Medium


You are given an m x n grid where each cell can have one of three values:

+ +
    +
  • 0 representing an empty cell,
  • +
  • 1 representing a fresh orange, or
  • +
  • 2 representing a rotten orange.
  • +
+ +

Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.

+ +

Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1.

+ +

 

+

Example 1:

+ +
Input: grid = [[2,1,1],[1,1,0],[0,1,1]]
+Output: 4
+
+ +

Example 2:

+ +
Input: grid = [[2,1,1],[0,1,1],[1,0,1]]
+Output: -1
+Explanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally.
+
+ +

Example 3:

+ +
Input: grid = [[0,2]]
+Output: 0
+Explanation: Since there are already no fresh oranges at minute 0, the answer is just 0.
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 10
  • +
  • grid[i][j] is 0, 1, or 2.
  • +
+
\ No newline at end of file diff --git a/0995-minimum-number-of-k-consecutive-bit-flips/0995-minimum-number-of-k-consecutive-bit-flips.py b/problems/0995-minimum-number-of-k-consecutive-bit-flips/0995-minimum-number-of-k-consecutive-bit-flips.py similarity index 100% rename from 0995-minimum-number-of-k-consecutive-bit-flips/0995-minimum-number-of-k-consecutive-bit-flips.py rename to problems/0995-minimum-number-of-k-consecutive-bit-flips/0995-minimum-number-of-k-consecutive-bit-flips.py diff --git a/problems/0995-minimum-number-of-k-consecutive-bit-flips/README.md b/problems/0995-minimum-number-of-k-consecutive-bit-flips/README.md new file mode 100644 index 000000000..4a559ed8d --- /dev/null +++ b/problems/0995-minimum-number-of-k-consecutive-bit-flips/README.md @@ -0,0 +1,41 @@ +

995. Minimum Number of K Consecutive Bit Flips

Hard


You are given a binary array nums and an integer k.

+ +

A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.

+ +

Return the minimum number of k-bit flips required so that there is no 0 in the array. If it is not possible, return -1.

+ +

A subarray is a contiguous part of an array.

+ +

 

+

Example 1:

+ +
Input: nums = [0,1,0], k = 1
+Output: 2
+Explanation: Flip nums[0], then flip nums[2].
+
+ +

Example 2:

+ +
Input: nums = [1,1,0], k = 2
+Output: -1
+Explanation: No matter how we flip subarrays of size 2, we cannot make the array become [1,1,1].
+
+ +

Example 3:

+ +
Input: nums = [0,0,0,1,0,1,1,0], k = 3
+Output: 3
+Explanation: 
+Flip nums[0],nums[1],nums[2]: nums becomes [1,1,1,1,0,1,1,0]
+Flip nums[4],nums[5],nums[6]: nums becomes [1,1,1,1,1,0,0,0]
+Flip nums[5],nums[6],nums[7]: nums becomes [1,1,1,1,1,1,1,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= k <= nums.length
  • +
+
\ No newline at end of file diff --git a/0997-find-the-town-judge/0997-find-the-town-judge.py b/problems/0997-find-the-town-judge/0997-find-the-town-judge.py similarity index 100% rename from 0997-find-the-town-judge/0997-find-the-town-judge.py rename to problems/0997-find-the-town-judge/0997-find-the-town-judge.py diff --git a/0997-find-the-town-judge/NOTES.md b/problems/0997-find-the-town-judge/NOTES.md similarity index 100% rename from 0997-find-the-town-judge/NOTES.md rename to problems/0997-find-the-town-judge/NOTES.md diff --git a/problems/0997-find-the-town-judge/README.md b/problems/0997-find-the-town-judge/README.md new file mode 100644 index 000000000..a95c8d86b --- /dev/null +++ b/problems/0997-find-the-town-judge/README.md @@ -0,0 +1,45 @@ +

997. Find the Town Judge

Easy


In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.

+ +

If the town judge exists, then:

+ +
    +
  1. The town judge trusts nobody.
  2. +
  3. Everybody (except for the town judge) trusts the town judge.
  4. +
  5. There is exactly one person that satisfies properties 1 and 2.
  6. +
+ +

You are given an array trust where trust[i] = [ai, bi] representing that the person labeled ai trusts the person labeled bi. If a trust relationship does not exist in trust array, then such a trust relationship does not exist.

+ +

Return the label of the town judge if the town judge exists and can be identified, or return -1 otherwise.

+ +

 

+

Example 1:

+ +
Input: n = 2, trust = [[1,2]]
+Output: 2
+
+ +

Example 2:

+ +
Input: n = 3, trust = [[1,3],[2,3]]
+Output: 3
+
+ +

Example 3:

+ +
Input: n = 3, trust = [[1,3],[2,3],[3,1]]
+Output: -1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1000
  • +
  • 0 <= trust.length <= 104
  • +
  • trust[i].length == 2
  • +
  • All the pairs of trust are unique.
  • +
  • ai != bi
  • +
  • 1 <= ai, bi <= n
  • +
+
\ No newline at end of file diff --git a/1002-find-common-characters/1002-find-common-characters.py b/problems/1002-find-common-characters/1002-find-common-characters.py similarity index 100% rename from 1002-find-common-characters/1002-find-common-characters.py rename to problems/1002-find-common-characters/1002-find-common-characters.py diff --git a/1002-find-common-characters/NOTES.md b/problems/1002-find-common-characters/NOTES.md similarity index 100% rename from 1002-find-common-characters/NOTES.md rename to problems/1002-find-common-characters/NOTES.md diff --git a/problems/1002-find-common-characters/README.md b/problems/1002-find-common-characters/README.md new file mode 100644 index 000000000..54c8be402 --- /dev/null +++ b/problems/1002-find-common-characters/README.md @@ -0,0 +1,19 @@ +

1002. Find Common Characters

Easy


Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.

+ +

 

+

Example 1:

+
Input: words = ["bella","label","roller"]
+Output: ["e","l","l"]
+

Example 2:

+
Input: words = ["cool","lock","cook"]
+Output: ["c","o"]
+
+

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 100
  • +
  • 1 <= words[i].length <= 100
  • +
  • words[i] consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1026-maximum-difference-between-node-and-ancestor/1026-maximum-difference-between-node-and-ancestor.py b/problems/1026-maximum-difference-between-node-and-ancestor/1026-maximum-difference-between-node-and-ancestor.py similarity index 100% rename from 1026-maximum-difference-between-node-and-ancestor/1026-maximum-difference-between-node-and-ancestor.py rename to problems/1026-maximum-difference-between-node-and-ancestor/1026-maximum-difference-between-node-and-ancestor.py diff --git a/1026-maximum-difference-between-node-and-ancestor/NOTES.md b/problems/1026-maximum-difference-between-node-and-ancestor/NOTES.md similarity index 100% rename from 1026-maximum-difference-between-node-and-ancestor/NOTES.md rename to problems/1026-maximum-difference-between-node-and-ancestor/NOTES.md diff --git a/problems/1026-maximum-difference-between-node-and-ancestor/README.md b/problems/1026-maximum-difference-between-node-and-ancestor/README.md new file mode 100644 index 000000000..67c353c51 --- /dev/null +++ b/problems/1026-maximum-difference-between-node-and-ancestor/README.md @@ -0,0 +1,30 @@ +

1026. Maximum Difference Between Node and Ancestor

Medium


Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b.

+ +

A node a is an ancestor of b if either: any child of a is equal to b or any child of a is an ancestor of b.

+ +

 

+

Example 1:

+ +
Input: root = [8,3,10,1,6,null,14,null,null,4,7,13]
+Output: 7
+Explanation: We have various ancestor-node differences, some of which are given below :
+|8 - 3| = 5
+|3 - 7| = 4
+|8 - 1| = 7
+|10 - 13| = 3
+Among all possible differences, the maximum value of 7 is obtained by |8 - 1| = 7.
+ +

Example 2:

+ +
Input: root = [1,null,2,null,0,3]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [2, 5000].
  • +
  • 0 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/1038-binary-search-tree-to-greater-sum-tree/1038-binary-search-tree-to-greater-sum-tree.py b/problems/1038-binary-search-tree-to-greater-sum-tree/1038-binary-search-tree-to-greater-sum-tree.py similarity index 100% rename from 1038-binary-search-tree-to-greater-sum-tree/1038-binary-search-tree-to-greater-sum-tree.py rename to problems/1038-binary-search-tree-to-greater-sum-tree/1038-binary-search-tree-to-greater-sum-tree.py diff --git a/1038-binary-search-tree-to-greater-sum-tree/NOTES.md b/problems/1038-binary-search-tree-to-greater-sum-tree/NOTES.md similarity index 100% rename from 1038-binary-search-tree-to-greater-sum-tree/NOTES.md rename to problems/1038-binary-search-tree-to-greater-sum-tree/NOTES.md diff --git a/1043-partition-array-for-maximum-sum/1043-partition-array-for-maximum-sum.py b/problems/1043-partition-array-for-maximum-sum/1043-partition-array-for-maximum-sum.py similarity index 100% rename from 1043-partition-array-for-maximum-sum/1043-partition-array-for-maximum-sum.py rename to problems/1043-partition-array-for-maximum-sum/1043-partition-array-for-maximum-sum.py diff --git a/1043-partition-array-for-maximum-sum/NOTES.md b/problems/1043-partition-array-for-maximum-sum/NOTES.md similarity index 100% rename from 1043-partition-array-for-maximum-sum/NOTES.md rename to problems/1043-partition-array-for-maximum-sum/NOTES.md diff --git a/problems/1043-partition-array-for-maximum-sum/README.md b/problems/1043-partition-array-for-maximum-sum/README.md new file mode 100644 index 000000000..c0114e419 --- /dev/null +++ b/problems/1043-partition-array-for-maximum-sum/README.md @@ -0,0 +1,33 @@ +

1043. Partition Array for Maximum Sum

Medium


Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.

+ +

Return the largest sum of the given array after partitioning. Test cases are generated so that the answer fits in a 32-bit integer.

+ +

 

+

Example 1:

+ +
Input: arr = [1,15,7,9,2,5,10], k = 3
+Output: 84
+Explanation: arr becomes [15,15,15,9,10,10,10]
+
+ +

Example 2:

+ +
Input: arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4
+Output: 83
+
+ +

Example 3:

+ +
Input: arr = [1], k = 1
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 500
  • +
  • 0 <= arr[i] <= 109
  • +
  • 1 <= k <= arr.length
  • +
+
\ No newline at end of file diff --git a/1046-last-stone-weight/1046-last-stone-weight.py b/problems/1046-last-stone-weight/1046-last-stone-weight.py similarity index 100% rename from 1046-last-stone-weight/1046-last-stone-weight.py rename to problems/1046-last-stone-weight/1046-last-stone-weight.py diff --git a/1046-last-stone-weight/NOTES.md b/problems/1046-last-stone-weight/NOTES.md similarity index 100% rename from 1046-last-stone-weight/NOTES.md rename to problems/1046-last-stone-weight/NOTES.md diff --git a/problems/1046-last-stone-weight/README.md b/problems/1046-last-stone-weight/README.md new file mode 100644 index 000000000..96c0911b2 --- /dev/null +++ b/problems/1046-last-stone-weight/README.md @@ -0,0 +1,39 @@ +

1046. Last Stone Weight

Easy


You are given an array of integers stones where stones[i] is the weight of the ith stone.

+ +

We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is:

+ +
    +
  • If x == y, both stones are destroyed, and
  • +
  • If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.
  • +
+ +

At the end of the game, there is at most one stone left.

+ +

Return the weight of the last remaining stone. If there are no stones left, return 0.

+ +

 

+

Example 1:

+ +
Input: stones = [2,7,4,1,8,1]
+Output: 1
+Explanation: 
+We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,
+we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,
+we combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
+we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of the last stone.
+
+ +

Example 2:

+ +
Input: stones = [1]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= stones.length <= 30
  • +
  • 1 <= stones[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/1048-longest-string-chain/1048-longest-string-chain.py b/problems/1048-longest-string-chain/1048-longest-string-chain.py similarity index 100% rename from 1048-longest-string-chain/1048-longest-string-chain.py rename to problems/1048-longest-string-chain/1048-longest-string-chain.py diff --git a/1048-longest-string-chain/NOTES.md b/problems/1048-longest-string-chain/NOTES.md similarity index 100% rename from 1048-longest-string-chain/NOTES.md rename to problems/1048-longest-string-chain/NOTES.md diff --git a/problems/1048-longest-string-chain/README.md b/problems/1048-longest-string-chain/README.md new file mode 100644 index 000000000..ef989d396 --- /dev/null +++ b/problems/1048-longest-string-chain/README.md @@ -0,0 +1,44 @@ +

1048. Longest String Chain

Medium


You are given an array of words where each word consists of lowercase English letters.

+ +

wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB.

+ +
    +
  • For example, "abc" is a predecessor of "abac", while "cba" is not a predecessor of "bcad".
  • +
+ +

A word chain is a sequence of words [word1, word2, ..., wordk] with k >= 1, where word1 is a predecessor of word2, word2 is a predecessor of word3, and so on. A single word is trivially a word chain with k == 1.

+ +

Return the length of the longest possible word chain with words chosen from the given list of words.

+ +

 

+

Example 1:

+ +
Input: words = ["a","b","ba","bca","bda","bdca"]
+Output: 4
+Explanation: One of the longest word chains is ["a","ba","bda","bdca"].
+
+ +

Example 2:

+ +
Input: words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]
+Output: 5
+Explanation: All the words can be put in a word chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].
+
+ +

Example 3:

+ +
Input: words = ["abcd","dbqca"]
+Output: 1
+Explanation: The trivial word chain ["abcd"] is one of the longest word chains.
+["abcd","dbqca"] is not a valid word chain because the ordering of the letters is changed.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 1000
  • +
  • 1 <= words[i].length <= 16
  • +
  • words[i] only consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1051-height-checker/1051-height-checker.py b/problems/1051-height-checker/1051-height-checker.py similarity index 100% rename from 1051-height-checker/1051-height-checker.py rename to problems/1051-height-checker/1051-height-checker.py diff --git a/1051-height-checker/NOTES.md b/problems/1051-height-checker/NOTES.md similarity index 100% rename from 1051-height-checker/NOTES.md rename to problems/1051-height-checker/NOTES.md diff --git a/problems/1051-height-checker/README.md b/problems/1051-height-checker/README.md new file mode 100644 index 000000000..59363b7ec --- /dev/null +++ b/problems/1051-height-checker/README.md @@ -0,0 +1,45 @@ +

1051. Height Checker

Easy


A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.

+ +

You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed).

+ +

Return the number of indices where heights[i] != expected[i].

+ +

 

+

Example 1:

+ +
Input: heights = [1,1,4,2,1,3]
+Output: 3
+Explanation: 
+heights:  [1,1,4,2,1,3]
+expected: [1,1,1,2,3,4]
+Indices 2, 4, and 5 do not match.
+
+ +

Example 2:

+ +
Input: heights = [5,1,2,3,4]
+Output: 5
+Explanation:
+heights:  [5,1,2,3,4]
+expected: [1,2,3,4,5]
+All indices do not match.
+
+ +

Example 3:

+ +
Input: heights = [1,2,3,4,5]
+Output: 0
+Explanation:
+heights:  [1,2,3,4,5]
+expected: [1,2,3,4,5]
+All indices match.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= heights.length <= 100
  • +
  • 1 <= heights[i] <= 100
  • +
+
\ No newline at end of file diff --git a/1052-grumpy-bookstore-owner/1052-grumpy-bookstore-owner.py b/problems/1052-grumpy-bookstore-owner/1052-grumpy-bookstore-owner.py similarity index 100% rename from 1052-grumpy-bookstore-owner/1052-grumpy-bookstore-owner.py rename to problems/1052-grumpy-bookstore-owner/1052-grumpy-bookstore-owner.py diff --git a/1052-grumpy-bookstore-owner/NOTES.md b/problems/1052-grumpy-bookstore-owner/NOTES.md similarity index 100% rename from 1052-grumpy-bookstore-owner/NOTES.md rename to problems/1052-grumpy-bookstore-owner/NOTES.md diff --git a/problems/1052-grumpy-bookstore-owner/README.md b/problems/1052-grumpy-bookstore-owner/README.md new file mode 100644 index 000000000..dce57e167 --- /dev/null +++ b/problems/1052-grumpy-bookstore-owner/README.md @@ -0,0 +1,35 @@ +

1052. Grumpy Bookstore Owner

Medium


There is a bookstore owner that has a store open for n minutes. Every minute, some number of customers enter the store. You are given an integer array customers of length n where customers[i] is the number of the customer that enters the store at the start of the ith minute and all those customers leave after the end of that minute.

+ +

On some minutes, the bookstore owner is grumpy. You are given a binary array grumpy where grumpy[i] is 1 if the bookstore owner is grumpy during the ith minute, and is 0 otherwise.

+ +

When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise, they are satisfied.

+ +

The bookstore owner knows a secret technique to keep themselves not grumpy for minutes consecutive minutes, but can only use it once.

+ +

Return the maximum number of customers that can be satisfied throughout the day.

+ +

 

+

Example 1:

+ +
Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
+Output: 16
+Explanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. 
+The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
+
+ +

Example 2:

+ +
Input: customers = [1], grumpy = [0], minutes = 1
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • n == customers.length == grumpy.length
  • +
  • 1 <= minutes <= n <= 2 * 104
  • +
  • 0 <= customers[i] <= 1000
  • +
  • grumpy[i] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/1057-campus-bikes/1057-campus-bikes.py b/problems/1057-campus-bikes/1057-campus-bikes.py similarity index 100% rename from 1057-campus-bikes/1057-campus-bikes.py rename to problems/1057-campus-bikes/1057-campus-bikes.py diff --git a/1057-campus-bikes/NOTES.md b/problems/1057-campus-bikes/NOTES.md similarity index 100% rename from 1057-campus-bikes/NOTES.md rename to problems/1057-campus-bikes/NOTES.md diff --git a/problems/1057-campus-bikes/README.md b/problems/1057-campus-bikes/README.md new file mode 100644 index 000000000..d2a150479 --- /dev/null +++ b/problems/1057-campus-bikes/README.md @@ -0,0 +1,40 @@ +

1057. Campus Bikes

Medium


On a campus represented on the X-Y plane, there are n workers and m bikes, with n <= m.

+ +

You are given an array workers of length n where workers[i] = [xi, yi] is the position of the ith worker. You are also given an array bikes of length m where bikes[j] = [xj, yj] is the position of the jth bike. All the given positions are unique.

+ +

Assign a bike to each worker. Among the available bikes and workers, we choose the (workeri, bikej) pair with the shortest Manhattan distance between each other and assign the bike to that worker.

+ +

If there are multiple (workeri, bikej) pairs with the same shortest Manhattan distance, we choose the pair with the smallest worker index. If there are multiple ways to do that, we choose the pair with the smallest bike index. Repeat this process until there are no available workers.

+ +

Return an array answer of length n, where answer[i] is the index (0-indexed) of the bike that the ith worker is assigned to.

+ +

The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

+ +

 

+

Example 1:

+ +
Input: workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]
+Output: [1,0]
+Explanation: Worker 1 grabs Bike 0 as they are closest (without ties), and Worker 0 is assigned Bike 1. So the output is [1, 0].
+
+ +

Example 2:

+ +
Input: workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]
+Output: [0,2,1]
+Explanation: Worker 0 grabs Bike 0 at first. Worker 1 and Worker 2 share the same distance to Bike 2, thus Worker 1 is assigned to Bike 2, and Worker 2 will take Bike 1. So the output is [0,2,1].
+
+ +

 

+

Constraints:

+ +
    +
  • n == workers.length
  • +
  • m == bikes.length
  • +
  • 1 <= n <= m <= 1000
  • +
  • workers[i].length == bikes[j].length == 2
  • +
  • 0 <= xi, yi < 1000
  • +
  • 0 <= xj, yj < 1000
  • +
  • All worker and bike locations are unique.
  • +
+
\ No newline at end of file diff --git a/1060-missing-element-in-sorted-array/1060-missing-element-in-sorted-array.py b/problems/1060-missing-element-in-sorted-array/1060-missing-element-in-sorted-array.py similarity index 100% rename from 1060-missing-element-in-sorted-array/1060-missing-element-in-sorted-array.py rename to problems/1060-missing-element-in-sorted-array/1060-missing-element-in-sorted-array.py diff --git a/1060-missing-element-in-sorted-array/NOTES.md b/problems/1060-missing-element-in-sorted-array/NOTES.md similarity index 100% rename from 1060-missing-element-in-sorted-array/NOTES.md rename to problems/1060-missing-element-in-sorted-array/NOTES.md diff --git a/problems/1060-missing-element-in-sorted-array/README.md b/problems/1060-missing-element-in-sorted-array/README.md new file mode 100644 index 000000000..c6258e4d0 --- /dev/null +++ b/problems/1060-missing-element-in-sorted-array/README.md @@ -0,0 +1,36 @@ +

1060. Missing Element in Sorted Array

Medium


Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.

+ +

 

+

Example 1:

+ +
Input: nums = [4,7,9,10], k = 1
+Output: 5
+Explanation: The first missing number is 5.
+
+ +

Example 2:

+ +
Input: nums = [4,7,9,10], k = 3
+Output: 8
+Explanation: The missing numbers are [5,6,8,...], hence the third missing number is 8.
+
+ +

Example 3:

+ +
Input: nums = [1,2,4], k = 3
+Output: 6
+Explanation: The missing numbers are [3,5,6,7,...], hence the third missing number is 6.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • 1 <= nums[i] <= 107
  • +
  • nums is sorted in ascending order, and all the elements are unique.
  • +
  • 1 <= k <= 108
  • +
+ +

 

+Follow up: Can you find a logarithmic time complexity (i.e., O(log(n))) solution?
\ No newline at end of file diff --git a/1062-longest-repeating-substring/1062-longest-repeating-substring.py b/problems/1062-longest-repeating-substring/1062-longest-repeating-substring.py similarity index 100% rename from 1062-longest-repeating-substring/1062-longest-repeating-substring.py rename to problems/1062-longest-repeating-substring/1062-longest-repeating-substring.py diff --git a/problems/1062-longest-repeating-substring/README.md b/problems/1062-longest-repeating-substring/README.md new file mode 100644 index 000000000..93f6a590b --- /dev/null +++ b/problems/1062-longest-repeating-substring/README.md @@ -0,0 +1,32 @@ +

1062. Longest Repeating Substring

Medium


Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.

+ +

 

+

Example 1:

+ +
Input: s = "abcd"
+Output: 0
+Explanation: There is no repeating substring.
+
+ +

Example 2:

+ +
Input: s = "abbaba"
+Output: 2
+Explanation: The longest repeating substrings are "ab" and "ba", each of which occurs twice.
+
+ +

Example 3:

+ +
Input: s = "aabcaabdaab"
+Output: 3
+Explanation: The longest repeating substring is "aab", which occurs 3 times.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 2000
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1063-number-of-valid-subarrays/1063-number-of-valid-subarrays.py b/problems/1063-number-of-valid-subarrays/1063-number-of-valid-subarrays.py similarity index 100% rename from 1063-number-of-valid-subarrays/1063-number-of-valid-subarrays.py rename to problems/1063-number-of-valid-subarrays/1063-number-of-valid-subarrays.py diff --git a/1063-number-of-valid-subarrays/NOTES.md b/problems/1063-number-of-valid-subarrays/NOTES.md similarity index 100% rename from 1063-number-of-valid-subarrays/NOTES.md rename to problems/1063-number-of-valid-subarrays/NOTES.md diff --git a/problems/1063-number-of-valid-subarrays/README.md b/problems/1063-number-of-valid-subarrays/README.md new file mode 100644 index 000000000..0f4498bb1 --- /dev/null +++ b/problems/1063-number-of-valid-subarrays/README.md @@ -0,0 +1,34 @@ +

1063. Number of Valid Subarrays

Hard


Given an integer array nums, return the number of non-empty subarrays with the leftmost element of the subarray not larger than other elements in the subarray.

+ +

A subarray is a contiguous part of an array.

+ +

 

+

Example 1:

+ +
Input: nums = [1,4,2,5,3]
+Output: 11
+Explanation: There are 11 valid subarrays: [1],[4],[2],[5],[3],[1,4],[2,5],[1,4,2],[2,5,3],[1,4,2,5],[1,4,2,5,3].
+
+ +

Example 2:

+ +
Input: nums = [3,2,1]
+Output: 3
+Explanation: The 3 valid subarrays are: [3],[2],[1].
+
+ +

Example 3:

+ +
Input: nums = [2,2,2]
+Output: 6
+Explanation: There are 6 valid subarrays: [2],[2],[2],[2,2],[2,2],[2,2,2].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • 0 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/1066-campus-bikes-ii/1066-campus-bikes-ii.py b/problems/1066-campus-bikes-ii/1066-campus-bikes-ii.py similarity index 100% rename from 1066-campus-bikes-ii/1066-campus-bikes-ii.py rename to problems/1066-campus-bikes-ii/1066-campus-bikes-ii.py diff --git a/1066-campus-bikes-ii/NOTES.md b/problems/1066-campus-bikes-ii/NOTES.md similarity index 100% rename from 1066-campus-bikes-ii/NOTES.md rename to problems/1066-campus-bikes-ii/NOTES.md diff --git a/problems/1066-campus-bikes-ii/README.md b/problems/1066-campus-bikes-ii/README.md new file mode 100644 index 000000000..db2187717 --- /dev/null +++ b/problems/1066-campus-bikes-ii/README.md @@ -0,0 +1,44 @@ +

1066. Campus Bikes II

Medium


On a campus represented as a 2D grid, there are n workers and m bikes, with n <= m. Each worker and bike is a 2D coordinate on this grid.

+ +

We assign one unique bike to each worker so that the sum of the Manhattan distances between each worker and their assigned bike is minimized.

+ +

Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.

+ +

The Manhattan distance between two points p1 and p2 is Manhattan(p1, p2) = |p1.x - p2.x| + |p1.y - p2.y|.

+ +

 

+

Example 1:

+ +
Input: workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]
+Output: 6
+Explanation: 
+We assign bike 0 to worker 0, bike 1 to worker 1. The Manhattan distance of both assignments is 3, so the output is 6.
+
+ +

Example 2:

+ +
Input: workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]
+Output: 4
+Explanation: 
+We first assign bike 0 to worker 0, then assign bike 1 to worker 1 or worker 2, bike 2 to worker 2 or worker 1. Both assignments lead to sum of the Manhattan distances as 4.
+
+ +

Example 3:

+ +
Input: workers = [[0,0],[1,0],[2,0],[3,0],[4,0]], bikes = [[0,999],[1,999],[2,999],[3,999],[4,999]]
+Output: 4995
+
+ +

 

+

Constraints:

+ +
    +
  • n == workers.length
  • +
  • m == bikes.length
  • +
  • 1 <= n <= m <= 10
  • +
  • workers[i].length == 2
  • +
  • bikes[i].length == 2
  • +
  • 0 <= workers[i][0], workers[i][1], bikes[i][0], bikes[i][1] < 1000
  • +
  • All the workers and the bikes locations are unique.
  • +
+
\ No newline at end of file diff --git a/1071-greatest-common-divisor-of-strings/1071-greatest-common-divisor-of-strings.py b/problems/1071-greatest-common-divisor-of-strings/1071-greatest-common-divisor-of-strings.py similarity index 100% rename from 1071-greatest-common-divisor-of-strings/1071-greatest-common-divisor-of-strings.py rename to problems/1071-greatest-common-divisor-of-strings/1071-greatest-common-divisor-of-strings.py diff --git a/1071-greatest-common-divisor-of-strings/NOTES.md b/problems/1071-greatest-common-divisor-of-strings/NOTES.md similarity index 100% rename from 1071-greatest-common-divisor-of-strings/NOTES.md rename to problems/1071-greatest-common-divisor-of-strings/NOTES.md diff --git a/problems/1071-greatest-common-divisor-of-strings/README.md b/problems/1071-greatest-common-divisor-of-strings/README.md new file mode 100644 index 000000000..67a8a3af8 --- /dev/null +++ b/problems/1071-greatest-common-divisor-of-strings/README.md @@ -0,0 +1,31 @@ +

1071. Greatest Common Divisor of Strings

Easy


For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times).

+ +

Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.

+ +

 

+

Example 1:

+ +
Input: str1 = "ABCABC", str2 = "ABC"
+Output: "ABC"
+
+ +

Example 2:

+ +
Input: str1 = "ABABAB", str2 = "ABAB"
+Output: "AB"
+
+ +

Example 3:

+ +
Input: str1 = "LEET", str2 = "CODE"
+Output: ""
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= str1.length, str2.length <= 1000
  • +
  • str1 and str2 consist of English uppercase letters.
  • +
+
\ No newline at end of file diff --git a/1074-number-of-submatrices-that-sum-to-target/1074-number-of-submatrices-that-sum-to-target.py b/problems/1074-number-of-submatrices-that-sum-to-target/1074-number-of-submatrices-that-sum-to-target.py similarity index 100% rename from 1074-number-of-submatrices-that-sum-to-target/1074-number-of-submatrices-that-sum-to-target.py rename to problems/1074-number-of-submatrices-that-sum-to-target/1074-number-of-submatrices-that-sum-to-target.py diff --git a/1074-number-of-submatrices-that-sum-to-target/NOTES.md b/problems/1074-number-of-submatrices-that-sum-to-target/NOTES.md similarity index 100% rename from 1074-number-of-submatrices-that-sum-to-target/NOTES.md rename to problems/1074-number-of-submatrices-that-sum-to-target/NOTES.md diff --git a/problems/1074-number-of-submatrices-that-sum-to-target/README.md b/problems/1074-number-of-submatrices-that-sum-to-target/README.md new file mode 100644 index 000000000..e73500102 --- /dev/null +++ b/problems/1074-number-of-submatrices-that-sum-to-target/README.md @@ -0,0 +1,37 @@ +

1074. Number of Submatrices That Sum to Target

Hard


Given a matrix and a target, return the number of non-empty submatrices that sum to target.

+ +

A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2.

+ +

Two submatrices (x1, y1, x2, y2) and (x1', y1', x2', y2') are different if they have some coordinate that is different: for example, if x1 != x1'.

+ +

 

+

Example 1:

+ +
Input: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0
+Output: 4
+Explanation: The four 1x1 submatrices that only contain 0.
+
+ +

Example 2:

+ +
Input: matrix = [[1,-1],[-1,1]], target = 0
+Output: 5
+Explanation: The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.
+
+ +

Example 3:

+ +
Input: matrix = [[904]], target = 0
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= matrix.length <= 100
  • +
  • 1 <= matrix[0].length <= 100
  • +
  • -1000 <= matrix[i] <= 1000
  • +
  • -10^8 <= target <= 10^8
  • +
+
\ No newline at end of file diff --git a/1095-find-in-mountain-array/1095-find-in-mountain-array.py b/problems/1095-find-in-mountain-array/1095-find-in-mountain-array.py similarity index 100% rename from 1095-find-in-mountain-array/1095-find-in-mountain-array.py rename to problems/1095-find-in-mountain-array/1095-find-in-mountain-array.py diff --git a/1095-find-in-mountain-array/NOTES.md b/problems/1095-find-in-mountain-array/NOTES.md similarity index 100% rename from 1095-find-in-mountain-array/NOTES.md rename to problems/1095-find-in-mountain-array/NOTES.md diff --git a/problems/1095-find-in-mountain-array/README.md b/problems/1095-find-in-mountain-array/README.md new file mode 100644 index 000000000..217db3203 --- /dev/null +++ b/problems/1095-find-in-mountain-array/README.md @@ -0,0 +1,48 @@ +

1095. Find in Mountain Array

Hard


(This problem is an interactive problem.)

+ +

You may recall that an array arr is a mountain array if and only if:

+ +
    +
  • arr.length >= 3
  • +
  • There exists some i with 0 < i < arr.length - 1 such that: +
      +
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • +
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
    • +
    +
  • +
+ +

Given a mountain array mountainArr, return the minimum index such that mountainArr.get(index) == target. If such an index does not exist, return -1.

+ +

You cannot access the mountain array directly. You may only access the array using a MountainArray interface:

+ +
    +
  • MountainArray.get(k) returns the element of the array at index k (0-indexed).
  • +
  • MountainArray.length() returns the length of the array.
  • +
+ +

Submissions making more than 100 calls to MountainArray.get will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.

+ +

 

+

Example 1:

+ +
Input: array = [1,2,3,4,5,3,1], target = 3
+Output: 2
+Explanation: 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.
+ +

Example 2:

+ +
Input: array = [0,1,2,4,2,1], target = 3
+Output: -1
+Explanation: 3 does not exist in the array, so we return -1.
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= mountain_arr.length() <= 104
  • +
  • 0 <= target <= 109
  • +
  • 0 <= mountain_arr.get(index) <= 109
  • +
+
\ No newline at end of file diff --git a/1099-two-sum-less-than-k/1099-two-sum-less-than-k.py b/problems/1099-two-sum-less-than-k/1099-two-sum-less-than-k.py similarity index 100% rename from 1099-two-sum-less-than-k/1099-two-sum-less-than-k.py rename to problems/1099-two-sum-less-than-k/1099-two-sum-less-than-k.py diff --git a/1099-two-sum-less-than-k/NOTES.md b/problems/1099-two-sum-less-than-k/NOTES.md similarity index 100% rename from 1099-two-sum-less-than-k/NOTES.md rename to problems/1099-two-sum-less-than-k/NOTES.md diff --git a/problems/1099-two-sum-less-than-k/README.md b/problems/1099-two-sum-less-than-k/README.md new file mode 100644 index 000000000..212aaeb1c --- /dev/null +++ b/problems/1099-two-sum-less-than-k/README.md @@ -0,0 +1,26 @@ +

1099. Two Sum Less Than K

Easy


Given an array nums of integers and integer k, return the maximum sum such that there exists i < j with nums[i] + nums[j] = sum and sum < k. If no i, j exist satisfying this equation, return -1.

+ +

 

+

Example 1:

+ +
Input: nums = [34,23,1,24,75,33,54,8], k = 60
+Output: 58
+Explanation: We can use 34 and 24 to sum 58 which is less than 60.
+
+ +

Example 2:

+ +
Input: nums = [10,20,30], k = 15
+Output: -1
+Explanation: In this case it is not possible to get a pair sum less that 15.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 1 <= nums[i] <= 1000
  • +
  • 1 <= k <= 2000
  • +
+
\ No newline at end of file diff --git a/1101-the-earliest-moment-when-everyone-become-friends/1101-the-earliest-moment-when-everyone-become-friends.py b/problems/1101-the-earliest-moment-when-everyone-become-friends/1101-the-earliest-moment-when-everyone-become-friends.py similarity index 100% rename from 1101-the-earliest-moment-when-everyone-become-friends/1101-the-earliest-moment-when-everyone-become-friends.py rename to problems/1101-the-earliest-moment-when-everyone-become-friends/1101-the-earliest-moment-when-everyone-become-friends.py diff --git a/problems/1101-the-earliest-moment-when-everyone-become-friends/README.md b/problems/1101-the-earliest-moment-when-everyone-become-friends/README.md new file mode 100644 index 000000000..fcfdbee75 --- /dev/null +++ b/problems/1101-the-earliest-moment-when-everyone-become-friends/README.md @@ -0,0 +1,41 @@ +

1101. The Earliest Moment When Everyone Become Friends

Medium


There are n people in a social group labeled from 0 to n - 1. You are given an array logs where logs[i] = [timestampi, xi, yi] indicates that xi and yi will be friends at the time timestampi.

+ +

Friendship is symmetric. That means if a is friends with b, then b is friends with a. Also, person a is acquainted with a person b if a is friends with b, or a is a friend of someone acquainted with b.

+ +

Return the earliest time for which every person became acquainted with every other person. If there is no such earliest time, return -1.

+ +

 

+

Example 1:

+ +
Input: logs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], n = 6
+Output: 20190301
+Explanation: 
+The first event occurs at timestamp = 20190101, and after 0 and 1 become friends, we have the following friendship groups [0,1], [2], [3], [4], [5].
+The second event occurs at timestamp = 20190104, and after 3 and 4 become friends, we have the following friendship groups [0,1], [2], [3,4], [5].
+The third event occurs at timestamp = 20190107, and after 2 and 3 become friends, we have the following friendship groups [0,1], [2,3,4], [5].
+The fourth event occurs at timestamp = 20190211, and after 1 and 5 become friends, we have the following friendship groups [0,1,5], [2,3,4].
+The fifth event occurs at timestamp = 20190224, and as 2 and 4 are already friends, nothing happens.
+The sixth event occurs at timestamp = 20190301, and after 0 and 3 become friends, we all become friends.
+
+ +

Example 2:

+ +
Input: logs = [[0,2,0],[1,0,1],[3,0,3],[4,1,2],[7,3,1]], n = 4
+Output: 3
+Explanation: At timestamp = 3, all the persons (i.e., 0, 1, 2, and 3) become friends.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 100
  • +
  • 1 <= logs.length <= 104
  • +
  • logs[i].length == 3
  • +
  • 0 <= timestampi <= 109
  • +
  • 0 <= xi, yi <= n - 1
  • +
  • xi != yi
  • +
  • All the values timestampi are unique.
  • +
  • All the pairs (xi, yi) occur at most one time in the input.
  • +
+
\ No newline at end of file diff --git a/1105-filling-bookcase-shelves/1105-filling-bookcase-shelves.py b/problems/1105-filling-bookcase-shelves/1105-filling-bookcase-shelves.py similarity index 100% rename from 1105-filling-bookcase-shelves/1105-filling-bookcase-shelves.py rename to problems/1105-filling-bookcase-shelves/1105-filling-bookcase-shelves.py diff --git a/1105-filling-bookcase-shelves/NOTES.md b/problems/1105-filling-bookcase-shelves/NOTES.md similarity index 100% rename from 1105-filling-bookcase-shelves/NOTES.md rename to problems/1105-filling-bookcase-shelves/NOTES.md diff --git a/problems/1105-filling-bookcase-shelves/README.md b/problems/1105-filling-bookcase-shelves/README.md new file mode 100644 index 000000000..a85820e4e --- /dev/null +++ b/problems/1105-filling-bookcase-shelves/README.md @@ -0,0 +1,39 @@ +

1105. Filling Bookcase Shelves

Medium


You are given an array books where books[i] = [thicknessi, heighti] indicates the thickness and height of the ith book. You are also given an integer shelfWidth.

+ +

We want to place these books in order onto bookcase shelves that have a total width shelfWidth.

+ +

We choose some of the books to place on this shelf such that the sum of their thickness is less than or equal to shelfWidth, then build another level of the shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down. We repeat this process until there are no more books to place.

+ +

Note that at each step of the above process, the order of the books we place is the same order as the given sequence of books.

+ +
    +
  • For example, if we have an ordered list of 5 books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.
  • +
+ +

Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.

+ +

 

+

Example 1:

+ +
Input: books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelfWidth = 4
+Output: 6
+Explanation:
+The sum of the heights of the 3 shelves is 1 + 3 + 2 = 6.
+Notice that book number 2 does not have to be on the first shelf.
+
+ +

Example 2:

+ +
Input: books = [[1,3],[2,4],[3,2]], shelfWidth = 6
+Output: 4
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= books.length <= 1000
  • +
  • 1 <= thicknessi <= shelfWidth <= 1000
  • +
  • 1 <= heighti <= 1000
  • +
+
\ No newline at end of file diff --git a/1110-delete-nodes-and-return-forest/1110-delete-nodes-and-return-forest.py b/problems/1110-delete-nodes-and-return-forest/1110-delete-nodes-and-return-forest.py similarity index 100% rename from 1110-delete-nodes-and-return-forest/1110-delete-nodes-and-return-forest.py rename to problems/1110-delete-nodes-and-return-forest/1110-delete-nodes-and-return-forest.py diff --git a/problems/1110-delete-nodes-and-return-forest/README.md b/problems/1110-delete-nodes-and-return-forest/README.md new file mode 100644 index 000000000..d613487a2 --- /dev/null +++ b/problems/1110-delete-nodes-and-return-forest/README.md @@ -0,0 +1,29 @@ +

1110. Delete Nodes And Return Forest

Medium


Given the root of a binary tree, each node in the tree has a distinct value.

+ +

After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).

+ +

Return the roots of the trees in the remaining forest. You may return the result in any order.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,4,5,6,7], to_delete = [3,5]
+Output: [[1,2,null,4],[6],[7]]
+
+ +

Example 2:

+ +
Input: root = [1,2,4,null,3], to_delete = [3]
+Output: [[1,2,4]]
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the given tree is at most 1000.
  • +
  • Each node has a distinct value between 1 and 1000.
  • +
  • to_delete.length <= 1000
  • +
  • to_delete contains distinct values between 1 and 1000.
  • +
+
\ No newline at end of file diff --git a/1119-remove-vowels-from-a-string/1119-remove-vowels-from-a-string.py b/problems/1119-remove-vowels-from-a-string/1119-remove-vowels-from-a-string.py similarity index 100% rename from 1119-remove-vowels-from-a-string/1119-remove-vowels-from-a-string.py rename to problems/1119-remove-vowels-from-a-string/1119-remove-vowels-from-a-string.py diff --git a/problems/1119-remove-vowels-from-a-string/README.md b/problems/1119-remove-vowels-from-a-string/README.md new file mode 100644 index 000000000..efd8de961 --- /dev/null +++ b/problems/1119-remove-vowels-from-a-string/README.md @@ -0,0 +1,23 @@ +

1119. Remove Vowels from a String

Easy


Given a string s, remove the vowels 'a', 'e', 'i', 'o', and 'u' from it, and return the new string.

+ +

 

+

Example 1:

+ +
Input: s = "leetcodeisacommunityforcoders"
+Output: "ltcdscmmntyfrcdrs"
+
+ +

Example 2:

+ +
Input: s = "aeiou"
+Output: ""
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consists of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1120-maximum-average-subtree/1120-maximum-average-subtree.py b/problems/1120-maximum-average-subtree/1120-maximum-average-subtree.py similarity index 100% rename from 1120-maximum-average-subtree/1120-maximum-average-subtree.py rename to problems/1120-maximum-average-subtree/1120-maximum-average-subtree.py diff --git a/1120-maximum-average-subtree/NOTES.md b/problems/1120-maximum-average-subtree/NOTES.md similarity index 100% rename from 1120-maximum-average-subtree/NOTES.md rename to problems/1120-maximum-average-subtree/NOTES.md diff --git a/problems/1120-maximum-average-subtree/README.md b/problems/1120-maximum-average-subtree/README.md new file mode 100644 index 000000000..1b9575cff --- /dev/null +++ b/problems/1120-maximum-average-subtree/README.md @@ -0,0 +1,32 @@ +

1120. Maximum Average Subtree

Medium


Given the root of a binary tree, return the maximum average value of a subtree of that tree. Answers within 10-5 of the actual answer will be accepted.

+ +

A subtree of a tree is any node of that tree plus all its descendants.

+ +

The average value of a tree is the sum of its values, divided by the number of nodes.

+ +

 

+

Example 1:

+ +
Input: root = [5,6,1]
+Output: 6.00000
+Explanation: 
+For the node with value = 5 we have an average of (5 + 6 + 1) / 3 = 4.
+For the node with value = 6 we have an average of 6 / 1 = 6.
+For the node with value = 1 we have an average of 1 / 1 = 1.
+So the answer is 6 which is the maximum.
+
+ +

Example 2:

+ +
Input: root = [0,null,1]
+Output: 1.00000
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • 0 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/1122-relative-sort-array/1122-relative-sort-array.py b/problems/1122-relative-sort-array/1122-relative-sort-array.py similarity index 100% rename from 1122-relative-sort-array/1122-relative-sort-array.py rename to problems/1122-relative-sort-array/1122-relative-sort-array.py diff --git a/1122-relative-sort-array/NOTES.md b/problems/1122-relative-sort-array/NOTES.md similarity index 100% rename from 1122-relative-sort-array/NOTES.md rename to problems/1122-relative-sort-array/NOTES.md diff --git a/problems/1122-relative-sort-array/README.md b/problems/1122-relative-sort-array/README.md new file mode 100644 index 000000000..fabd6b8ca --- /dev/null +++ b/problems/1122-relative-sort-array/README.md @@ -0,0 +1,27 @@ +

1122. Relative Sort Array

Easy


Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.

+ +

Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order.

+ +

 

+

Example 1:

+ +
Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]
+Output: [2,2,2,1,4,3,3,9,6,7,19]
+
+ +

Example 2:

+ +
Input: arr1 = [28,6,22,8,44,17], arr2 = [22,28,8,6]
+Output: [22,28,8,6,17,44]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr1.length, arr2.length <= 1000
  • +
  • 0 <= arr1[i], arr2[i] <= 1000
  • +
  • All the elements of arr2 are distinct.
  • +
  • Each arr2[i] is in arr1.
  • +
+
\ No newline at end of file diff --git a/1136-parallel-courses/1136-parallel-courses.py b/problems/1136-parallel-courses/1136-parallel-courses.py similarity index 100% rename from 1136-parallel-courses/1136-parallel-courses.py rename to problems/1136-parallel-courses/1136-parallel-courses.py diff --git a/1136-parallel-courses/NOTES.md b/problems/1136-parallel-courses/NOTES.md similarity index 100% rename from 1136-parallel-courses/NOTES.md rename to problems/1136-parallel-courses/NOTES.md diff --git a/problems/1136-parallel-courses/README.md b/problems/1136-parallel-courses/README.md new file mode 100644 index 000000000..d4d7b7b12 --- /dev/null +++ b/problems/1136-parallel-courses/README.md @@ -0,0 +1,35 @@ +

1136. Parallel Courses

Medium


You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representing a prerequisite relationship between course prevCoursei and course nextCoursei: course prevCoursei has to be taken before course nextCoursei.

+ +

In one semester, you can take any number of courses as long as you have taken all the prerequisites in the previous semester for the courses you are taking.

+ +

Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.

+ +

 

+

Example 1:

+ +
Input: n = 3, relations = [[1,3],[2,3]]
+Output: 2
+Explanation: The figure above represents the given graph.
+In the first semester, you can take courses 1 and 2.
+In the second semester, you can take course 3.
+
+ +

Example 2:

+ +
Input: n = 3, relations = [[1,2],[2,3],[3,1]]
+Output: -1
+Explanation: No course can be studied because they are prerequisites of each other.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 5000
  • +
  • 1 <= relations.length <= 5000
  • +
  • relations[i].length == 2
  • +
  • 1 <= prevCoursei, nextCoursei <= n
  • +
  • prevCoursei != nextCoursei
  • +
  • All the pairs [prevCoursei, nextCoursei] are unique.
  • +
+
\ No newline at end of file diff --git a/1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.cpp b/problems/1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.cpp similarity index 100% rename from 1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.cpp rename to problems/1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.cpp diff --git a/1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.py b/problems/1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.py similarity index 100% rename from 1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.py rename to problems/1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.py diff --git a/1137-n-th-tribonacci-number/NOTES.md b/problems/1137-n-th-tribonacci-number/NOTES.md similarity index 100% rename from 1137-n-th-tribonacci-number/NOTES.md rename to problems/1137-n-th-tribonacci-number/NOTES.md diff --git a/problems/1137-n-th-tribonacci-number/README.md b/problems/1137-n-th-tribonacci-number/README.md new file mode 100644 index 000000000..198667d58 --- /dev/null +++ b/problems/1137-n-th-tribonacci-number/README.md @@ -0,0 +1,29 @@ +

1137. N-th Tribonacci Number

Easy


The Tribonacci sequence Tn is defined as follows: 

+ +

T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.

+ +

Given n, return the value of Tn.

+ +

 

+

Example 1:

+ +
Input: n = 4
+Output: 4
+Explanation:
+T_3 = 0 + 1 + 1 = 2
+T_4 = 1 + 1 + 2 = 4
+
+ +

Example 2:

+ +
Input: n = 25
+Output: 1389537
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= n <= 37
  • +
  • The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.
  • +
\ No newline at end of file diff --git a/1140-stone-game-ii/1140-stone-game-ii.py b/problems/1140-stone-game-ii/1140-stone-game-ii.py similarity index 100% rename from 1140-stone-game-ii/1140-stone-game-ii.py rename to problems/1140-stone-game-ii/1140-stone-game-ii.py diff --git a/1140-stone-game-ii/NOTES.md b/problems/1140-stone-game-ii/NOTES.md similarity index 100% rename from 1140-stone-game-ii/NOTES.md rename to problems/1140-stone-game-ii/NOTES.md diff --git a/problems/1140-stone-game-ii/README.md b/problems/1140-stone-game-ii/README.md new file mode 100644 index 000000000..7add6be15 --- /dev/null +++ b/problems/1140-stone-game-ii/README.md @@ -0,0 +1,32 @@ +

1140. Stone Game II

Medium


Alice and Bob continue their games with piles of stones.  There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].  The objective of the game is to end with the most stones. 

+ +

Alice and Bob take turns, with Alice starting first.  Initially, M = 1.

+ +

On each player's turn, that player can take all the stones in the first X remaining piles, where 1 <= X <= 2M.  Then, we set M = max(M, X).

+ +

The game continues until all the stones have been taken.

+ +

Assuming Alice and Bob play optimally, return the maximum number of stones Alice can get.

+ +

 

+

Example 1:

+ +
Input: piles = [2,7,9,4,4]
+Output: 10
+Explanation:  If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 piles in total. If Alice takes two piles at the beginning, then Bob can take all three piles left. In this case, Alice get 2 + 7 = 9 piles in total. So we return 10 since it's larger. 
+
+ +

Example 2:

+ +
Input: piles = [1,2,3,4,5,100]
+Output: 104
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= piles.length <= 100
  • +
  • 1 <= piles[i] <= 104
  • +
+
\ No newline at end of file diff --git a/1143-longest-common-subsequence/1143-longest-common-subsequence.py b/problems/1143-longest-common-subsequence/1143-longest-common-subsequence.py similarity index 100% rename from 1143-longest-common-subsequence/1143-longest-common-subsequence.py rename to problems/1143-longest-common-subsequence/1143-longest-common-subsequence.py diff --git a/1143-longest-common-subsequence/NOTES.md b/problems/1143-longest-common-subsequence/NOTES.md similarity index 100% rename from 1143-longest-common-subsequence/NOTES.md rename to problems/1143-longest-common-subsequence/NOTES.md diff --git a/problems/1143-longest-common-subsequence/README.md b/problems/1143-longest-common-subsequence/README.md new file mode 100644 index 000000000..41371569a --- /dev/null +++ b/problems/1143-longest-common-subsequence/README.md @@ -0,0 +1,40 @@ +

1143. Longest Common Subsequence

Medium


Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

+ +

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

+ +
    +
  • For example, "ace" is a subsequence of "abcde".
  • +
+ +

A common subsequence of two strings is a subsequence that is common to both strings.

+ +

 

+

Example 1:

+ +
Input: text1 = "abcde", text2 = "ace" 
+Output: 3  
+Explanation: The longest common subsequence is "ace" and its length is 3.
+
+ +

Example 2:

+ +
Input: text1 = "abc", text2 = "abc"
+Output: 3
+Explanation: The longest common subsequence is "abc" and its length is 3.
+
+ +

Example 3:

+ +
Input: text1 = "abc", text2 = "def"
+Output: 0
+Explanation: There is no such common subsequence, so the result is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= text1.length, text2.length <= 1000
  • +
  • text1 and text2 consist of only lowercase English characters.
  • +
+
\ No newline at end of file diff --git a/1148-article-views-i/1148-article-views-i.sql b/problems/1148-article-views-i/1148-article-views-i.sql similarity index 100% rename from 1148-article-views-i/1148-article-views-i.sql rename to problems/1148-article-views-i/1148-article-views-i.sql diff --git a/1148-article-views-i/NOTES.md b/problems/1148-article-views-i/NOTES.md similarity index 100% rename from 1148-article-views-i/NOTES.md rename to problems/1148-article-views-i/NOTES.md diff --git a/problems/1148-article-views-i/README.md b/problems/1148-article-views-i/README.md new file mode 100644 index 000000000..fa2d7609b --- /dev/null +++ b/problems/1148-article-views-i/README.md @@ -0,0 +1,48 @@ +

1148. Article Views I

Easy


Table: Views

+ +
+---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| article_id    | int     |
+| author_id     | int     |
+| viewer_id     | int     |
+| view_date     | date    |
++---------------+---------+
+There is no primary key (column with unique values) for this table, the table may have duplicate rows.
+Each row of this table indicates that some viewer viewed an article (written by some author) on some date. 
+Note that equal author_id and viewer_id indicate the same person.
+
+ +

 

+ +

Write a solution to find all the authors that viewed at least one of their own articles.

+ +

Return the result table sorted by id in ascending order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
Input: 
+Views table:
++------------+-----------+-----------+------------+
+| article_id | author_id | viewer_id | view_date  |
++------------+-----------+-----------+------------+
+| 1          | 3         | 5         | 2019-08-01 |
+| 1          | 3         | 6         | 2019-08-02 |
+| 2          | 7         | 7         | 2019-08-01 |
+| 2          | 7         | 6         | 2019-08-02 |
+| 4          | 7         | 1         | 2019-07-22 |
+| 3          | 4         | 4         | 2019-07-21 |
+| 3          | 4         | 4         | 2019-07-21 |
++------------+-----------+-----------+------------+
+Output: 
++------+
+| id   |
++------+
+| 4    |
+| 7    |
++------+
+
+
\ No newline at end of file diff --git a/1155-number-of-dice-rolls-with-target-sum/1155-number-of-dice-rolls-with-target-sum.py b/problems/1155-number-of-dice-rolls-with-target-sum/1155-number-of-dice-rolls-with-target-sum.py similarity index 100% rename from 1155-number-of-dice-rolls-with-target-sum/1155-number-of-dice-rolls-with-target-sum.py rename to problems/1155-number-of-dice-rolls-with-target-sum/1155-number-of-dice-rolls-with-target-sum.py diff --git a/1155-number-of-dice-rolls-with-target-sum/NOTES.md b/problems/1155-number-of-dice-rolls-with-target-sum/NOTES.md similarity index 100% rename from 1155-number-of-dice-rolls-with-target-sum/NOTES.md rename to problems/1155-number-of-dice-rolls-with-target-sum/NOTES.md diff --git a/problems/1155-number-of-dice-rolls-with-target-sum/README.md b/problems/1155-number-of-dice-rolls-with-target-sum/README.md new file mode 100644 index 000000000..19dd039a7 --- /dev/null +++ b/problems/1155-number-of-dice-rolls-with-target-sum/README.md @@ -0,0 +1,36 @@ +

1155. Number of Dice Rolls With Target Sum

Medium


You have n dice, and each die has k faces numbered from 1 to k.

+ +

Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice, so the sum of the face-up numbers equals target. Since the answer may be too large, return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 1, k = 6, target = 3
+Output: 1
+Explanation: You throw one die with 6 faces.
+There is only one way to get a sum of 3.
+
+ +

Example 2:

+ +
Input: n = 2, k = 6, target = 7
+Output: 6
+Explanation: You throw two dice, each with 6 faces.
+There are 6 ways to get a sum of 7: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1.
+
+ +

Example 3:

+ +
Input: n = 30, k = 30, target = 500
+Output: 222616187
+Explanation: The answer must be returned modulo 109 + 7.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n, k <= 30
  • +
  • 1 <= target <= 1000
  • +
+
\ No newline at end of file diff --git a/1160-find-words-that-can-be-formed-by-characters/1160-find-words-that-can-be-formed-by-characters.py b/problems/1160-find-words-that-can-be-formed-by-characters/1160-find-words-that-can-be-formed-by-characters.py similarity index 100% rename from 1160-find-words-that-can-be-formed-by-characters/1160-find-words-that-can-be-formed-by-characters.py rename to problems/1160-find-words-that-can-be-formed-by-characters/1160-find-words-that-can-be-formed-by-characters.py diff --git a/1160-find-words-that-can-be-formed-by-characters/NOTES.md b/problems/1160-find-words-that-can-be-formed-by-characters/NOTES.md similarity index 100% rename from 1160-find-words-that-can-be-formed-by-characters/NOTES.md rename to problems/1160-find-words-that-can-be-formed-by-characters/NOTES.md diff --git a/problems/1160-find-words-that-can-be-formed-by-characters/README.md b/problems/1160-find-words-that-can-be-formed-by-characters/README.md new file mode 100644 index 000000000..7c301b188 --- /dev/null +++ b/problems/1160-find-words-that-can-be-formed-by-characters/README.md @@ -0,0 +1,30 @@ +

1160. Find Words That Can Be Formed by Characters

Easy


You are given an array of strings words and a string chars.

+ +

A string is good if it can be formed by characters from chars (each character can only be used once).

+ +

Return the sum of lengths of all good strings in words.

+ +

 

+

Example 1:

+ +
Input: words = ["cat","bt","hat","tree"], chars = "atach"
+Output: 6
+Explanation: The strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
+
+ +

Example 2:

+ +
Input: words = ["hello","world","leetcode"], chars = "welldonehoneyr"
+Output: 10
+Explanation: The strings that can be formed are "hello" and "world" so the answer is 5 + 5 = 10.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 1000
  • +
  • 1 <= words[i].length, chars.length <= 100
  • +
  • words[i] and chars consist of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1165-single-row-keyboard/1165-single-row-keyboard.py b/problems/1165-single-row-keyboard/1165-single-row-keyboard.py similarity index 100% rename from 1165-single-row-keyboard/1165-single-row-keyboard.py rename to problems/1165-single-row-keyboard/1165-single-row-keyboard.py diff --git a/1165-single-row-keyboard/NOTES.md b/problems/1165-single-row-keyboard/NOTES.md similarity index 100% rename from 1165-single-row-keyboard/NOTES.md rename to problems/1165-single-row-keyboard/NOTES.md diff --git a/problems/1165-single-row-keyboard/README.md b/problems/1165-single-row-keyboard/README.md new file mode 100644 index 000000000..4046c74ee --- /dev/null +++ b/problems/1165-single-row-keyboard/README.md @@ -0,0 +1,31 @@ +

1165. Single-Row Keyboard

Easy


There is a special keyboard with all keys in a single row.

+ +

Given a string keyboard of length 26 indicating the layout of the keyboard (indexed from 0 to 25). Initially, your finger is at index 0. To type a character, you have to move your finger to the index of the desired character. The time taken to move your finger from index i to index j is |i - j|.

+ +

You want to type a string word. Write a function to calculate how much time it takes to type it with one finger.

+ +

 

+

Example 1:

+ +
Input: keyboard = "abcdefghijklmnopqrstuvwxyz", word = "cba"
+Output: 4
+Explanation: The index moves from 0 to 2 to write 'c' then to 1 to write 'b' then to 0 again to write 'a'.
+Total time = 2 + 1 + 1 = 4. 
+
+ +

Example 2:

+ +
Input: keyboard = "pqrstuvwxyzabcdefghijklmno", word = "leetcode"
+Output: 73
+
+ +

 

+

Constraints:

+ +
    +
  • keyboard.length == 26
  • +
  • keyboard contains each English lowercase letter exactly once in some order.
  • +
  • 1 <= word.length <= 104
  • +
  • word[i] is an English lowercase letter.
  • +
+
\ No newline at end of file diff --git a/1167-minimum-cost-to-connect-sticks/1167-minimum-cost-to-connect-sticks.py b/problems/1167-minimum-cost-to-connect-sticks/1167-minimum-cost-to-connect-sticks.py similarity index 100% rename from 1167-minimum-cost-to-connect-sticks/1167-minimum-cost-to-connect-sticks.py rename to problems/1167-minimum-cost-to-connect-sticks/1167-minimum-cost-to-connect-sticks.py diff --git a/1167-minimum-cost-to-connect-sticks/NOTES.md b/problems/1167-minimum-cost-to-connect-sticks/NOTES.md similarity index 100% rename from 1167-minimum-cost-to-connect-sticks/NOTES.md rename to problems/1167-minimum-cost-to-connect-sticks/NOTES.md diff --git a/problems/1167-minimum-cost-to-connect-sticks/README.md b/problems/1167-minimum-cost-to-connect-sticks/README.md new file mode 100644 index 000000000..ac09be26a --- /dev/null +++ b/problems/1167-minimum-cost-to-connect-sticks/README.md @@ -0,0 +1,43 @@ +

1167. Minimum Cost to Connect Sticks

Medium


You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the ith stick.

+ +

You can connect any two sticks of lengths x and y into one stick by paying a cost of x + y. You must connect all the sticks until there is only one stick remaining.

+ +

Return the minimum cost of connecting all the given sticks into one stick in this way.

+ +

 

+

Example 1:

+ +
Input: sticks = [2,4,3]
+Output: 14
+Explanation: You start with sticks = [2,4,3].
+1. Combine sticks 2 and 3 for a cost of 2 + 3 = 5. Now you have sticks = [5,4].
+2. Combine sticks 5 and 4 for a cost of 5 + 4 = 9. Now you have sticks = [9].
+There is only one stick left, so you are done. The total cost is 5 + 9 = 14.
+
+ +

Example 2:

+ +
Input: sticks = [1,8,3,5]
+Output: 30
+Explanation: You start with sticks = [1,8,3,5].
+1. Combine sticks 1 and 3 for a cost of 1 + 3 = 4. Now you have sticks = [4,8,5].
+2. Combine sticks 4 and 5 for a cost of 4 + 5 = 9. Now you have sticks = [9,8].
+3. Combine sticks 9 and 8 for a cost of 9 + 8 = 17. Now you have sticks = [17].
+There is only one stick left, so you are done. The total cost is 4 + 9 + 17 = 30.
+
+ +

Example 3:

+ +
Input: sticks = [5]
+Output: 0
+Explanation: There is only one stick, so you don't need to do anything. The total cost is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= sticks.length <= 104
  • +
  • 1 <= sticks[i] <= 104
  • +
+
\ No newline at end of file diff --git a/1171-remove-zero-sum-consecutive-nodes-from-linked-list/1171-remove-zero-sum-consecutive-nodes-from-linked-list.py b/problems/1171-remove-zero-sum-consecutive-nodes-from-linked-list/1171-remove-zero-sum-consecutive-nodes-from-linked-list.py similarity index 100% rename from 1171-remove-zero-sum-consecutive-nodes-from-linked-list/1171-remove-zero-sum-consecutive-nodes-from-linked-list.py rename to problems/1171-remove-zero-sum-consecutive-nodes-from-linked-list/1171-remove-zero-sum-consecutive-nodes-from-linked-list.py diff --git a/1171-remove-zero-sum-consecutive-nodes-from-linked-list/NOTES.md b/problems/1171-remove-zero-sum-consecutive-nodes-from-linked-list/NOTES.md similarity index 100% rename from 1171-remove-zero-sum-consecutive-nodes-from-linked-list/NOTES.md rename to problems/1171-remove-zero-sum-consecutive-nodes-from-linked-list/NOTES.md diff --git a/problems/1171-remove-zero-sum-consecutive-nodes-from-linked-list/README.md b/problems/1171-remove-zero-sum-consecutive-nodes-from-linked-list/README.md new file mode 100644 index 000000000..a851823fd --- /dev/null +++ b/problems/1171-remove-zero-sum-consecutive-nodes-from-linked-list/README.md @@ -0,0 +1,34 @@ +

1171. Remove Zero Sum Consecutive Nodes from Linked List

Medium


Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences.

+ +

After doing so, return the head of the final linked list.  You may return any such answer.

+ +

 

+

(Note that in the examples below, all sequences are serializations of ListNode objects.)

+ +

Example 1:

+ +
Input: head = [1,2,-3,3,1]
+Output: [3,1]
+Note: The answer [1,2,1] would also be accepted.
+
+ +

Example 2:

+ +
Input: head = [1,2,3,-3,4]
+Output: [1,2,4]
+
+ +

Example 3:

+ +
Input: head = [1,2,3,-3,-2]
+Output: [1]
+
+ +

 

+

Constraints:

+ +
    +
  • The given linked list will contain between 1 and 1000 nodes.
  • +
  • Each node in the linked list has -1000 <= node.val <= 1000.
  • +
+
\ No newline at end of file diff --git a/1183-maximum-number-of-ones/1183-maximum-number-of-ones.py b/problems/1183-maximum-number-of-ones/1183-maximum-number-of-ones.py similarity index 100% rename from 1183-maximum-number-of-ones/1183-maximum-number-of-ones.py rename to problems/1183-maximum-number-of-ones/1183-maximum-number-of-ones.py diff --git a/1183-maximum-number-of-ones/NOTES.md b/problems/1183-maximum-number-of-ones/NOTES.md similarity index 100% rename from 1183-maximum-number-of-ones/NOTES.md rename to problems/1183-maximum-number-of-ones/NOTES.md diff --git a/problems/1183-maximum-number-of-ones/README.md b/problems/1183-maximum-number-of-ones/README.md new file mode 100644 index 000000000..fe52f1a05 --- /dev/null +++ b/problems/1183-maximum-number-of-ones/README.md @@ -0,0 +1,36 @@ +

1183. Maximum Number of Ones

Hard


Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones.

+ +

Return the maximum possible number of ones that the matrix M can have.

+ +

 

+

Example 1:

+ +
Input: width = 3, height = 3, sideLength = 2, maxOnes = 1
+Output: 4
+Explanation:
+In a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one.
+The best solution that has 4 ones is:
+[1,0,1]
+[0,0,0]
+[1,0,1]
+
+ +

Example 2:

+ +
Input: width = 3, height = 3, sideLength = 2, maxOnes = 2
+Output: 6
+Explanation:
+[1,0,1]
+[1,0,1]
+[1,0,1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= width, height <= 100
  • +
  • 1 <= sideLength <= width, height
  • +
  • 0 <= maxOnes <= sideLength * sideLength
  • +
+
\ No newline at end of file diff --git a/1190-reverse-substrings-between-each-pair-of-parentheses/1190-reverse-substrings-between-each-pair-of-parentheses.py b/problems/1190-reverse-substrings-between-each-pair-of-parentheses/1190-reverse-substrings-between-each-pair-of-parentheses.py similarity index 100% rename from 1190-reverse-substrings-between-each-pair-of-parentheses/1190-reverse-substrings-between-each-pair-of-parentheses.py rename to problems/1190-reverse-substrings-between-each-pair-of-parentheses/1190-reverse-substrings-between-each-pair-of-parentheses.py diff --git a/problems/1190-reverse-substrings-between-each-pair-of-parentheses/README.md b/problems/1190-reverse-substrings-between-each-pair-of-parentheses/README.md new file mode 100644 index 000000000..c422a3606 --- /dev/null +++ b/problems/1190-reverse-substrings-between-each-pair-of-parentheses/README.md @@ -0,0 +1,36 @@ +

1190. Reverse Substrings Between Each Pair of Parentheses

Medium


You are given a string s that consists of lower case English letters and brackets.

+ +

Reverse the strings in each pair of matching parentheses, starting from the innermost one.

+ +

Your result should not contain any brackets.

+ +

 

+

Example 1:

+ +
Input: s = "(abcd)"
+Output: "dcba"
+
+ +

Example 2:

+ +
Input: s = "(u(love)i)"
+Output: "iloveu"
+Explanation: The substring "love" is reversed first, then the whole string is reversed.
+
+ +

Example 3:

+ +
Input: s = "(ed(et(oc))el)"
+Output: "leetcode"
+Explanation: First, we reverse the substring "oc", then "etco", and finally, the whole string.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 2000
  • +
  • s only contains lower case English characters and parentheses.
  • +
  • It is guaranteed that all parentheses are balanced.
  • +
+
\ No newline at end of file diff --git a/1197-minimum-knight-moves/1197-minimum-knight-moves.py b/problems/1197-minimum-knight-moves/1197-minimum-knight-moves.py similarity index 100% rename from 1197-minimum-knight-moves/1197-minimum-knight-moves.py rename to problems/1197-minimum-knight-moves/1197-minimum-knight-moves.py diff --git a/1197-minimum-knight-moves/NOTES.md b/problems/1197-minimum-knight-moves/NOTES.md similarity index 100% rename from 1197-minimum-knight-moves/NOTES.md rename to problems/1197-minimum-knight-moves/NOTES.md diff --git a/problems/1197-minimum-knight-moves/README.md b/problems/1197-minimum-knight-moves/README.md new file mode 100644 index 000000000..f41372a77 --- /dev/null +++ b/problems/1197-minimum-knight-moves/README.md @@ -0,0 +1,29 @@ +

1197. Minimum Knight Moves

Medium


In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].

+ +

A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.

+ +

Return the minimum number of steps needed to move the knight to the square [x, y]. It is guaranteed the answer exists.

+ +

 

+

Example 1:

+ +
Input: x = 2, y = 1
+Output: 1
+Explanation: [0, 0] → [2, 1]
+
+ +

Example 2:

+ +
Input: x = 5, y = 5
+Output: 4
+Explanation: [0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]
+
+ +

 

+

Constraints:

+ +
    +
  • -300 <= x, y <= 300
  • +
  • 0 <= |x| + |y| <= 300
  • +
+
\ No newline at end of file diff --git a/1199-minimum-time-to-build-blocks/1199-minimum-time-to-build-blocks.py b/problems/1199-minimum-time-to-build-blocks/1199-minimum-time-to-build-blocks.py similarity index 100% rename from 1199-minimum-time-to-build-blocks/1199-minimum-time-to-build-blocks.py rename to problems/1199-minimum-time-to-build-blocks/1199-minimum-time-to-build-blocks.py diff --git a/1199-minimum-time-to-build-blocks/NOTES.md b/problems/1199-minimum-time-to-build-blocks/NOTES.md similarity index 100% rename from 1199-minimum-time-to-build-blocks/NOTES.md rename to problems/1199-minimum-time-to-build-blocks/NOTES.md diff --git a/problems/1199-minimum-time-to-build-blocks/README.md b/problems/1199-minimum-time-to-build-blocks/README.md new file mode 100644 index 000000000..5a7a3afc7 --- /dev/null +++ b/problems/1199-minimum-time-to-build-blocks/README.md @@ -0,0 +1,43 @@ +

1199. Minimum Time to Build Blocks

Hard


You are given a list of blocks, where blocks[i] = t means that the i-th block needs t units of time to be built. A block can only be built by exactly one worker.

+ +

A worker can either split into two workers (number of workers increases by one) or build a block then go home. Both decisions cost some time.

+ +

The time cost of spliting one worker into two workers is given as an integer split. Note that if two workers split at the same time, they split in parallel so the cost would be split.

+ +

Output the minimum time needed to build all blocks.

+ +

Initially, there is only one worker.

+ +

 

+

Example 1:

+ +
Input: blocks = [1], split = 1
+Output: 1
+Explanation: We use 1 worker to build 1 block in 1 time unit.
+
+ +

Example 2:

+ +
Input: blocks = [1,2], split = 5
+Output: 7
+Explanation: We split the worker into 2 workers in 5 time units then assign each of them to a block so the cost is 5 + max(1, 2) = 7.
+
+ +

Example 3:

+ +
Input: blocks = [1,2,3], split = 1
+Output: 4
+Explanation: Split 1 worker into 2, then assign the first worker to the last block and split the second worker into 2.
+Then, use the two unassigned workers to build the first two blocks.
+The cost is 1 + max(3, 1 + max(1, 2)) = 4.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= blocks.length <= 1000
  • +
  • 1 <= blocks[i] <= 10^5
  • +
  • 1 <= split <= 100
  • +
+
\ No newline at end of file diff --git a/1203-sort-items-by-groups-respecting-dependencies/1203-sort-items-by-groups-respecting-dependencies.py b/problems/1203-sort-items-by-groups-respecting-dependencies/1203-sort-items-by-groups-respecting-dependencies.py similarity index 100% rename from 1203-sort-items-by-groups-respecting-dependencies/1203-sort-items-by-groups-respecting-dependencies.py rename to problems/1203-sort-items-by-groups-respecting-dependencies/1203-sort-items-by-groups-respecting-dependencies.py diff --git a/1203-sort-items-by-groups-respecting-dependencies/NOTES.md b/problems/1203-sort-items-by-groups-respecting-dependencies/NOTES.md similarity index 100% rename from 1203-sort-items-by-groups-respecting-dependencies/NOTES.md rename to problems/1203-sort-items-by-groups-respecting-dependencies/NOTES.md diff --git a/problems/1203-sort-items-by-groups-respecting-dependencies/README.md b/problems/1203-sort-items-by-groups-respecting-dependencies/README.md new file mode 100644 index 000000000..3bf64a00c --- /dev/null +++ b/problems/1203-sort-items-by-groups-respecting-dependencies/README.md @@ -0,0 +1,40 @@ +

1203. Sort Items by Groups Respecting Dependencies

Hard


There are n items each belonging to zero or one of m groups where group[i] is the group that the i-th item belongs to and it's equal to -1 if the i-th item belongs to no group. The items and the groups are zero indexed. A group can have no item belonging to it.

+ +

Return a sorted list of the items such that:

+ +
    +
  • The items that belong to the same group are next to each other in the sorted list.
  • +
  • There are some relations between these items where beforeItems[i] is a list containing all the items that should come before the i-th item in the sorted array (to the left of the i-th item).
  • +
+ +

Return any solution if there is more than one solution and return an empty list if there is no solution.

+ +

 

+

Example 1:

+ +

+ +
Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3,6],[],[],[]]
+Output: [6,3,4,1,5,2,0,7]
+
+ +

Example 2:

+ +
Input: n = 8, m = 2, group = [-1,-1,1,0,0,1,0,-1], beforeItems = [[],[6],[5],[6],[3],[],[4],[]]
+Output: []
+Explanation: This is the same as example 1 except that 4 needs to be before 6 in the sorted list.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= m <= n <= 3 * 104
  • +
  • group.length == beforeItems.length == n
  • +
  • -1 <= group[i] <= m - 1
  • +
  • 0 <= beforeItems[i].length <= n - 1
  • +
  • 0 <= beforeItems[i][j] <= n - 1
  • +
  • i != beforeItems[i][j]
  • +
  • beforeItems[i] does not contain duplicates elements.
  • +
+
\ No newline at end of file diff --git a/1207-unique-number-of-occurrences/1207-unique-number-of-occurrences.py b/problems/1207-unique-number-of-occurrences/1207-unique-number-of-occurrences.py similarity index 100% rename from 1207-unique-number-of-occurrences/1207-unique-number-of-occurrences.py rename to problems/1207-unique-number-of-occurrences/1207-unique-number-of-occurrences.py diff --git a/1207-unique-number-of-occurrences/NOTES.md b/problems/1207-unique-number-of-occurrences/NOTES.md similarity index 100% rename from 1207-unique-number-of-occurrences/NOTES.md rename to problems/1207-unique-number-of-occurrences/NOTES.md diff --git a/problems/1207-unique-number-of-occurrences/README.md b/problems/1207-unique-number-of-occurrences/README.md new file mode 100644 index 000000000..2970e6191 --- /dev/null +++ b/problems/1207-unique-number-of-occurrences/README.md @@ -0,0 +1,29 @@ +

1207. Unique Number of Occurrences

Easy


Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.

+ +

 

+

Example 1:

+ +
Input: arr = [1,2,2,1,1,3]
+Output: true
+Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
+ +

Example 2:

+ +
Input: arr = [1,2]
+Output: false
+
+ +

Example 3:

+ +
Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
+Output: true
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 1000
  • +
  • -1000 <= arr[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/1208-get-equal-substrings-within-budget/1208-get-equal-substrings-within-budget.py b/problems/1208-get-equal-substrings-within-budget/1208-get-equal-substrings-within-budget.py similarity index 100% rename from 1208-get-equal-substrings-within-budget/1208-get-equal-substrings-within-budget.py rename to problems/1208-get-equal-substrings-within-budget/1208-get-equal-substrings-within-budget.py diff --git a/1208-get-equal-substrings-within-budget/NOTES.md b/problems/1208-get-equal-substrings-within-budget/NOTES.md similarity index 100% rename from 1208-get-equal-substrings-within-budget/NOTES.md rename to problems/1208-get-equal-substrings-within-budget/NOTES.md diff --git a/problems/1208-get-equal-substrings-within-budget/README.md b/problems/1208-get-equal-substrings-within-budget/README.md new file mode 100644 index 000000000..45da02325 --- /dev/null +++ b/problems/1208-get-equal-substrings-within-budget/README.md @@ -0,0 +1,39 @@ +

1208. Get Equal Substrings Within Budget

Medium


You are given two strings s and t of the same length and an integer maxCost.

+ +

You want to change s to t. Changing the ith character of s to ith character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters).

+ +

Return the maximum length of a substring of s that can be changed to be the same as the corresponding substring of t with a cost less than or equal to maxCost. If there is no substring from s that can be changed to its corresponding substring from t, return 0.

+ +

 

+

Example 1:

+ +
Input: s = "abcd", t = "bcdf", maxCost = 3
+Output: 3
+Explanation: "abc" of s can change to "bcd".
+That costs 3, so the maximum length is 3.
+
+ +

Example 2:

+ +
Input: s = "abcd", t = "cdef", maxCost = 3
+Output: 1
+Explanation: Each character in s costs 2 to change to character in t,  so the maximum length is 1.
+
+ +

Example 3:

+ +
Input: s = "abcd", t = "acde", maxCost = 0
+Output: 1
+Explanation: You cannot make any change, so the maximum length is 1.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • t.length == s.length
  • +
  • 0 <= maxCost <= 106
  • +
  • s and t consist of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1216-valid-palindrome-iii/1216-valid-palindrome-iii.py b/problems/1216-valid-palindrome-iii/1216-valid-palindrome-iii.py similarity index 100% rename from 1216-valid-palindrome-iii/1216-valid-palindrome-iii.py rename to problems/1216-valid-palindrome-iii/1216-valid-palindrome-iii.py diff --git a/1216-valid-palindrome-iii/NOTES.md b/problems/1216-valid-palindrome-iii/NOTES.md similarity index 100% rename from 1216-valid-palindrome-iii/NOTES.md rename to problems/1216-valid-palindrome-iii/NOTES.md diff --git a/problems/1216-valid-palindrome-iii/README.md b/problems/1216-valid-palindrome-iii/README.md new file mode 100644 index 000000000..663796af1 --- /dev/null +++ b/problems/1216-valid-palindrome-iii/README.md @@ -0,0 +1,27 @@ +

1216. Valid Palindrome III

Hard


Given a string s and an integer k, return true if s is a k-palindrome.

+ +

A string is k-palindrome if it can be transformed into a palindrome by removing at most k characters from it.

+ +

 

+

Example 1:

+ +
Input: s = "abcdeca", k = 2
+Output: true
+Explanation: Remove 'b' and 'e' characters.
+
+ +

Example 2:

+ +
Input: s = "abbababa", k = 1
+Output: true
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 1000
  • +
  • s consists of only lowercase English letters.
  • +
  • 1 <= k <= s.length
  • +
+
\ No newline at end of file diff --git a/1219-path-with-maximum-gold/1219-path-with-maximum-gold.py b/problems/1219-path-with-maximum-gold/1219-path-with-maximum-gold.py similarity index 100% rename from 1219-path-with-maximum-gold/1219-path-with-maximum-gold.py rename to problems/1219-path-with-maximum-gold/1219-path-with-maximum-gold.py diff --git a/problems/1219-path-with-maximum-gold/README.md b/problems/1219-path-with-maximum-gold/README.md new file mode 100644 index 000000000..399cf0bda --- /dev/null +++ b/problems/1219-path-with-maximum-gold/README.md @@ -0,0 +1,48 @@ +

1219. Path with Maximum Gold

Medium


In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.

+ +

Return the maximum amount of gold you can collect under the conditions:

+ +
    +
  • Every time you are located in a cell you will collect all the gold in that cell.
  • +
  • From your position, you can walk one step to the left, right, up, or down.
  • +
  • You can't visit the same cell more than once.
  • +
  • Never visit a cell with 0 gold.
  • +
  • You can start and stop collecting gold from any position in the grid that has some gold.
  • +
+ +

 

+

Example 1:

+ +
Input: grid = [[0,6,0],[5,8,7],[0,9,0]]
+Output: 24
+Explanation:
+[[0,6,0],
+ [5,8,7],
+ [0,9,0]]
+Path to get the maximum gold, 9 -> 8 -> 7.
+
+ +

Example 2:

+ +
Input: grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]
+Output: 28
+Explanation:
+[[1,0,7],
+ [2,0,6],
+ [3,4,5],
+ [0,3,0],
+ [9,0,20]]
+Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 15
  • +
  • 0 <= grid[i][j] <= 100
  • +
  • There are at most 25 cells containing gold.
  • +
+
\ No newline at end of file diff --git a/1220-count-vowels-permutation/1220-count-vowels-permutation.py b/problems/1220-count-vowels-permutation/1220-count-vowels-permutation.py similarity index 100% rename from 1220-count-vowels-permutation/1220-count-vowels-permutation.py rename to problems/1220-count-vowels-permutation/1220-count-vowels-permutation.py diff --git a/1220-count-vowels-permutation/NOTES.md b/problems/1220-count-vowels-permutation/NOTES.md similarity index 100% rename from 1220-count-vowels-permutation/NOTES.md rename to problems/1220-count-vowels-permutation/NOTES.md diff --git a/problems/1220-count-vowels-permutation/README.md b/problems/1220-count-vowels-permutation/README.md new file mode 100644 index 000000000..0eaafd104 --- /dev/null +++ b/problems/1220-count-vowels-permutation/README.md @@ -0,0 +1,40 @@ +

1220. Count Vowels Permutation

Hard


Given an integer n, your task is to count how many strings of length n can be formed under the following rules:

+ +
    +
  • Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')
  • +
  • Each vowel 'a' may only be followed by an 'e'.
  • +
  • Each vowel 'e' may only be followed by an 'a' or an 'i'.
  • +
  • Each vowel 'i' may not be followed by another 'i'.
  • +
  • Each vowel 'o' may only be followed by an 'i' or a 'u'.
  • +
  • Each vowel 'u' may only be followed by an 'a'.
  • +
+ +

Since the answer may be too large, return it modulo 10^9 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 1
+Output: 5
+Explanation: All possible strings are: "a", "e", "i" , "o" and "u".
+
+ +

Example 2:

+ +
Input: n = 2
+Output: 10
+Explanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".
+
+ +

Example 3: 

+ +
Input: n = 5
+Output: 68
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 2 * 10^4
  • +
+
\ No newline at end of file diff --git a/1230-toss-strange-coins/1230-toss-strange-coins.py b/problems/1230-toss-strange-coins/1230-toss-strange-coins.py similarity index 100% rename from 1230-toss-strange-coins/1230-toss-strange-coins.py rename to problems/1230-toss-strange-coins/1230-toss-strange-coins.py diff --git a/problems/1230-toss-strange-coins/README.md b/problems/1230-toss-strange-coins/README.md new file mode 100644 index 000000000..69921f393 --- /dev/null +++ b/problems/1230-toss-strange-coins/README.md @@ -0,0 +1,22 @@ +

1230. Toss Strange Coins

Medium


You have some coins.  The i-th coin has a probability prob[i] of facing heads when tossed.

+ +

Return the probability that the number of coins facing heads equals target if you toss every coin exactly once.

+ +

 

+

Example 1:

+
Input: prob = [0.4], target = 1
+Output: 0.40000
+

Example 2:

+
Input: prob = [0.5,0.5,0.5,0.5,0.5], target = 0
+Output: 0.03125
+
+

 

+

Constraints:

+ +
    +
  • 1 <= prob.length <= 1000
  • +
  • 0 <= prob[i] <= 1
  • +
  • 0 <= target <= prob.length
  • +
  • Answers will be accepted as correct if they are within 10^-5 of the correct answer.
  • +
+
\ No newline at end of file diff --git a/1235-maximum-profit-in-job-scheduling/1235-maximum-profit-in-job-scheduling.py b/problems/1235-maximum-profit-in-job-scheduling/1235-maximum-profit-in-job-scheduling.py similarity index 100% rename from 1235-maximum-profit-in-job-scheduling/1235-maximum-profit-in-job-scheduling.py rename to problems/1235-maximum-profit-in-job-scheduling/1235-maximum-profit-in-job-scheduling.py diff --git a/1235-maximum-profit-in-job-scheduling/NOTES.md b/problems/1235-maximum-profit-in-job-scheduling/NOTES.md similarity index 100% rename from 1235-maximum-profit-in-job-scheduling/NOTES.md rename to problems/1235-maximum-profit-in-job-scheduling/NOTES.md diff --git a/problems/1235-maximum-profit-in-job-scheduling/README.md b/problems/1235-maximum-profit-in-job-scheduling/README.md new file mode 100644 index 000000000..8660019ec --- /dev/null +++ b/problems/1235-maximum-profit-in-job-scheduling/README.md @@ -0,0 +1,44 @@ +

1235. Maximum Profit in Job Scheduling

Hard


We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].

+ +

You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range.

+ +

If you choose a job that ends at time X you will be able to start another job that starts at time X.

+ +

 

+

Example 1:

+ +

+ +
Input: startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]
+Output: 120
+Explanation: The subset chosen is the first and fourth job. 
+Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70.
+
+ +

Example 2:

+ +

+ +
Input: startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]
+Output: 150
+Explanation: The subset chosen is the first, fourth and fifth job. 
+Profit obtained 150 = 20 + 70 + 60.
+
+ +

Example 3:

+ +

+ +
Input: startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]
+Output: 6
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= startTime.length == endTime.length == profit.length <= 5 * 104
  • +
  • 1 <= startTime[i] < endTime[i] <= 109
  • +
  • 1 <= profit[i] <= 104
  • +
+
\ No newline at end of file diff --git a/1239-maximum-length-of-a-concatenated-string-with-unique-characters/1239-maximum-length-of-a-concatenated-string-with-unique-characters.py b/problems/1239-maximum-length-of-a-concatenated-string-with-unique-characters/1239-maximum-length-of-a-concatenated-string-with-unique-characters.py similarity index 100% rename from 1239-maximum-length-of-a-concatenated-string-with-unique-characters/1239-maximum-length-of-a-concatenated-string-with-unique-characters.py rename to problems/1239-maximum-length-of-a-concatenated-string-with-unique-characters/1239-maximum-length-of-a-concatenated-string-with-unique-characters.py diff --git a/1239-maximum-length-of-a-concatenated-string-with-unique-characters/NOTES.md b/problems/1239-maximum-length-of-a-concatenated-string-with-unique-characters/NOTES.md similarity index 100% rename from 1239-maximum-length-of-a-concatenated-string-with-unique-characters/NOTES.md rename to problems/1239-maximum-length-of-a-concatenated-string-with-unique-characters/NOTES.md diff --git a/problems/1239-maximum-length-of-a-concatenated-string-with-unique-characters/README.md b/problems/1239-maximum-length-of-a-concatenated-string-with-unique-characters/README.md new file mode 100644 index 000000000..32b1a0804 --- /dev/null +++ b/problems/1239-maximum-length-of-a-concatenated-string-with-unique-characters/README.md @@ -0,0 +1,44 @@ +

1239. Maximum Length of a Concatenated String with Unique Characters

Medium


You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters.

+ +

Return the maximum possible length of s.

+ +

A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

+ +

 

+

Example 1:

+ +
Input: arr = ["un","iq","ue"]
+Output: 4
+Explanation: All the valid concatenations are:
+- ""
+- "un"
+- "iq"
+- "ue"
+- "uniq" ("un" + "iq")
+- "ique" ("iq" + "ue")
+Maximum length is 4.
+
+ +

Example 2:

+ +
Input: arr = ["cha","r","act","ers"]
+Output: 6
+Explanation: Possible longest valid concatenations are "chaers" ("cha" + "ers") and "acters" ("act" + "ers").
+
+ +

Example 3:

+ +
Input: arr = ["abcdefghijklmnopqrstuvwxyz"]
+Output: 26
+Explanation: The only string in arr has all 26 characters.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 16
  • +
  • 1 <= arr[i].length <= 26
  • +
  • arr[i] contains only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1245-tree-diameter/1245-tree-diameter.py b/problems/1245-tree-diameter/1245-tree-diameter.py similarity index 100% rename from 1245-tree-diameter/1245-tree-diameter.py rename to problems/1245-tree-diameter/1245-tree-diameter.py diff --git a/1245-tree-diameter/NOTES.md b/problems/1245-tree-diameter/NOTES.md similarity index 100% rename from 1245-tree-diameter/NOTES.md rename to problems/1245-tree-diameter/NOTES.md diff --git a/problems/1245-tree-diameter/README.md b/problems/1245-tree-diameter/README.md new file mode 100644 index 000000000..0c13e1747 --- /dev/null +++ b/problems/1245-tree-diameter/README.md @@ -0,0 +1,31 @@ +

1245. Tree Diameter

Medium


The diameter of a tree is the number of edges in the longest path in that tree.

+ +

There is an undirected tree of n nodes labeled from 0 to n - 1. You are given a 2D array edges where edges.length == n - 1 and edges[i] = [ai, bi] indicates that there is an undirected edge between nodes ai and bi in the tree.

+ +

Return the diameter of the tree.

+ +

 

+

Example 1:

+ +
Input: edges = [[0,1],[0,2]]
+Output: 2
+Explanation: The longest path of the tree is the path 1 - 0 - 2.
+
+ +

Example 2:

+ +
Input: edges = [[0,1],[1,2],[2,3],[1,4],[4,5]]
+Output: 4
+Explanation: The longest path of the tree is the path 3 - 2 - 1 - 4 - 5.
+
+ +

 

+

Constraints:

+ +
    +
  • n == edges.length + 1
  • +
  • 1 <= n <= 104
  • +
  • 0 <= ai, bi < n
  • +
  • ai != bi
  • +
+
\ No newline at end of file diff --git a/1248-count-number-of-nice-subarrays/1248-count-number-of-nice-subarrays.py b/problems/1248-count-number-of-nice-subarrays/1248-count-number-of-nice-subarrays.py similarity index 100% rename from 1248-count-number-of-nice-subarrays/1248-count-number-of-nice-subarrays.py rename to problems/1248-count-number-of-nice-subarrays/1248-count-number-of-nice-subarrays.py diff --git a/1248-count-number-of-nice-subarrays/NOTES.md b/problems/1248-count-number-of-nice-subarrays/NOTES.md similarity index 100% rename from 1248-count-number-of-nice-subarrays/NOTES.md rename to problems/1248-count-number-of-nice-subarrays/NOTES.md diff --git a/problems/1248-count-number-of-nice-subarrays/README.md b/problems/1248-count-number-of-nice-subarrays/README.md new file mode 100644 index 000000000..e5144d0dd --- /dev/null +++ b/problems/1248-count-number-of-nice-subarrays/README.md @@ -0,0 +1,34 @@ +

1248. Count Number of Nice Subarrays

Medium


Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.

+ +

Return the number of nice sub-arrays.

+ +

 

+

Example 1:

+ +
Input: nums = [1,1,2,1,1], k = 3
+Output: 2
+Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
+
+ +

Example 2:

+ +
Input: nums = [2,4,6], k = 1
+Output: 0
+Explanation: There are no odd numbers in the array.
+
+ +

Example 3:

+ +
Input: nums = [2,2,2,1,2,2,1,2,2,2], k = 2
+Output: 16
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 50000
  • +
  • 1 <= nums[i] <= 10^5
  • +
  • 1 <= k <= nums.length
  • +
+
\ No newline at end of file diff --git a/1249-minimum-remove-to-make-valid-parentheses/1249-minimum-remove-to-make-valid-parentheses.py b/problems/1249-minimum-remove-to-make-valid-parentheses/1249-minimum-remove-to-make-valid-parentheses.py similarity index 100% rename from 1249-minimum-remove-to-make-valid-parentheses/1249-minimum-remove-to-make-valid-parentheses.py rename to problems/1249-minimum-remove-to-make-valid-parentheses/1249-minimum-remove-to-make-valid-parentheses.py diff --git a/1249-minimum-remove-to-make-valid-parentheses/NOTES.md b/problems/1249-minimum-remove-to-make-valid-parentheses/NOTES.md similarity index 100% rename from 1249-minimum-remove-to-make-valid-parentheses/NOTES.md rename to problems/1249-minimum-remove-to-make-valid-parentheses/NOTES.md diff --git a/problems/1249-minimum-remove-to-make-valid-parentheses/README.md b/problems/1249-minimum-remove-to-make-valid-parentheses/README.md new file mode 100644 index 000000000..d5ec3542c --- /dev/null +++ b/problems/1249-minimum-remove-to-make-valid-parentheses/README.md @@ -0,0 +1,41 @@ +

1249. Minimum Remove to Make Valid Parentheses

Medium


Given a string s of '(' , ')' and lowercase English characters.

+ +

Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.

+ +

Formally, a parentheses string is valid if and only if:

+ +
    +
  • It is the empty string, contains only lowercase characters, or
  • +
  • It can be written as AB (A concatenated with B), where A and B are valid strings, or
  • +
  • It can be written as (A), where A is a valid string.
  • +
+ +

 

+

Example 1:

+ +
Input: s = "lee(t(c)o)de)"
+Output: "lee(t(c)o)de"
+Explanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.
+
+ +

Example 2:

+ +
Input: s = "a)b(c)d"
+Output: "ab(c)d"
+
+ +

Example 3:

+ +
Input: s = "))(("
+Output: ""
+Explanation: An empty string is also valid.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s[i] is either'(' , ')', or lowercase English letter.
  • +
+
\ No newline at end of file diff --git a/1255-maximum-score-words-formed-by-letters/1255-maximum-score-words-formed-by-letters.py b/problems/1255-maximum-score-words-formed-by-letters/1255-maximum-score-words-formed-by-letters.py similarity index 100% rename from 1255-maximum-score-words-formed-by-letters/1255-maximum-score-words-formed-by-letters.py rename to problems/1255-maximum-score-words-formed-by-letters/1255-maximum-score-words-formed-by-letters.py diff --git a/1255-maximum-score-words-formed-by-letters/NOTES.md b/problems/1255-maximum-score-words-formed-by-letters/NOTES.md similarity index 100% rename from 1255-maximum-score-words-formed-by-letters/NOTES.md rename to problems/1255-maximum-score-words-formed-by-letters/NOTES.md diff --git a/problems/1255-maximum-score-words-formed-by-letters/README.md b/problems/1255-maximum-score-words-formed-by-letters/README.md new file mode 100644 index 000000000..6f764711f --- /dev/null +++ b/problems/1255-maximum-score-words-formed-by-letters/README.md @@ -0,0 +1,45 @@ +

1255. Maximum Score Words Formed by Letters

Hard


Given a list of words, list of  single letters (might be repeating) and score of every character.

+ +

Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).

+ +

It is not necessary to use all characters in letters and each letter can only be used once. Score of letters 'a', 'b', 'c', ... ,'z' is given by score[0], score[1], ... , score[25] respectively.

+ +

 

+

Example 1:

+ +
Input: words = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]
+Output: 23
+Explanation:
+Score  a=1, c=9, d=5, g=3, o=2
+Given letters, we can form the words "dad" (5+1+5) and "good" (3+2+2+5) with a score of 23.
+Words "dad" and "dog" only get a score of 21.
+ +

Example 2:

+ +
Input: words = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]
+Output: 27
+Explanation:
+Score  a=4, b=4, c=4, x=5, z=10
+Given letters, we can form the words "ax" (4+5), "bx" (4+5) and "cx" (4+5) with a score of 27.
+Word "xxxz" only get a score of 25.
+ +

Example 3:

+ +
Input: words = ["leetcode"], letters = ["l","e","t","c","o","d"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0]
+Output: 0
+Explanation:
+Letter "e" can only be used once.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 14
  • +
  • 1 <= words[i].length <= 15
  • +
  • 1 <= letters.length <= 100
  • +
  • letters[i].length == 1
  • +
  • score.length == 26
  • +
  • 0 <= score[i] <= 10
  • +
  • words[i], letters[i] contains only lower case English letters.
  • +
+
\ No newline at end of file diff --git a/1265-print-immutable-linked-list-in-reverse/1265-print-immutable-linked-list-in-reverse.cpp b/problems/1265-print-immutable-linked-list-in-reverse/1265-print-immutable-linked-list-in-reverse.cpp similarity index 100% rename from 1265-print-immutable-linked-list-in-reverse/1265-print-immutable-linked-list-in-reverse.cpp rename to problems/1265-print-immutable-linked-list-in-reverse/1265-print-immutable-linked-list-in-reverse.cpp diff --git a/1265-print-immutable-linked-list-in-reverse/NOTES.md b/problems/1265-print-immutable-linked-list-in-reverse/NOTES.md similarity index 100% rename from 1265-print-immutable-linked-list-in-reverse/NOTES.md rename to problems/1265-print-immutable-linked-list-in-reverse/NOTES.md diff --git a/problems/1265-print-immutable-linked-list-in-reverse/README.md b/problems/1265-print-immutable-linked-list-in-reverse/README.md new file mode 100644 index 000000000..1a7fc2224 --- /dev/null +++ b/problems/1265-print-immutable-linked-list-in-reverse/README.md @@ -0,0 +1,56 @@ +

1265. Print Immutable Linked List in Reverse

Medium


You are given an immutable linked list, print out all values of each node in reverse with the help of the following interface:

+ +
    +
  • ImmutableListNode: An interface of immutable linked list, you are given the head of the list.
  • +
+ +

You need to use the following functions to access the linked list (you can't access the ImmutableListNode directly):

+ +
    +
  • ImmutableListNode.printValue(): Print value of the current node.
  • +
  • ImmutableListNode.getNext(): Return the next node.
  • +
+ +

The input is only given to initialize the linked list internally. You must solve this problem without modifying the linked list. In other words, you must operate the linked list using only the mentioned APIs.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,4]
+Output: [4,3,2,1]
+
+ +

Example 2:

+ +
Input: head = [0,-4,-1,3,-5]
+Output: [-5,3,-1,-4,0]
+
+ +

Example 3:

+ +
Input: head = [-2,0,6,4,4,-6]
+Output: [-6,4,4,6,0,-2]
+
+ +
    +
+ +

 

+

Constraints:

+ +
    +
  • The length of the linked list is between [1, 1000].
  • +
  • The value of each node in the linked list is between [-1000, 1000].
  • +
+ +

 

+ +

Follow up:

+ +

Could you solve this problem in:

+ +
    +
  • Constant space complexity?
  • +
  • Linear time complexity and less than linear space complexity?
  • +
+
\ No newline at end of file diff --git a/1266-minimum-time-visiting-all-points/1266-minimum-time-visiting-all-points.py b/problems/1266-minimum-time-visiting-all-points/1266-minimum-time-visiting-all-points.py similarity index 100% rename from 1266-minimum-time-visiting-all-points/1266-minimum-time-visiting-all-points.py rename to problems/1266-minimum-time-visiting-all-points/1266-minimum-time-visiting-all-points.py diff --git a/1266-minimum-time-visiting-all-points/NOTES.md b/problems/1266-minimum-time-visiting-all-points/NOTES.md similarity index 100% rename from 1266-minimum-time-visiting-all-points/NOTES.md rename to problems/1266-minimum-time-visiting-all-points/NOTES.md diff --git a/problems/1266-minimum-time-visiting-all-points/README.md b/problems/1266-minimum-time-visiting-all-points/README.md new file mode 100644 index 000000000..dea582493 --- /dev/null +++ b/problems/1266-minimum-time-visiting-all-points/README.md @@ -0,0 +1,43 @@ +

1266. Minimum Time Visiting All Points

Easy


On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.

+ +

You can move according to these rules:

+ +
    +
  • In 1 second, you can either: + +
      +
    • move vertically by one unit,
    • +
    • move horizontally by one unit, or
    • +
    • move diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second).
    • +
    +
  • +
  • You have to visit the points in the same order as they appear in the array.
  • +
  • You are allowed to pass through points that appear later in the order, but these do not count as visits.
  • +
+ +

 

+

Example 1:

+ +
Input: points = [[1,1],[3,4],[-1,0]]
+Output: 7
+Explanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]   
+Time from [1,1] to [3,4] = 3 seconds 
+Time from [3,4] to [-1,0] = 4 seconds
+Total time = 7 seconds
+ +

Example 2:

+ +
Input: points = [[3,2],[-2,2]]
+Output: 5
+
+ +

 

+

Constraints:

+ +
    +
  • points.length == n
  • +
  • 1 <= n <= 100
  • +
  • points[i].length == 2
  • +
  • -1000 <= points[i][0], points[i][1] <= 1000
  • +
+
\ No newline at end of file diff --git a/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.py b/problems/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.py similarity index 100% rename from 1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.py rename to problems/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.py diff --git a/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/NOTES.md b/problems/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/NOTES.md similarity index 100% rename from 1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/NOTES.md rename to problems/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/NOTES.md diff --git a/problems/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/README.md b/problems/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/README.md new file mode 100644 index 000000000..c22cfa162 --- /dev/null +++ b/problems/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps/README.md @@ -0,0 +1,39 @@ +

1269. Number of Ways to Stay in the Same Place After Some Steps

Hard


You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).

+ +

Given two integers steps and arrLen, return the number of ways such that your pointer is still at index 0 after exactly steps steps. Since the answer may be too large, return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: steps = 3, arrLen = 2
+Output: 4
+Explanation: There are 4 differents ways to stay at index 0 after 3 steps.
+Right, Left, Stay
+Stay, Right, Left
+Right, Stay, Left
+Stay, Stay, Stay
+
+ +

Example 2:

+ +
Input: steps = 2, arrLen = 4
+Output: 2
+Explanation: There are 2 differents ways to stay at index 0 after 2 steps
+Right, Left
+Stay, Stay
+
+ +

Example 3:

+ +
Input: steps = 4, arrLen = 2
+Output: 8
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= steps <= 500
  • +
  • 1 <= arrLen <= 106
  • +
+
\ No newline at end of file diff --git a/1272-remove-interval/1272-remove-interval.py b/problems/1272-remove-interval/1272-remove-interval.py similarity index 100% rename from 1272-remove-interval/1272-remove-interval.py rename to problems/1272-remove-interval/1272-remove-interval.py diff --git a/1272-remove-interval/NOTES.md b/problems/1272-remove-interval/NOTES.md similarity index 100% rename from 1272-remove-interval/NOTES.md rename to problems/1272-remove-interval/NOTES.md diff --git a/problems/1272-remove-interval/README.md b/problems/1272-remove-interval/README.md new file mode 100644 index 000000000..5bed67581 --- /dev/null +++ b/problems/1272-remove-interval/README.md @@ -0,0 +1,33 @@ +

1272. Remove Interval

Medium


A set of real numbers can be represented as the union of several disjoint intervals, where each interval is in the form [a, b). A real number x is in the set if one of its intervals [a, b) contains x (i.e. a <= x < b).

+ +

You are given a sorted list of disjoint intervals intervals representing a set of real numbers as described above, where intervals[i] = [ai, bi] represents the interval [ai, bi). You are also given another interval toBeRemoved.

+ +

Return the set of real numbers with the interval toBeRemoved removed from intervals. In other words, return the set of real numbers such that every x in the set is in intervals but not in toBeRemoved. Your answer should be a sorted list of disjoint intervals as described above.

+ +

 

+

Example 1:

+ +
Input: intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]
+Output: [[0,1],[6,7]]
+
+ +

Example 2:

+ +
Input: intervals = [[0,5]], toBeRemoved = [2,3]
+Output: [[0,2],[3,5]]
+
+ +

Example 3:

+ +
Input: intervals = [[-5,-4],[-3,-2],[1,2],[3,5],[8,9]], toBeRemoved = [-1,4]
+Output: [[-5,-4],[-3,-2],[4,5],[8,9]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= intervals.length <= 104
  • +
  • -109 <= ai < bi <= 109
  • +
+
\ No newline at end of file diff --git a/1282-group-the-people-given-the-group-size-they-belong-to/1282-group-the-people-given-the-group-size-they-belong-to.py b/problems/1282-group-the-people-given-the-group-size-they-belong-to/1282-group-the-people-given-the-group-size-they-belong-to.py similarity index 100% rename from 1282-group-the-people-given-the-group-size-they-belong-to/1282-group-the-people-given-the-group-size-they-belong-to.py rename to problems/1282-group-the-people-given-the-group-size-they-belong-to/1282-group-the-people-given-the-group-size-they-belong-to.py diff --git a/1282-group-the-people-given-the-group-size-they-belong-to/NOTES.md b/problems/1282-group-the-people-given-the-group-size-they-belong-to/NOTES.md similarity index 100% rename from 1282-group-the-people-given-the-group-size-they-belong-to/NOTES.md rename to problems/1282-group-the-people-given-the-group-size-they-belong-to/NOTES.md diff --git a/problems/1282-group-the-people-given-the-group-size-they-belong-to/README.md b/problems/1282-group-the-people-given-the-group-size-they-belong-to/README.md new file mode 100644 index 000000000..5db21c7e5 --- /dev/null +++ b/problems/1282-group-the-people-given-the-group-size-they-belong-to/README.md @@ -0,0 +1,35 @@ +

1282. Group the People Given the Group Size They Belong To

Medium


There are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1.

+ +

You are given an integer array groupSizes, where groupSizes[i] is the size of the group that person i is in. For example, if groupSizes[1] = 3, then person 1 must be in a group of size 3.

+ +

Return a list of groups such that each person i is in a group of size groupSizes[i].

+ +

Each person should appear in exactly one group, and every person must be in a group. If there are multiple answers, return any of them. It is guaranteed that there will be at least one valid solution for the given input.

+ +

 

+

Example 1:

+ +
Input: groupSizes = [3,3,3,3,3,1,3]
+Output: [[5],[0,1,2],[3,4,6]]
+Explanation: 
+The first group is [5]. The size is 1, and groupSizes[5] = 1.
+The second group is [0,1,2]. The size is 3, and groupSizes[0] = groupSizes[1] = groupSizes[2] = 3.
+The third group is [3,4,6]. The size is 3, and groupSizes[3] = groupSizes[4] = groupSizes[6] = 3.
+Other possible solutions are [[2,1,6],[5],[0,4,3]] and [[5],[0,6,2],[4,3,1]].
+
+ +

Example 2:

+ +
Input: groupSizes = [2,1,3,3,3,2]
+Output: [[1],[0,5],[2,3,4]]
+
+ +

 

+

Constraints:

+ +
    +
  • groupSizes.length == n
  • +
  • 1 <= n <= 500
  • +
  • 1 <= groupSizes[i] <= n
  • +
+
\ No newline at end of file diff --git a/1287-element-appearing-more-than-25-in-sorted-array/1287-element-appearing-more-than-25-in-sorted-array.py b/problems/1287-element-appearing-more-than-25-in-sorted-array/1287-element-appearing-more-than-25-in-sorted-array.py similarity index 100% rename from 1287-element-appearing-more-than-25-in-sorted-array/1287-element-appearing-more-than-25-in-sorted-array.py rename to problems/1287-element-appearing-more-than-25-in-sorted-array/1287-element-appearing-more-than-25-in-sorted-array.py diff --git a/1287-element-appearing-more-than-25-in-sorted-array/NOTES.md b/problems/1287-element-appearing-more-than-25-in-sorted-array/NOTES.md similarity index 100% rename from 1287-element-appearing-more-than-25-in-sorted-array/NOTES.md rename to problems/1287-element-appearing-more-than-25-in-sorted-array/NOTES.md diff --git a/problems/1287-element-appearing-more-than-25-in-sorted-array/README.md b/problems/1287-element-appearing-more-than-25-in-sorted-array/README.md new file mode 100644 index 000000000..d7dfbbffb --- /dev/null +++ b/problems/1287-element-appearing-more-than-25-in-sorted-array/README.md @@ -0,0 +1,23 @@ +

1287. Element Appearing More Than 25% In Sorted Array

Easy


Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.

+ +

 

+

Example 1:

+ +
Input: arr = [1,2,2,6,6,6,6,7,10]
+Output: 6
+
+ +

Example 2:

+ +
Input: arr = [1,1]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 104
  • +
  • 0 <= arr[i] <= 105
  • +
+
\ No newline at end of file diff --git a/1289-minimum-falling-path-sum-ii/1289-minimum-falling-path-sum-ii.py b/problems/1289-minimum-falling-path-sum-ii/1289-minimum-falling-path-sum-ii.py similarity index 100% rename from 1289-minimum-falling-path-sum-ii/1289-minimum-falling-path-sum-ii.py rename to problems/1289-minimum-falling-path-sum-ii/1289-minimum-falling-path-sum-ii.py diff --git a/1289-minimum-falling-path-sum-ii/NOTES.md b/problems/1289-minimum-falling-path-sum-ii/NOTES.md similarity index 100% rename from 1289-minimum-falling-path-sum-ii/NOTES.md rename to problems/1289-minimum-falling-path-sum-ii/NOTES.md diff --git a/problems/1289-minimum-falling-path-sum-ii/README.md b/problems/1289-minimum-falling-path-sum-ii/README.md new file mode 100644 index 000000000..90e5bbb6a --- /dev/null +++ b/problems/1289-minimum-falling-path-sum-ii/README.md @@ -0,0 +1,32 @@ +

1289. Minimum Falling Path Sum II

Hard


Given an n x n integer matrix grid, return the minimum sum of a falling path with non-zero shifts.

+ +

A falling path with non-zero shifts is a choice of exactly one element from each row of grid such that no two elements chosen in adjacent rows are in the same column.

+ +

 

+

Example 1:

+ +
Input: grid = [[1,2,3],[4,5,6],[7,8,9]]
+Output: 13
+Explanation: 
+The possible falling paths are:
+[1,5,9], [1,5,7], [1,6,7], [1,6,8],
+[2,4,8], [2,4,9], [2,6,7], [2,6,8],
+[3,4,8], [3,4,9], [3,5,7], [3,5,9]
+The falling path with the smallest sum is [1,5,7], so the answer is 13.
+
+ +

Example 2:

+ +
Input: grid = [[7]]
+Output: 7
+
+ +

 

+

Constraints:

+ +
    +
  • n == grid.length == grid[i].length
  • +
  • 1 <= n <= 200
  • +
  • -99 <= grid[i][j] <= 99
  • +
+
\ No newline at end of file diff --git a/1291-sequential-digits/1291-sequential-digits.py b/problems/1291-sequential-digits/1291-sequential-digits.py similarity index 100% rename from 1291-sequential-digits/1291-sequential-digits.py rename to problems/1291-sequential-digits/1291-sequential-digits.py diff --git a/1291-sequential-digits/NOTES.md b/problems/1291-sequential-digits/NOTES.md similarity index 100% rename from 1291-sequential-digits/NOTES.md rename to problems/1291-sequential-digits/NOTES.md diff --git a/problems/1291-sequential-digits/README.md b/problems/1291-sequential-digits/README.md new file mode 100644 index 000000000..bc5b1ec64 --- /dev/null +++ b/problems/1291-sequential-digits/README.md @@ -0,0 +1,19 @@ +

1291. Sequential Digits

Medium


An integer has sequential digits if and only if each digit in the number is one more than the previous digit.

+ +

Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.

+ +

 

+

Example 1:

+
Input: low = 100, high = 300
+Output: [123,234]
+

Example 2:

+
Input: low = 1000, high = 13000
+Output: [1234,2345,3456,4567,5678,6789,12345]
+
+

 

+

Constraints:

+ +
    +
  • 10 <= low <= high <= 10^9
  • +
+
\ No newline at end of file diff --git a/1325-delete-leaves-with-a-given-value/1325-delete-leaves-with-a-given-value.py b/problems/1325-delete-leaves-with-a-given-value/1325-delete-leaves-with-a-given-value.py similarity index 100% rename from 1325-delete-leaves-with-a-given-value/1325-delete-leaves-with-a-given-value.py rename to problems/1325-delete-leaves-with-a-given-value/1325-delete-leaves-with-a-given-value.py diff --git a/1325-delete-leaves-with-a-given-value/NOTES.md b/problems/1325-delete-leaves-with-a-given-value/NOTES.md similarity index 100% rename from 1325-delete-leaves-with-a-given-value/NOTES.md rename to problems/1325-delete-leaves-with-a-given-value/NOTES.md diff --git a/problems/1325-delete-leaves-with-a-given-value/README.md b/problems/1325-delete-leaves-with-a-given-value/README.md new file mode 100644 index 000000000..23f321db6 --- /dev/null +++ b/problems/1325-delete-leaves-with-a-given-value/README.md @@ -0,0 +1,40 @@ +

1325. Delete Leaves With a Given Value

Medium


Given a binary tree root and an integer target, delete all the leaf nodes with value target.

+ +

Note that once you delete a leaf node with value target, if its parent node becomes a leaf node and has the value target, it should also be deleted (you need to continue doing that until you cannot).

+ +

 

+

Example 1:

+ +

+ +
Input: root = [1,2,3,2,null,2,4], target = 2
+Output: [1,null,3,null,4]
+Explanation: Leaf nodes in green with value (target = 2) are removed (Picture in left). 
+After removing, new nodes become leaf nodes with value (target = 2) (Picture in center).
+
+ +

Example 2:

+ +

+ +
Input: root = [1,3,3,3,2], target = 3
+Output: [1,3,null,null,2]
+
+ +

Example 3:

+ +

+ +
Input: root = [1,2,null,2,null,2], target = 2
+Output: [1]
+Explanation: Leaf nodes in green with value (target = 2) are removed at each step.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 3000].
  • +
  • 1 <= Node.val, target <= 1000
  • +
+
\ No newline at end of file diff --git a/1326-minimum-number-of-taps-to-open-to-water-a-garden/1326-minimum-number-of-taps-to-open-to-water-a-garden.py b/problems/1326-minimum-number-of-taps-to-open-to-water-a-garden/1326-minimum-number-of-taps-to-open-to-water-a-garden.py similarity index 100% rename from 1326-minimum-number-of-taps-to-open-to-water-a-garden/1326-minimum-number-of-taps-to-open-to-water-a-garden.py rename to problems/1326-minimum-number-of-taps-to-open-to-water-a-garden/1326-minimum-number-of-taps-to-open-to-water-a-garden.py diff --git a/1326-minimum-number-of-taps-to-open-to-water-a-garden/NOTES.md b/problems/1326-minimum-number-of-taps-to-open-to-water-a-garden/NOTES.md similarity index 100% rename from 1326-minimum-number-of-taps-to-open-to-water-a-garden/NOTES.md rename to problems/1326-minimum-number-of-taps-to-open-to-water-a-garden/NOTES.md diff --git a/problems/1326-minimum-number-of-taps-to-open-to-water-a-garden/README.md b/problems/1326-minimum-number-of-taps-to-open-to-water-a-garden/README.md new file mode 100644 index 000000000..ce218a32a --- /dev/null +++ b/problems/1326-minimum-number-of-taps-to-open-to-water-a-garden/README.md @@ -0,0 +1,38 @@ +

1326. Minimum Number of Taps to Open to Water a Garden

Hard


There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e The length of the garden is n).

+ +

There are n + 1 taps located at points [0, 1, ..., n] in the garden.

+ +

Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open.

+ +

Return the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1.

+ +

 

+

Example 1:

+ +
Input: n = 5, ranges = [3,4,1,1,0,0]
+Output: 1
+Explanation: The tap at point 0 can cover the interval [-3,3]
+The tap at point 1 can cover the interval [-3,5]
+The tap at point 2 can cover the interval [1,3]
+The tap at point 3 can cover the interval [2,4]
+The tap at point 4 can cover the interval [4,4]
+The tap at point 5 can cover the interval [5,5]
+Opening Only the second tap will water the whole garden [0,5]
+
+ +

Example 2:

+ +
Input: n = 3, ranges = [0,0,0,0]
+Output: -1
+Explanation: Even if you activate all the four taps you cannot water the whole garden.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 104
  • +
  • ranges.length == n + 1
  • +
  • 0 <= ranges[i] <= 100
  • +
+
\ No newline at end of file diff --git a/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.py b/problems/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.py similarity index 100% rename from 1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.py rename to problems/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.py diff --git a/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/NOTES.md b/problems/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/NOTES.md similarity index 100% rename from 1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/NOTES.md rename to problems/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/NOTES.md diff --git a/problems/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/README.md b/problems/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/README.md new file mode 100644 index 000000000..b1f25dcea --- /dev/null +++ b/problems/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/README.md @@ -0,0 +1,46 @@ +

1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance

Medium


There are n cities numbered from 0 to n-1. Given the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distanceThreshold.

+ +

Return the city with the smallest number of cities that are reachable through some path and whose distance is at most distanceThreshold, If there are multiple such cities, return the city with the greatest number.

+ +

Notice that the distance of a path connecting cities i and j is equal to the sum of the edges' weights along that path.

+ +

 

+

Example 1:

+ +
Input: n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4
+Output: 3
+Explanation: The figure above describes the graph. 
+The neighboring cities at a distanceThreshold = 4 for each city are:
+City 0 -> [City 1, City 2] 
+City 1 -> [City 0, City 2, City 3] 
+City 2 -> [City 0, City 1, City 3] 
+City 3 -> [City 1, City 2] 
+Cities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number.
+
+ +

Example 2:

+ +
Input: n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2
+Output: 0
+Explanation: The figure above describes the graph. 
+The neighboring cities at a distanceThreshold = 2 for each city are:
+City 0 -> [City 1] 
+City 1 -> [City 0, City 4] 
+City 2 -> [City 3, City 4] 
+City 3 -> [City 2, City 4]
+City 4 -> [City 1, City 2, City 3] 
+The city 0 has 1 neighboring city at a distanceThreshold = 2.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 100
  • +
  • 1 <= edges.length <= n * (n - 1) / 2
  • +
  • edges[i].length == 3
  • +
  • 0 <= fromi < toi < n
  • +
  • 1 <= weighti, distanceThreshold <= 10^4
  • +
  • All pairs (fromi, toi) are distinct.
  • +
+
\ No newline at end of file diff --git a/1335-minimum-difficulty-of-a-job-schedule/1335-minimum-difficulty-of-a-job-schedule.py b/problems/1335-minimum-difficulty-of-a-job-schedule/1335-minimum-difficulty-of-a-job-schedule.py similarity index 100% rename from 1335-minimum-difficulty-of-a-job-schedule/1335-minimum-difficulty-of-a-job-schedule.py rename to problems/1335-minimum-difficulty-of-a-job-schedule/1335-minimum-difficulty-of-a-job-schedule.py diff --git a/1335-minimum-difficulty-of-a-job-schedule/NOTES.md b/problems/1335-minimum-difficulty-of-a-job-schedule/NOTES.md similarity index 100% rename from 1335-minimum-difficulty-of-a-job-schedule/NOTES.md rename to problems/1335-minimum-difficulty-of-a-job-schedule/NOTES.md diff --git a/problems/1335-minimum-difficulty-of-a-job-schedule/README.md b/problems/1335-minimum-difficulty-of-a-job-schedule/README.md new file mode 100644 index 000000000..2c1f61306 --- /dev/null +++ b/problems/1335-minimum-difficulty-of-a-job-schedule/README.md @@ -0,0 +1,41 @@ +

1335. Minimum Difficulty of a Job Schedule

Hard


You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the ith job, you have to finish all the jobs j where 0 <= j < i).

+ +

You have to finish at least one task every day. The difficulty of a job schedule is the sum of difficulties of each day of the d days. The difficulty of a day is the maximum difficulty of a job done on that day.

+ +

You are given an integer array jobDifficulty and an integer d. The difficulty of the ith job is jobDifficulty[i].

+ +

Return the minimum difficulty of a job schedule. If you cannot find a schedule for the jobs return -1.

+ +

 

+

Example 1:

+ +
Input: jobDifficulty = [6,5,4,3,2,1], d = 2
+Output: 7
+Explanation: First day you can finish the first 5 jobs, total difficulty = 6.
+Second day you can finish the last job, total difficulty = 1.
+The difficulty of the schedule = 6 + 1 = 7 
+
+ +

Example 2:

+ +
Input: jobDifficulty = [9,9,9], d = 4
+Output: -1
+Explanation: If you finish a job per day you will still have a free day. you cannot find a schedule for the given jobs.
+
+ +

Example 3:

+ +
Input: jobDifficulty = [1,1,1], d = 3
+Output: 3
+Explanation: The schedule is one job per day. total difficulty will be 3.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= jobDifficulty.length <= 300
  • +
  • 0 <= jobDifficulty[i] <= 1000
  • +
  • 1 <= d <= 10
  • +
+
\ No newline at end of file diff --git a/1337-the-k-weakest-rows-in-a-matrix/1337-the-k-weakest-rows-in-a-matrix.py b/problems/1337-the-k-weakest-rows-in-a-matrix/1337-the-k-weakest-rows-in-a-matrix.py similarity index 100% rename from 1337-the-k-weakest-rows-in-a-matrix/1337-the-k-weakest-rows-in-a-matrix.py rename to problems/1337-the-k-weakest-rows-in-a-matrix/1337-the-k-weakest-rows-in-a-matrix.py diff --git a/1337-the-k-weakest-rows-in-a-matrix/NOTES.md b/problems/1337-the-k-weakest-rows-in-a-matrix/NOTES.md similarity index 100% rename from 1337-the-k-weakest-rows-in-a-matrix/NOTES.md rename to problems/1337-the-k-weakest-rows-in-a-matrix/NOTES.md diff --git a/problems/1337-the-k-weakest-rows-in-a-matrix/README.md b/problems/1337-the-k-weakest-rows-in-a-matrix/README.md new file mode 100644 index 000000000..7f0784e51 --- /dev/null +++ b/problems/1337-the-k-weakest-rows-in-a-matrix/README.md @@ -0,0 +1,61 @@ +

1337. The K Weakest Rows in a Matrix

Easy


You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.

+ +

A row i is weaker than a row j if one of the following is true:

+ +
    +
  • The number of soldiers in row i is less than the number of soldiers in row j.
  • +
  • Both rows have the same number of soldiers and i < j.
  • +
+ +

Return the indices of the k weakest rows in the matrix ordered from weakest to strongest.

+ +

 

+

Example 1:

+ +
Input: mat = 
+[[1,1,0,0,0],
+ [1,1,1,1,0],
+ [1,0,0,0,0],
+ [1,1,0,0,0],
+ [1,1,1,1,1]], 
+k = 3
+Output: [2,0,3]
+Explanation: 
+The number of soldiers in each row is: 
+- Row 0: 2 
+- Row 1: 4 
+- Row 2: 1 
+- Row 3: 2 
+- Row 4: 5 
+The rows ordered from weakest to strongest are [2,0,3,1,4].
+
+ +

Example 2:

+ +
Input: mat = 
+[[1,0,0,0],
+ [1,1,1,1],
+ [1,0,0,0],
+ [1,0,0,0]], 
+k = 2
+Output: [0,2]
+Explanation: 
+The number of soldiers in each row is: 
+- Row 0: 1 
+- Row 1: 4 
+- Row 2: 1 
+- Row 3: 1 
+The rows ordered from weakest to strongest are [0,2,3,1].
+
+ +

 

+

Constraints:

+ +
    +
  • m == mat.length
  • +
  • n == mat[i].length
  • +
  • 2 <= n, m <= 100
  • +
  • 1 <= k <= m
  • +
  • matrix[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/1347-minimum-number-of-steps-to-make-two-strings-anagram/1347-minimum-number-of-steps-to-make-two-strings-anagram.py b/problems/1347-minimum-number-of-steps-to-make-two-strings-anagram/1347-minimum-number-of-steps-to-make-two-strings-anagram.py similarity index 100% rename from 1347-minimum-number-of-steps-to-make-two-strings-anagram/1347-minimum-number-of-steps-to-make-two-strings-anagram.py rename to problems/1347-minimum-number-of-steps-to-make-two-strings-anagram/1347-minimum-number-of-steps-to-make-two-strings-anagram.py diff --git a/1347-minimum-number-of-steps-to-make-two-strings-anagram/NOTES.md b/problems/1347-minimum-number-of-steps-to-make-two-strings-anagram/NOTES.md similarity index 100% rename from 1347-minimum-number-of-steps-to-make-two-strings-anagram/NOTES.md rename to problems/1347-minimum-number-of-steps-to-make-two-strings-anagram/NOTES.md diff --git a/problems/1347-minimum-number-of-steps-to-make-two-strings-anagram/README.md b/problems/1347-minimum-number-of-steps-to-make-two-strings-anagram/README.md new file mode 100644 index 000000000..6838a54f2 --- /dev/null +++ b/problems/1347-minimum-number-of-steps-to-make-two-strings-anagram/README.md @@ -0,0 +1,37 @@ +

1347. Minimum Number of Steps to Make Two Strings Anagram

Medium


You are given two strings of the same length s and t. In one step you can choose any character of t and replace it with another character.

+ +

Return the minimum number of steps to make t an anagram of s.

+ +

An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.

+ +

 

+

Example 1:

+ +
Input: s = "bab", t = "aba"
+Output: 1
+Explanation: Replace the first 'a' in t with b, t = "bba" which is anagram of s.
+
+ +

Example 2:

+ +
Input: s = "leetcode", t = "practice"
+Output: 5
+Explanation: Replace 'p', 'r', 'a', 'i' and 'c' from t with proper characters to make t anagram of s.
+
+ +

Example 3:

+ +
Input: s = "anagram", t = "mangaar"
+Output: 0
+Explanation: "anagram" and "mangaar" are anagrams. 
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 5 * 104
  • +
  • s.length == t.length
  • +
  • s and t consist of lowercase English letters only.
  • +
+
\ No newline at end of file diff --git a/1356-sort-integers-by-the-number-of-1-bits/1356-sort-integers-by-the-number-of-1-bits.py b/problems/1356-sort-integers-by-the-number-of-1-bits/1356-sort-integers-by-the-number-of-1-bits.py similarity index 100% rename from 1356-sort-integers-by-the-number-of-1-bits/1356-sort-integers-by-the-number-of-1-bits.py rename to problems/1356-sort-integers-by-the-number-of-1-bits/1356-sort-integers-by-the-number-of-1-bits.py diff --git a/1356-sort-integers-by-the-number-of-1-bits/NOTES.md b/problems/1356-sort-integers-by-the-number-of-1-bits/NOTES.md similarity index 100% rename from 1356-sort-integers-by-the-number-of-1-bits/NOTES.md rename to problems/1356-sort-integers-by-the-number-of-1-bits/NOTES.md diff --git a/problems/1356-sort-integers-by-the-number-of-1-bits/README.md b/problems/1356-sort-integers-by-the-number-of-1-bits/README.md new file mode 100644 index 000000000..75b8e6dec --- /dev/null +++ b/problems/1356-sort-integers-by-the-number-of-1-bits/README.md @@ -0,0 +1,31 @@ +

1356. Sort Integers by The Number of 1 Bits

Easy


You are given an integer array arr. Sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more integers have the same number of 1's you have to sort them in ascending order.

+ +

Return the array after sorting it.

+ +

 

+

Example 1:

+ +
Input: arr = [0,1,2,3,4,5,6,7,8]
+Output: [0,1,2,4,8,3,5,6,7]
+Explantion: [0] is the only integer with 0 bits.
+[1,2,4,8] all have 1 bit.
+[3,5,6] have 2 bits.
+[7] has 3 bits.
+The sorted array by bits is [0,1,2,4,8,3,5,6,7]
+
+ +

Example 2:

+ +
Input: arr = [1024,512,256,128,64,32,16,8,4,2,1]
+Output: [1,2,4,8,16,32,64,128,256,512,1024]
+Explantion: All integers have 1 bit in the binary representation, you should just sort them in ascending order.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 500
  • +
  • 0 <= arr[i] <= 104
  • +
+
\ No newline at end of file diff --git a/1359-count-all-valid-pickup-and-delivery-options/1359-count-all-valid-pickup-and-delivery-options.py b/problems/1359-count-all-valid-pickup-and-delivery-options/1359-count-all-valid-pickup-and-delivery-options.py similarity index 100% rename from 1359-count-all-valid-pickup-and-delivery-options/1359-count-all-valid-pickup-and-delivery-options.py rename to problems/1359-count-all-valid-pickup-and-delivery-options/1359-count-all-valid-pickup-and-delivery-options.py diff --git a/1359-count-all-valid-pickup-and-delivery-options/NOTES.md b/problems/1359-count-all-valid-pickup-and-delivery-options/NOTES.md similarity index 100% rename from 1359-count-all-valid-pickup-and-delivery-options/NOTES.md rename to problems/1359-count-all-valid-pickup-and-delivery-options/NOTES.md diff --git a/problems/1359-count-all-valid-pickup-and-delivery-options/README.md b/problems/1359-count-all-valid-pickup-and-delivery-options/README.md new file mode 100644 index 000000000..35b4e77bf --- /dev/null +++ b/problems/1359-count-all-valid-pickup-and-delivery-options/README.md @@ -0,0 +1,36 @@ +

1359. Count All Valid Pickup and Delivery Options

Hard


Given n orders, each order consist in pickup and delivery services. 

+ +

Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i). 

+ +

Since the answer may be too large, return it modulo 10^9 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 1
+Output: 1
+Explanation: Unique order (P1, D1), Delivery 1 always is after of Pickup 1.
+
+ +

Example 2:

+ +
Input: n = 2
+Output: 6
+Explanation: All possible orders: 
+(P1,P2,D1,D2), (P1,P2,D2,D1), (P1,D1,P2,D2), (P2,P1,D1,D2), (P2,P1,D2,D1) and (P2,D2,P1,D1).
+This is an invalid order (P1,D2,P2,D1) because Pickup 2 is after of Delivery 2.
+
+ +

Example 3:

+ +
Input: n = 3
+Output: 90
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 500
  • +
+
\ No newline at end of file diff --git a/1361-validate-binary-tree-nodes/1361-validate-binary-tree-nodes.py b/problems/1361-validate-binary-tree-nodes/1361-validate-binary-tree-nodes.py similarity index 100% rename from 1361-validate-binary-tree-nodes/1361-validate-binary-tree-nodes.py rename to problems/1361-validate-binary-tree-nodes/1361-validate-binary-tree-nodes.py diff --git a/1361-validate-binary-tree-nodes/NOTES.md b/problems/1361-validate-binary-tree-nodes/NOTES.md similarity index 100% rename from 1361-validate-binary-tree-nodes/NOTES.md rename to problems/1361-validate-binary-tree-nodes/NOTES.md diff --git a/problems/1361-validate-binary-tree-nodes/README.md b/problems/1361-validate-binary-tree-nodes/README.md new file mode 100644 index 000000000..ac15f6e09 --- /dev/null +++ b/problems/1361-validate-binary-tree-nodes/README.md @@ -0,0 +1,34 @@ +

1361. Validate Binary Tree Nodes

Medium


You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.

+ +

If node i has no left child then leftChild[i] will equal -1, similarly for the right child.

+ +

Note that the nodes have no values and that we only use the node numbers in this problem.

+ +

 

+

Example 1:

+ +
Input: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]
+Output: true
+
+ +

Example 2:

+ +
Input: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]
+Output: false
+
+ +

Example 3:

+ +
Input: n = 2, leftChild = [1,0], rightChild = [-1,-1]
+Output: false
+
+ +

 

+

Constraints:

+ +
    +
  • n == leftChild.length == rightChild.length
  • +
  • 1 <= n <= 104
  • +
  • -1 <= leftChild[i], rightChild[i] <= n - 1
  • +
+
\ No newline at end of file diff --git a/1380-lucky-numbers-in-a-matrix/1380-lucky-numbers-in-a-matrix.py b/problems/1380-lucky-numbers-in-a-matrix/1380-lucky-numbers-in-a-matrix.py similarity index 100% rename from 1380-lucky-numbers-in-a-matrix/1380-lucky-numbers-in-a-matrix.py rename to problems/1380-lucky-numbers-in-a-matrix/1380-lucky-numbers-in-a-matrix.py diff --git a/problems/1380-lucky-numbers-in-a-matrix/README.md b/problems/1380-lucky-numbers-in-a-matrix/README.md new file mode 100644 index 000000000..5cfd13f59 --- /dev/null +++ b/problems/1380-lucky-numbers-in-a-matrix/README.md @@ -0,0 +1,37 @@ +

1380. Lucky Numbers in a Matrix

Easy


Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

+ +

A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.

+ +

 

+

Example 1:

+ +
Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
+Output: [15]
+Explanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column.
+
+ +

Example 2:

+ +
Input: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
+Output: [12]
+Explanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.
+
+ +

Example 3:

+ +
Input: matrix = [[7,8],[1,2]]
+Output: [7]
+Explanation: 7 is the only lucky number since it is the minimum in its row and the maximum in its column.
+
+ +

 

+

Constraints:

+ +
    +
  • m == mat.length
  • +
  • n == mat[i].length
  • +
  • 1 <= n, m <= 50
  • +
  • 1 <= matrix[i][j] <= 105.
  • +
  • All elements in the matrix are distinct.
  • +
+
\ No newline at end of file diff --git a/1382-balance-a-binary-search-tree/1382-balance-a-binary-search-tree.py b/problems/1382-balance-a-binary-search-tree/1382-balance-a-binary-search-tree.py similarity index 100% rename from 1382-balance-a-binary-search-tree/1382-balance-a-binary-search-tree.py rename to problems/1382-balance-a-binary-search-tree/1382-balance-a-binary-search-tree.py diff --git a/1382-balance-a-binary-search-tree/NOTES.md b/problems/1382-balance-a-binary-search-tree/NOTES.md similarity index 100% rename from 1382-balance-a-binary-search-tree/NOTES.md rename to problems/1382-balance-a-binary-search-tree/NOTES.md diff --git a/1395-count-number-of-teams/1395-count-number-of-teams.py b/problems/1395-count-number-of-teams/1395-count-number-of-teams.py similarity index 100% rename from 1395-count-number-of-teams/1395-count-number-of-teams.py rename to problems/1395-count-number-of-teams/1395-count-number-of-teams.py diff --git a/1395-count-number-of-teams/NOTES.md b/problems/1395-count-number-of-teams/NOTES.md similarity index 100% rename from 1395-count-number-of-teams/NOTES.md rename to problems/1395-count-number-of-teams/NOTES.md diff --git a/problems/1395-count-number-of-teams/README.md b/problems/1395-count-number-of-teams/README.md new file mode 100644 index 000000000..e0ebb7f20 --- /dev/null +++ b/problems/1395-count-number-of-teams/README.md @@ -0,0 +1,42 @@ +

1395. Count Number of Teams

Medium


There are n soldiers standing in a line. Each soldier is assigned a unique rating value.

+ +

You have to form a team of 3 soldiers amongst them under the following rules:

+ +
    +
  • Choose 3 soldiers with index (i, j, k) with rating (rating[i], rating[j], rating[k]).
  • +
  • A team is valid if: (rating[i] < rating[j] < rating[k]) or (rating[i] > rating[j] > rating[k]) where (0 <= i < j < k < n).
  • +
+ +

Return the number of teams you can form given the conditions. (soldiers can be part of multiple teams).

+ +

 

+

Example 1:

+ +
Input: rating = [2,5,3,4,1]
+Output: 3
+Explanation: We can form three teams given the conditions. (2,3,4), (5,4,1), (5,3,1). 
+
+ +

Example 2:

+ +
Input: rating = [2,1,3]
+Output: 0
+Explanation: We can't form any team given the conditions.
+
+ +

Example 3:

+ +
Input: rating = [1,2,3,4]
+Output: 4
+
+ +

 

+

Constraints:

+ +
    +
  • n == rating.length
  • +
  • 3 <= n <= 1000
  • +
  • 1 <= rating[i] <= 105
  • +
  • All the integers in rating are unique.
  • +
+
\ No newline at end of file diff --git a/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.py b/problems/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.py similarity index 100% rename from 1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.py rename to problems/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one.py diff --git a/problems/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/README.md b/problems/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/README.md new file mode 100644 index 000000000..d5797331c --- /dev/null +++ b/problems/1404-number-of-steps-to-reduce-a-number-in-binary-representation-to-one/README.md @@ -0,0 +1,50 @@ +

1404. Number of Steps to Reduce a Number in Binary Representation to One

Medium


Given the binary representation of an integer as a string s, return the number of steps to reduce it to 1 under the following rules:

+ +
    +
  • +

    If the current number is even, you have to divide it by 2.

    +
  • +
  • +

    If the current number is odd, you have to add 1 to it.

    +
  • +
+ +

It is guaranteed that you can always reach one for all test cases.

+ +

 

+

Example 1:

+ +
Input: s = "1101"
+Output: 6
+Explanation: "1101" corressponds to number 13 in their decimal representation.
+Step 1) 13 is odd, add 1 and obtain 14. 
+Step 2) 14 is even, divide by 2 and obtain 7.
+Step 3) 7 is odd, add 1 and obtain 8.
+Step 4) 8 is even, divide by 2 and obtain 4.  
+Step 5) 4 is even, divide by 2 and obtain 2. 
+Step 6) 2 is even, divide by 2 and obtain 1.  
+
+ +

Example 2:

+ +
Input: s = "10"
+Output: 1
+Explanation: "10" corressponds to number 2 in their decimal representation.
+Step 1) 2 is even, divide by 2 and obtain 1.  
+
+ +

Example 3:

+ +
Input: s = "1"
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 500
  • +
  • s consists of characters '0' or '1'
  • +
  • s[0] == '1'
  • +
+
\ No newline at end of file diff --git a/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.py b/problems/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.py similarity index 100% rename from 1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.py rename to problems/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.py diff --git a/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/NOTES.md b/problems/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/NOTES.md similarity index 100% rename from 1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/NOTES.md rename to problems/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/NOTES.md diff --git a/problems/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/README.md b/problems/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/README.md new file mode 100644 index 000000000..32f673a4c --- /dev/null +++ b/problems/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons/README.md @@ -0,0 +1,43 @@ +

1420. Build Array Where You Can Find The Maximum Exactly K Comparisons

Hard


You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:

+ +

You should build the array arr which has the following properties:

+ +
    +
  • arr has exactly n integers.
  • +
  • 1 <= arr[i] <= m where (0 <= i < n).
  • +
  • After applying the mentioned algorithm to arr, the value search_cost is equal to k.
  • +
+ +

Return the number of ways to build the array arr under the mentioned conditions. As the answer may grow large, the answer must be computed modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: n = 2, m = 3, k = 1
+Output: 6
+Explanation: The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]
+
+ +

Example 2:

+ +
Input: n = 5, m = 2, k = 3
+Output: 0
+Explanation: There are no possible arrays that satisfy the mentioned conditions.
+
+ +

Example 3:

+ +
Input: n = 9, m = 1, k = 1
+Output: 1
+Explanation: The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 50
  • +
  • 1 <= m <= 100
  • +
  • 0 <= k <= n
  • +
+
\ No newline at end of file diff --git a/1422-maximum-score-after-splitting-a-string/1422-maximum-score-after-splitting-a-string.py b/problems/1422-maximum-score-after-splitting-a-string/1422-maximum-score-after-splitting-a-string.py similarity index 100% rename from 1422-maximum-score-after-splitting-a-string/1422-maximum-score-after-splitting-a-string.py rename to problems/1422-maximum-score-after-splitting-a-string/1422-maximum-score-after-splitting-a-string.py diff --git a/1422-maximum-score-after-splitting-a-string/NOTES.md b/problems/1422-maximum-score-after-splitting-a-string/NOTES.md similarity index 100% rename from 1422-maximum-score-after-splitting-a-string/NOTES.md rename to problems/1422-maximum-score-after-splitting-a-string/NOTES.md diff --git a/problems/1422-maximum-score-after-splitting-a-string/README.md b/problems/1422-maximum-score-after-splitting-a-string/README.md new file mode 100644 index 000000000..a8524c03f --- /dev/null +++ b/problems/1422-maximum-score-after-splitting-a-string/README.md @@ -0,0 +1,39 @@ +

1422. Maximum Score After Splitting a String

Easy


Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).

+ +

The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.

+ +

 

+

Example 1:

+ +
Input: s = "011101"
+Output: 5 
+Explanation: 
+All possible ways of splitting s into two non-empty substrings are:
+left = "0" and right = "11101", score = 1 + 4 = 5 
+left = "01" and right = "1101", score = 1 + 3 = 4 
+left = "011" and right = "101", score = 1 + 2 = 3 
+left = "0111" and right = "01", score = 1 + 1 = 2 
+left = "01110" and right = "1", score = 2 + 1 = 3
+
+ +

Example 2:

+ +
Input: s = "00111"
+Output: 5
+Explanation: When left = "00" and right = "111", we get the maximum score = 2 + 3 = 5
+
+ +

Example 3:

+ +
Input: s = "1111"
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= s.length <= 500
  • +
  • The string s consists of characters '0' and '1' only.
  • +
+
\ No newline at end of file diff --git a/1424-diagonal-traverse-ii/1424-diagonal-traverse-ii.py b/problems/1424-diagonal-traverse-ii/1424-diagonal-traverse-ii.py similarity index 100% rename from 1424-diagonal-traverse-ii/1424-diagonal-traverse-ii.py rename to problems/1424-diagonal-traverse-ii/1424-diagonal-traverse-ii.py diff --git a/1424-diagonal-traverse-ii/NOTES.md b/problems/1424-diagonal-traverse-ii/NOTES.md similarity index 100% rename from 1424-diagonal-traverse-ii/NOTES.md rename to problems/1424-diagonal-traverse-ii/NOTES.md diff --git a/problems/1424-diagonal-traverse-ii/README.md b/problems/1424-diagonal-traverse-ii/README.md new file mode 100644 index 000000000..4cc012c96 --- /dev/null +++ b/problems/1424-diagonal-traverse-ii/README.md @@ -0,0 +1,25 @@ +

1424. Diagonal Traverse II

Medium


Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.

+ +

 

+

Example 1:

+ +
Input: nums = [[1,2,3],[4,5,6],[7,8,9]]
+Output: [1,4,2,7,5,3,8,6,9]
+
+ +

Example 2:

+ +
Input: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]
+Output: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i].length <= 105
  • +
  • 1 <= sum(nums[i].length) <= 105
  • +
  • 1 <= nums[i][j] <= 105
  • +
+
\ No newline at end of file diff --git a/1425-constrained-subsequence-sum/1425-constrained-subsequence-sum.py b/problems/1425-constrained-subsequence-sum/1425-constrained-subsequence-sum.py similarity index 100% rename from 1425-constrained-subsequence-sum/1425-constrained-subsequence-sum.py rename to problems/1425-constrained-subsequence-sum/1425-constrained-subsequence-sum.py diff --git a/1425-constrained-subsequence-sum/NOTES.md b/problems/1425-constrained-subsequence-sum/NOTES.md similarity index 100% rename from 1425-constrained-subsequence-sum/NOTES.md rename to problems/1425-constrained-subsequence-sum/NOTES.md diff --git a/problems/1425-constrained-subsequence-sum/README.md b/problems/1425-constrained-subsequence-sum/README.md new file mode 100644 index 000000000..6afbb1b60 --- /dev/null +++ b/problems/1425-constrained-subsequence-sum/README.md @@ -0,0 +1,34 @@ +

1425. Constrained Subsequence Sum

Hard


Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j], where i < j, the condition j - i <= k is satisfied.

+ +

A subsequence of an array is obtained by deleting some number of elements (can be zero) from the array, leaving the remaining elements in their original order.

+ +

 

+

Example 1:

+ +
Input: nums = [10,2,-10,5,20], k = 2
+Output: 37
+Explanation: The subsequence is [10, 2, 5, 20].
+
+ +

Example 2:

+ +
Input: nums = [-1,-2,-3], k = 1
+Output: -1
+Explanation: The subsequence must be non-empty, so we choose the largest number.
+
+ +

Example 3:

+ +
Input: nums = [10,-2,-10,-5,20], k = 2
+Output: 23
+Explanation: The subsequence is [10, -2, -5, 20].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= nums.length <= 105
  • +
  • -104 <= nums[i] <= 104
  • +
+
\ No newline at end of file diff --git a/1428-leftmost-column-with-at-least-a-one/1428-leftmost-column-with-at-least-a-one.py b/problems/1428-leftmost-column-with-at-least-a-one/1428-leftmost-column-with-at-least-a-one.py similarity index 100% rename from 1428-leftmost-column-with-at-least-a-one/1428-leftmost-column-with-at-least-a-one.py rename to problems/1428-leftmost-column-with-at-least-a-one/1428-leftmost-column-with-at-least-a-one.py diff --git a/1428-leftmost-column-with-at-least-a-one/NOTES.md b/problems/1428-leftmost-column-with-at-least-a-one/NOTES.md similarity index 100% rename from 1428-leftmost-column-with-at-least-a-one/NOTES.md rename to problems/1428-leftmost-column-with-at-least-a-one/NOTES.md diff --git a/problems/1428-leftmost-column-with-at-least-a-one/README.md b/problems/1428-leftmost-column-with-at-least-a-one/README.md new file mode 100644 index 000000000..ddf6d5be0 --- /dev/null +++ b/problems/1428-leftmost-column-with-at-least-a-one/README.md @@ -0,0 +1,45 @@ +

1428. Leftmost Column with at Least a One

Medium


A row-sorted binary matrix means that all elements are 0 or 1 and each row of the matrix is sorted in non-decreasing order.

+ +

Given a row-sorted binary matrix binaryMatrix, return the index (0-indexed) of the leftmost column with a 1 in it. If such an index does not exist, return -1.

+ +

You can't access the Binary Matrix directly. You may only access the matrix using a BinaryMatrix interface:

+ +
    +
  • BinaryMatrix.get(row, col) returns the element of the matrix at index (row, col) (0-indexed).
  • +
  • BinaryMatrix.dimensions() returns the dimensions of the matrix as a list of 2 elements [rows, cols], which means the matrix is rows x cols.
  • +
+ +

Submissions making more than 1000 calls to BinaryMatrix.get will be judged Wrong Answer. Also, any solutions that attempt to circumvent the judge will result in disqualification.

+ +

For custom testing purposes, the input will be the entire binary matrix mat. You will not have access to the binary matrix directly.

+ +

 

+

Example 1:

+ +
Input: mat = [[0,0],[1,1]]
+Output: 0
+
+ +

Example 2:

+ +
Input: mat = [[0,0],[0,1]]
+Output: 1
+
+ +

Example 3:

+ +
Input: mat = [[0,0],[0,0]]
+Output: -1
+
+ +

 

+

Constraints:

+ +
    +
  • rows == mat.length
  • +
  • cols == mat[i].length
  • +
  • 1 <= rows, cols <= 100
  • +
  • mat[i][j] is either 0 or 1.
  • +
  • mat[i] is sorted in non-decreasing order.
  • +
+
\ No newline at end of file diff --git a/1436-destination-city/1436-destination-city.py b/problems/1436-destination-city/1436-destination-city.py similarity index 100% rename from 1436-destination-city/1436-destination-city.py rename to problems/1436-destination-city/1436-destination-city.py diff --git a/1436-destination-city/NOTES.md b/problems/1436-destination-city/NOTES.md similarity index 100% rename from 1436-destination-city/NOTES.md rename to problems/1436-destination-city/NOTES.md diff --git a/problems/1436-destination-city/README.md b/problems/1436-destination-city/README.md new file mode 100644 index 000000000..f7fa451aa --- /dev/null +++ b/problems/1436-destination-city/README.md @@ -0,0 +1,41 @@ +

1436. Destination City

Easy


You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city.

+ +

It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city.

+ +

 

+

Example 1:

+ +
Input: paths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]
+Output: "Sao Paulo" 
+Explanation: Starting at "London" city you will reach "Sao Paulo" city which is the destination city. Your trip consist of: "London" -> "New York" -> "Lima" -> "Sao Paulo".
+
+ +

Example 2:

+ +
Input: paths = [["B","C"],["D","B"],["C","A"]]
+Output: "A"
+Explanation: All possible trips are: 
+"D" -> "B" -> "C" -> "A". 
+"B" -> "C" -> "A". 
+"C" -> "A". 
+"A". 
+Clearly the destination city is "A".
+
+ +

Example 3:

+ +
Input: paths = [["A","Z"]]
+Output: "Z"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= paths.length <= 100
  • +
  • paths[i].length == 2
  • +
  • 1 <= cityAi.length, cityBi.length <= 10
  • +
  • cityAi != cityBi
  • +
  • All strings consist of lowercase and uppercase English letters and the space character.
  • +
+
\ No newline at end of file diff --git a/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.py b/problems/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.py similarity index 100% rename from 1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.py rename to problems/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.py diff --git a/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/NOTES.md b/problems/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/NOTES.md similarity index 100% rename from 1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/NOTES.md rename to problems/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/NOTES.md diff --git a/problems/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/README.md b/problems/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/README.md new file mode 100644 index 000000000..8081e9124 --- /dev/null +++ b/problems/1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/README.md @@ -0,0 +1,43 @@ +

1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

Medium


Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.

+ +

 

+

Example 1:

+ +
Input: nums = [8,2,4,7], limit = 4
+Output: 2 
+Explanation: All subarrays are: 
+[8] with maximum absolute diff |8-8| = 0 <= 4.
+[8,2] with maximum absolute diff |8-2| = 6 > 4. 
+[8,2,4] with maximum absolute diff |8-2| = 6 > 4.
+[8,2,4,7] with maximum absolute diff |8-2| = 6 > 4.
+[2] with maximum absolute diff |2-2| = 0 <= 4.
+[2,4] with maximum absolute diff |2-4| = 2 <= 4.
+[2,4,7] with maximum absolute diff |2-7| = 5 > 4.
+[4] with maximum absolute diff |4-4| = 0 <= 4.
+[4,7] with maximum absolute diff |4-7| = 3 <= 4.
+[7] with maximum absolute diff |7-7| = 0 <= 4. 
+Therefore, the size of the longest subarray is 2.
+
+ +

Example 2:

+ +
Input: nums = [10,1,2,4,7,2], limit = 5
+Output: 4 
+Explanation: The subarray [2,4,7,2] is the longest since the maximum absolute diff is |2-7| = 5 <= 5.
+
+ +

Example 3:

+ +
Input: nums = [4,2,2,2,4,4,2,2], limit = 0
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 109
  • +
  • 0 <= limit <= 109
  • +
+
\ No newline at end of file diff --git a/1441-build-an-array-with-stack-operations/1441-build-an-array-with-stack-operations.py b/problems/1441-build-an-array-with-stack-operations/1441-build-an-array-with-stack-operations.py similarity index 100% rename from 1441-build-an-array-with-stack-operations/1441-build-an-array-with-stack-operations.py rename to problems/1441-build-an-array-with-stack-operations/1441-build-an-array-with-stack-operations.py diff --git a/problems/1441-build-an-array-with-stack-operations/README.md b/problems/1441-build-an-array-with-stack-operations/README.md new file mode 100644 index 000000000..35c2d79fd --- /dev/null +++ b/problems/1441-build-an-array-with-stack-operations/README.md @@ -0,0 +1,64 @@ +

1441. Build an Array With Stack Operations

Medium


You are given an integer array target and an integer n.

+ +

You have an empty stack with the two following operations:

+ +
    +
  • "Push": pushes an integer to the top of the stack.
  • +
  • "Pop": removes the integer on the top of the stack.
  • +
+ +

You also have a stream of the integers in the range [1, n].

+ +

Use the two stack operations to make the numbers in the stack (from the bottom to the top) equal to target. You should follow the following rules:

+ +
    +
  • If the stream of the integers is not empty, pick the next integer from the stream and push it to the top of the stack.
  • +
  • If the stack is not empty, pop the integer at the top of the stack.
  • +
  • If, at any moment, the elements in the stack (from the bottom to the top) are equal to target, do not read new integers from the stream and do not do more operations on the stack.
  • +
+ +

Return the stack operations needed to build target following the mentioned rules. If there are multiple valid answers, return any of them.

+ +

 

+

Example 1:

+ +
Input: target = [1,3], n = 3
+Output: ["Push","Push","Pop","Push"]
+Explanation: Initially the stack s is empty. The last element is the top of the stack.
+Read 1 from the stream and push it to the stack. s = [1].
+Read 2 from the stream and push it to the stack. s = [1,2].
+Pop the integer on the top of the stack. s = [1].
+Read 3 from the stream and push it to the stack. s = [1,3].
+
+ +

Example 2:

+ +
Input: target = [1,2,3], n = 3
+Output: ["Push","Push","Push"]
+Explanation: Initially the stack s is empty. The last element is the top of the stack.
+Read 1 from the stream and push it to the stack. s = [1].
+Read 2 from the stream and push it to the stack. s = [1,2].
+Read 3 from the stream and push it to the stack. s = [1,2,3].
+
+ +

Example 3:

+ +
Input: target = [1,2], n = 4
+Output: ["Push","Push"]
+Explanation: Initially the stack s is empty. The last element is the top of the stack.
+Read 1 from the stream and push it to the stack. s = [1].
+Read 2 from the stream and push it to the stack. s = [1,2].
+Since the stack (from the bottom to the top) is equal to target, we stop the stack operations.
+The answers that read integer 3 from the stream are not accepted.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= target.length <= 100
  • +
  • 1 <= n <= 100
  • +
  • 1 <= target[i] <= n
  • +
  • target is strictly increasing.
  • +
+
\ No newline at end of file diff --git a/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/1442-count-triplets-that-can-form-two-arrays-of-equal-xor.py b/problems/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/1442-count-triplets-that-can-form-two-arrays-of-equal-xor.py similarity index 100% rename from 1442-count-triplets-that-can-form-two-arrays-of-equal-xor/1442-count-triplets-that-can-form-two-arrays-of-equal-xor.py rename to problems/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/1442-count-triplets-that-can-form-two-arrays-of-equal-xor.py diff --git a/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/NOTES.md b/problems/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/NOTES.md similarity index 100% rename from 1442-count-triplets-that-can-form-two-arrays-of-equal-xor/NOTES.md rename to problems/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/NOTES.md diff --git a/problems/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/README.md b/problems/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/README.md new file mode 100644 index 000000000..5a85fce74 --- /dev/null +++ b/problems/1442-count-triplets-that-can-form-two-arrays-of-equal-xor/README.md @@ -0,0 +1,37 @@ +

1442. Count Triplets That Can Form Two Arrays of Equal XOR

Medium


Given an array of integers arr.

+ +

We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).

+ +

Let's define a and b as follows:

+ +
    +
  • a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
  • +
  • b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
  • +
+ +

Note that ^ denotes the bitwise-xor operation.

+ +

Return the number of triplets (i, j and k) Where a == b.

+ +

 

+

Example 1:

+ +
Input: arr = [2,3,1,6,7]
+Output: 4
+Explanation: The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)
+
+ +

Example 2:

+ +
Input: arr = [1,1,1,1,1]
+Output: 10
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 300
  • +
  • 1 <= arr[i] <= 108
  • +
+
\ No newline at end of file diff --git a/1457-pseudo-palindromic-paths-in-a-binary-tree/1457-pseudo-palindromic-paths-in-a-binary-tree.py b/problems/1457-pseudo-palindromic-paths-in-a-binary-tree/1457-pseudo-palindromic-paths-in-a-binary-tree.py similarity index 100% rename from 1457-pseudo-palindromic-paths-in-a-binary-tree/1457-pseudo-palindromic-paths-in-a-binary-tree.py rename to problems/1457-pseudo-palindromic-paths-in-a-binary-tree/1457-pseudo-palindromic-paths-in-a-binary-tree.py diff --git a/1457-pseudo-palindromic-paths-in-a-binary-tree/NOTES.md b/problems/1457-pseudo-palindromic-paths-in-a-binary-tree/NOTES.md similarity index 100% rename from 1457-pseudo-palindromic-paths-in-a-binary-tree/NOTES.md rename to problems/1457-pseudo-palindromic-paths-in-a-binary-tree/NOTES.md diff --git a/problems/1457-pseudo-palindromic-paths-in-a-binary-tree/README.md b/problems/1457-pseudo-palindromic-paths-in-a-binary-tree/README.md new file mode 100644 index 000000000..746fb2595 --- /dev/null +++ b/problems/1457-pseudo-palindromic-paths-in-a-binary-tree/README.md @@ -0,0 +1,37 @@ +

1457. Pseudo-Palindromic Paths in a Binary Tree

Medium


Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome.

+ +

Return the number of pseudo-palindromic paths going from the root node to leaf nodes.

+ +

 

+

Example 1:

+ +

+ +
Input: root = [2,3,1,3,1,null,1]
+Output: 2 
+Explanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the red path [2,3,3], the green path [2,1,1], and the path [2,3,1]. Among these paths only red path and green path are pseudo-palindromic paths since the red path [2,3,3] can be rearranged in [3,2,3] (palindrome) and the green path [2,1,1] can be rearranged in [1,2,1] (palindrome).
+
+ +

Example 2:

+ +

+ +
Input: root = [2,1,1,1,3,null,null,null,null,null,1]
+Output: 1 
+Explanation: The figure above represents the given binary tree. There are three paths going from the root node to leaf nodes: the green path [2,1,1], the path [2,1,3,1], and the path [2,1]. Among these paths only the green path is pseudo-palindromic since [2,1,1] can be rearranged in [1,2,1] (palindrome).
+
+ +

Example 3:

+ +
Input: root = [9]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 105].
  • +
  • 1 <= Node.val <= 9
  • +
+
\ No newline at end of file diff --git a/1458-max-dot-product-of-two-subsequences/1458-max-dot-product-of-two-subsequences.py b/problems/1458-max-dot-product-of-two-subsequences/1458-max-dot-product-of-two-subsequences.py similarity index 100% rename from 1458-max-dot-product-of-two-subsequences/1458-max-dot-product-of-two-subsequences.py rename to problems/1458-max-dot-product-of-two-subsequences/1458-max-dot-product-of-two-subsequences.py diff --git a/1458-max-dot-product-of-two-subsequences/NOTES.md b/problems/1458-max-dot-product-of-two-subsequences/NOTES.md similarity index 100% rename from 1458-max-dot-product-of-two-subsequences/NOTES.md rename to problems/1458-max-dot-product-of-two-subsequences/NOTES.md diff --git a/problems/1458-max-dot-product-of-two-subsequences/README.md b/problems/1458-max-dot-product-of-two-subsequences/README.md new file mode 100644 index 000000000..d2dce7b9a --- /dev/null +++ b/problems/1458-max-dot-product-of-two-subsequences/README.md @@ -0,0 +1,36 @@ +

1458. Max Dot Product of Two Subsequences

Hard


Given two arrays nums1 and nums2.

+ +

Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.

+ +

A subsequence of a array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, [2,3,5] is a subsequence of [1,2,3,4,5] while [1,5,3] is not).

+ +

 

+

Example 1:

+ +
Input: nums1 = [2,1,-2,5], nums2 = [3,0,-6]
+Output: 18
+Explanation: Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.
+Their dot product is (2*3 + (-2)*(-6)) = 18.
+ +

Example 2:

+ +
Input: nums1 = [3,-2], nums2 = [2,-6,7]
+Output: 21
+Explanation: Take subsequence [3] from nums1 and subsequence [7] from nums2.
+Their dot product is (3*7) = 21.
+ +

Example 3:

+ +
Input: nums1 = [-1,-1], nums2 = [1,1]
+Output: -1
+Explanation: Take subsequence [-1] from nums1 and subsequence [1] from nums2.
+Their dot product is -1.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums1.length, nums2.length <= 500
  • +
  • -1000 <= nums1[i], nums2[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/1460-make-two-arrays-equal-by-reversing-subarrays/1460-make-two-arrays-equal-by-reversing-subarrays.py b/problems/1460-make-two-arrays-equal-by-reversing-subarrays/1460-make-two-arrays-equal-by-reversing-subarrays.py similarity index 100% rename from 1460-make-two-arrays-equal-by-reversing-subarrays/1460-make-two-arrays-equal-by-reversing-subarrays.py rename to problems/1460-make-two-arrays-equal-by-reversing-subarrays/1460-make-two-arrays-equal-by-reversing-subarrays.py diff --git a/1460-make-two-arrays-equal-by-reversing-subarrays/NOTES.md b/problems/1460-make-two-arrays-equal-by-reversing-subarrays/NOTES.md similarity index 100% rename from 1460-make-two-arrays-equal-by-reversing-subarrays/NOTES.md rename to problems/1460-make-two-arrays-equal-by-reversing-subarrays/NOTES.md diff --git a/problems/1460-make-two-arrays-equal-by-reversing-subarrays/README.md b/problems/1460-make-two-arrays-equal-by-reversing-subarrays/README.md new file mode 100644 index 000000000..ff4aae0e3 --- /dev/null +++ b/problems/1460-make-two-arrays-equal-by-reversing-subarrays/README.md @@ -0,0 +1,40 @@ +

1460. Make Two Arrays Equal by Reversing Subarrays

Easy


You are given two integer arrays of equal length target and arr. In one step, you can select any non-empty subarray of arr and reverse it. You are allowed to make any number of steps.

+ +

Return true if you can make arr equal to target or false otherwise.

+ +

 

+

Example 1:

+ +
Input: target = [1,2,3,4], arr = [2,4,1,3]
+Output: true
+Explanation: You can follow the next steps to convert arr to target:
+1- Reverse subarray [2,4,1], arr becomes [1,4,2,3]
+2- Reverse subarray [4,2], arr becomes [1,2,4,3]
+3- Reverse subarray [4,3], arr becomes [1,2,3,4]
+There are multiple ways to convert arr to target, this is not the only way to do so.
+
+ +

Example 2:

+ +
Input: target = [7], arr = [7]
+Output: true
+Explanation: arr is equal to target without any reverses.
+
+ +

Example 3:

+ +
Input: target = [3,7,9], arr = [3,7,11]
+Output: false
+Explanation: arr does not have value 9 and it can never be converted to target.
+
+ +

 

+

Constraints:

+ +
    +
  • target.length == arr.length
  • +
  • 1 <= target.length <= 1000
  • +
  • 1 <= target[i] <= 1000
  • +
  • 1 <= arr[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/1463-cherry-pickup-ii/1463-cherry-pickup-ii.py b/problems/1463-cherry-pickup-ii/1463-cherry-pickup-ii.py similarity index 100% rename from 1463-cherry-pickup-ii/1463-cherry-pickup-ii.py rename to problems/1463-cherry-pickup-ii/1463-cherry-pickup-ii.py diff --git a/1463-cherry-pickup-ii/NOTES.md b/problems/1463-cherry-pickup-ii/NOTES.md similarity index 100% rename from 1463-cherry-pickup-ii/NOTES.md rename to problems/1463-cherry-pickup-ii/NOTES.md diff --git a/1464-maximum-product-of-two-elements-in-an-array/1464-maximum-product-of-two-elements-in-an-array.py b/problems/1464-maximum-product-of-two-elements-in-an-array/1464-maximum-product-of-two-elements-in-an-array.py similarity index 100% rename from 1464-maximum-product-of-two-elements-in-an-array/1464-maximum-product-of-two-elements-in-an-array.py rename to problems/1464-maximum-product-of-two-elements-in-an-array/1464-maximum-product-of-two-elements-in-an-array.py diff --git a/1464-maximum-product-of-two-elements-in-an-array/NOTES.md b/problems/1464-maximum-product-of-two-elements-in-an-array/NOTES.md similarity index 100% rename from 1464-maximum-product-of-two-elements-in-an-array/NOTES.md rename to problems/1464-maximum-product-of-two-elements-in-an-array/NOTES.md diff --git a/problems/1464-maximum-product-of-two-elements-in-an-array/README.md b/problems/1464-maximum-product-of-two-elements-in-an-array/README.md new file mode 100644 index 000000000..c3561d41a --- /dev/null +++ b/problems/1464-maximum-product-of-two-elements-in-an-array/README.md @@ -0,0 +1,30 @@ +

1464. Maximum Product of Two Elements in an Array

Easy


Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1). +

 

+

Example 1:

+ +
Input: nums = [3,4,5,2]
+Output: 12 
+Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)*(nums[2]-1) = (4-1)*(5-1) = 3*4 = 12. 
+
+ +

Example 2:

+ +
Input: nums = [1,5,4,5]
+Output: 16
+Explanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16.
+
+ +

Example 3:

+ +
Input: nums = [3,7]
+Output: 12
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 500
  • +
  • 1 <= nums[i] <= 10^3
  • +
+
\ No newline at end of file diff --git a/1469-find-all-the-lonely-nodes/1469-find-all-the-lonely-nodes.py b/problems/1469-find-all-the-lonely-nodes/1469-find-all-the-lonely-nodes.py similarity index 100% rename from 1469-find-all-the-lonely-nodes/1469-find-all-the-lonely-nodes.py rename to problems/1469-find-all-the-lonely-nodes/1469-find-all-the-lonely-nodes.py diff --git a/1469-find-all-the-lonely-nodes/NOTES.md b/problems/1469-find-all-the-lonely-nodes/NOTES.md similarity index 100% rename from 1469-find-all-the-lonely-nodes/NOTES.md rename to problems/1469-find-all-the-lonely-nodes/NOTES.md diff --git a/problems/1469-find-all-the-lonely-nodes/README.md b/problems/1469-find-all-the-lonely-nodes/README.md new file mode 100644 index 000000000..834d063d8 --- /dev/null +++ b/problems/1469-find-all-the-lonely-nodes/README.md @@ -0,0 +1,39 @@ +

1469. Find All The Lonely Nodes

Easy


In a binary tree, a lonely node is a node that is the only child of its parent node. The root of the tree is not lonely because it does not have a parent node.

+ +

Given the root of a binary tree, return an array containing the values of all lonely nodes in the tree. Return the list in any order.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,null,4]
+Output: [4]
+Explanation: Light blue node is the only lonely node.
+Node 1 is the root and is not lonely.
+Nodes 2 and 3 have the same parent and are not lonely.
+
+ +

Example 2:

+ +
Input: root = [7,1,4,6,null,5,3,null,null,null,null,null,2]
+Output: [6,2]
+Explanation: Light blue nodes are lonely nodes.
+Please remember that order doesn't matter, [2,6] is also an acceptable answer.
+
+ +

Example 3:

+ +

+Input: root = [11,99,88,77,null,null,66,55,null,null,44,33,null,null,22]
+Output: [77,55,33,66,44,22]
+Explanation: Nodes 99 and 88 share the same parent. Node 11 is the root.
+All other nodes are lonely.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 1000].
  • +
  • 1 <= Node.val <= 106
  • +
+
\ No newline at end of file diff --git a/1470-shuffle-the-array/1470-shuffle-the-array.py b/problems/1470-shuffle-the-array/1470-shuffle-the-array.py similarity index 100% rename from 1470-shuffle-the-array/1470-shuffle-the-array.py rename to problems/1470-shuffle-the-array/1470-shuffle-the-array.py diff --git a/1470-shuffle-the-array/NOTES.md b/problems/1470-shuffle-the-array/NOTES.md similarity index 100% rename from 1470-shuffle-the-array/NOTES.md rename to problems/1470-shuffle-the-array/NOTES.md diff --git a/problems/1470-shuffle-the-array/README.md b/problems/1470-shuffle-the-array/README.md new file mode 100644 index 000000000..49c3eae99 --- /dev/null +++ b/problems/1470-shuffle-the-array/README.md @@ -0,0 +1,32 @@ +

1470. Shuffle the Array

Easy


Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].

+ +

Return the array in the form [x1,y1,x2,y2,...,xn,yn].

+ +

 

+

Example 1:

+ +
Input: nums = [2,5,1,3,4,7], n = 3
+Output: [2,3,5,4,1,7] 
+Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7].
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,4,4,3,2,1], n = 4
+Output: [1,4,2,3,3,2,4,1]
+
+ +

Example 3:

+ +
Input: nums = [1,1,2,2], n = 2
+Output: [1,2,1,2]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 500
  • +
  • nums.length == 2n
  • +
  • 1 <= nums[i] <= 10^3
  • +
\ No newline at end of file diff --git a/1481-least-number-of-unique-integers-after-k-removals/1481-least-number-of-unique-integers-after-k-removals.py b/problems/1481-least-number-of-unique-integers-after-k-removals/1481-least-number-of-unique-integers-after-k-removals.py similarity index 100% rename from 1481-least-number-of-unique-integers-after-k-removals/1481-least-number-of-unique-integers-after-k-removals.py rename to problems/1481-least-number-of-unique-integers-after-k-removals/1481-least-number-of-unique-integers-after-k-removals.py diff --git a/1481-least-number-of-unique-integers-after-k-removals/NOTES.md b/problems/1481-least-number-of-unique-integers-after-k-removals/NOTES.md similarity index 100% rename from 1481-least-number-of-unique-integers-after-k-removals/NOTES.md rename to problems/1481-least-number-of-unique-integers-after-k-removals/NOTES.md diff --git a/problems/1481-least-number-of-unique-integers-after-k-removals/README.md b/problems/1481-least-number-of-unique-integers-after-k-removals/README.md new file mode 100644 index 000000000..a8ace42dd --- /dev/null +++ b/problems/1481-least-number-of-unique-integers-after-k-removals/README.md @@ -0,0 +1,26 @@ +

1481. Least Number of Unique Integers after K Removals

Medium


Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements.

+ +
    +
+ +

 

+

Example 1:

+ +
Input: arr = [5,5,4], k = 1
+Output: 1
+Explanation: Remove the single 4, only 5 is left.
+
+Example 2: + +
Input: arr = [4,3,1,1,3,3,2], k = 3
+Output: 2
+Explanation: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 10^5
  • +
  • 1 <= arr[i] <= 10^9
  • +
  • 0 <= k <= arr.length
  • +
\ No newline at end of file diff --git a/1482-minimum-number-of-days-to-make-m-bouquets/1482-minimum-number-of-days-to-make-m-bouquets.py b/problems/1482-minimum-number-of-days-to-make-m-bouquets/1482-minimum-number-of-days-to-make-m-bouquets.py similarity index 100% rename from 1482-minimum-number-of-days-to-make-m-bouquets/1482-minimum-number-of-days-to-make-m-bouquets.py rename to problems/1482-minimum-number-of-days-to-make-m-bouquets/1482-minimum-number-of-days-to-make-m-bouquets.py diff --git a/1482-minimum-number-of-days-to-make-m-bouquets/NOTES.md b/problems/1482-minimum-number-of-days-to-make-m-bouquets/NOTES.md similarity index 100% rename from 1482-minimum-number-of-days-to-make-m-bouquets/NOTES.md rename to problems/1482-minimum-number-of-days-to-make-m-bouquets/NOTES.md diff --git a/problems/1482-minimum-number-of-days-to-make-m-bouquets/README.md b/problems/1482-minimum-number-of-days-to-make-m-bouquets/README.md new file mode 100644 index 000000000..5d2527dff --- /dev/null +++ b/problems/1482-minimum-number-of-days-to-make-m-bouquets/README.md @@ -0,0 +1,50 @@ +

1482. Minimum Number of Days to Make m Bouquets

Medium


You are given an integer array bloomDay, an integer m and an integer k.

+ +

You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.

+ +

The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.

+ +

Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.

+ +

 

+

Example 1:

+ +
Input: bloomDay = [1,10,3,10,2], m = 3, k = 1
+Output: 3
+Explanation: Let us see what happened in the first three days. x means flower bloomed and _ means flower did not bloom in the garden.
+We need 3 bouquets each should contain 1 flower.
+After day 1: [x, _, _, _, _]   // we can only make one bouquet.
+After day 2: [x, _, _, _, x]   // we can only make two bouquets.
+After day 3: [x, _, x, _, x]   // we can make 3 bouquets. The answer is 3.
+
+ +

Example 2:

+ +
Input: bloomDay = [1,10,3,10,2], m = 3, k = 2
+Output: -1
+Explanation: We need 3 bouquets each has 2 flowers, that means we need 6 flowers. We only have 5 flowers so it is impossible to get the needed bouquets and we return -1.
+
+ +

Example 3:

+ +
Input: bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3
+Output: 12
+Explanation: We need 2 bouquets each should have 3 flowers.
+Here is the garden after the 7 and 12 days:
+After day 7: [x, x, x, x, _, x, x]
+We can make one bouquet of the first three flowers that bloomed. We cannot make another bouquet from the last three flowers that bloomed because they are not adjacent.
+After day 12: [x, x, x, x, x, x, x]
+It is obvious that we can make two bouquets in different ways.
+
+ +

 

+

Constraints:

+ +
    +
  • bloomDay.length == n
  • +
  • 1 <= n <= 105
  • +
  • 1 <= bloomDay[i] <= 109
  • +
  • 1 <= m <= 106
  • +
  • 1 <= k <= n
  • +
+
\ No newline at end of file diff --git a/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.py b/problems/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.py similarity index 100% rename from 1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.py rename to problems/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.py diff --git a/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/NOTES.md b/problems/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/NOTES.md similarity index 100% rename from 1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/NOTES.md rename to problems/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/NOTES.md diff --git a/problems/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/README.md b/problems/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/README.md new file mode 100644 index 000000000..e996e3ee8 --- /dev/null +++ b/problems/1489-find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/README.md @@ -0,0 +1,41 @@ +

1489. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree

Hard


Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minimum spanning tree (MST) is a subset of the graph's edges that connects all vertices without cycles and with the minimum possible total edge weight.

+ +

Find all the critical and pseudo-critical edges in the given graph's minimum spanning tree (MST). An MST edge whose deletion from the graph would cause the MST weight to increase is called a critical edge. On the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.

+ +

Note that you can return the indices of the edges in any order.

+ +

 

+

Example 1:

+ +

+ +
Input: n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]
+Output: [[0,1],[2,3,4,5]]
+Explanation: The figure above describes the graph.
+The following figure shows all the possible MSTs:
+
+Notice that the two edges 0 and 1 appear in all MSTs, therefore they are critical edges, so we return them in the first list of the output.
+The edges 2, 3, 4, and 5 are only part of some MSTs, therefore they are considered pseudo-critical edges. We add them to the second list of the output.
+
+ +

Example 2:

+ +

+ +
Input: n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]
+Output: [[],[0,1,2,3]]
+Explanation: We can observe that since all 4 edges have equal weight, choosing any 3 edges from the given 4 will yield an MST. Therefore all 4 edges are pseudo-critical.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 100
  • +
  • 1 <= edges.length <= min(200, n * (n - 1) / 2)
  • +
  • edges[i].length == 3
  • +
  • 0 <= ai < bi < n
  • +
  • 1 <= weighti <= 1000
  • +
  • All pairs (ai, bi) are distinct.
  • +
+
\ No newline at end of file diff --git a/1496-path-crossing/1496-path-crossing.py b/problems/1496-path-crossing/1496-path-crossing.py similarity index 100% rename from 1496-path-crossing/1496-path-crossing.py rename to problems/1496-path-crossing/1496-path-crossing.py diff --git a/1496-path-crossing/NOTES.md b/problems/1496-path-crossing/NOTES.md similarity index 100% rename from 1496-path-crossing/NOTES.md rename to problems/1496-path-crossing/NOTES.md diff --git a/problems/1496-path-crossing/README.md b/problems/1496-path-crossing/README.md new file mode 100644 index 000000000..71c6c3b5c --- /dev/null +++ b/problems/1496-path-crossing/README.md @@ -0,0 +1,26 @@ +

1496. Path Crossing

Easy


Given a string path, where path[i] = 'N', 'S', 'E' or 'W', each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path.

+ +

Return true if the path crosses itself at any point, that is, if at any time you are on a location you have previously visited. Return false otherwise.

+ +

 

+

Example 1:

+ +
Input: path = "NES"
+Output: false 
+Explanation: Notice that the path doesn't cross any point more than once.
+
+ +

Example 2:

+ +
Input: path = "NESWW"
+Output: true
+Explanation: Notice that the path visits the origin twice.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= path.length <= 104
  • +
  • path[i] is either 'N', 'S', 'E', or 'W'.
  • +
+
\ No newline at end of file diff --git a/1503-last-moment-before-all-ants-fall-out-of-a-plank/1503-last-moment-before-all-ants-fall-out-of-a-plank.py b/problems/1503-last-moment-before-all-ants-fall-out-of-a-plank/1503-last-moment-before-all-ants-fall-out-of-a-plank.py similarity index 100% rename from 1503-last-moment-before-all-ants-fall-out-of-a-plank/1503-last-moment-before-all-ants-fall-out-of-a-plank.py rename to problems/1503-last-moment-before-all-ants-fall-out-of-a-plank/1503-last-moment-before-all-ants-fall-out-of-a-plank.py diff --git a/1503-last-moment-before-all-ants-fall-out-of-a-plank/NOTES.md b/problems/1503-last-moment-before-all-ants-fall-out-of-a-plank/NOTES.md similarity index 100% rename from 1503-last-moment-before-all-ants-fall-out-of-a-plank/NOTES.md rename to problems/1503-last-moment-before-all-ants-fall-out-of-a-plank/NOTES.md diff --git a/problems/1503-last-moment-before-all-ants-fall-out-of-a-plank/README.md b/problems/1503-last-moment-before-all-ants-fall-out-of-a-plank/README.md new file mode 100644 index 000000000..0087fe01d --- /dev/null +++ b/problems/1503-last-moment-before-all-ants-fall-out-of-a-plank/README.md @@ -0,0 +1,48 @@ +

1503. Last Moment Before All Ants Fall Out of a Plank

Medium


We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with a speed of 1 unit per second. Some of the ants move to the left, the other move to the right.

+ +

When two ants moving in two different directions meet at some point, they change their directions and continue moving again. Assume changing directions does not take any additional time.

+ +

When an ant reaches one end of the plank at a time t, it falls out of the plank immediately.

+ +

Given an integer n and two integer arrays left and right, the positions of the ants moving to the left and the right, return the moment when the last ant(s) fall out of the plank.

+ +

 

+

Example 1:

+ +
Input: n = 4, left = [4,3], right = [0,1]
+Output: 4
+Explanation: In the image above:
+-The ant at index 0 is named A and going to the right.
+-The ant at index 1 is named B and going to the right.
+-The ant at index 3 is named C and going to the left.
+-The ant at index 4 is named D and going to the left.
+The last moment when an ant was on the plank is t = 4 seconds. After that, it falls immediately out of the plank. (i.e., We can say that at t = 4.0000000001, there are no ants on the plank).
+
+ +

Example 2:

+ +
Input: n = 7, left = [], right = [0,1,2,3,4,5,6,7]
+Output: 7
+Explanation: All ants are going to the right, the ant at index 0 needs 7 seconds to fall.
+
+ +

Example 3:

+ +
Input: n = 7, left = [0,1,2,3,4,5,6,7], right = []
+Output: 7
+Explanation: All ants are going to the left, the ant at index 7 needs 7 seconds to fall.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 104
  • +
  • 0 <= left.length <= n + 1
  • +
  • 0 <= left[i] <= n
  • +
  • 0 <= right.length <= n + 1
  • +
  • 0 <= right[i] <= n
  • +
  • 1 <= left.length + right.length <= n + 1
  • +
  • All values of left and right are unique, and each value can appear only in one of the two arrays.
  • +
+
\ No newline at end of file diff --git a/1508-range-sum-of-sorted-subarray-sums/1508-range-sum-of-sorted-subarray-sums.py b/problems/1508-range-sum-of-sorted-subarray-sums/1508-range-sum-of-sorted-subarray-sums.py similarity index 100% rename from 1508-range-sum-of-sorted-subarray-sums/1508-range-sum-of-sorted-subarray-sums.py rename to problems/1508-range-sum-of-sorted-subarray-sums/1508-range-sum-of-sorted-subarray-sums.py diff --git a/1508-range-sum-of-sorted-subarray-sums/NOTES.md b/problems/1508-range-sum-of-sorted-subarray-sums/NOTES.md similarity index 100% rename from 1508-range-sum-of-sorted-subarray-sums/NOTES.md rename to problems/1508-range-sum-of-sorted-subarray-sums/NOTES.md diff --git a/problems/1508-range-sum-of-sorted-subarray-sums/README.md b/problems/1508-range-sum-of-sorted-subarray-sums/README.md new file mode 100644 index 000000000..ac175361e --- /dev/null +++ b/problems/1508-range-sum-of-sorted-subarray-sums/README.md @@ -0,0 +1,35 @@ +

1508. Range Sum of Sorted Subarray Sums

Medium


You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.

+ +

Return the sum of the numbers from index left to index right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4], n = 4, left = 1, right = 5
+Output: 13 
+Explanation: All subarray sums are 1, 3, 6, 10, 2, 5, 9, 3, 7, 4. After sorting them in non-decreasing order we have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 1 to ri = 5 is 1 + 2 + 3 + 3 + 4 = 13. 
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,4], n = 4, left = 3, right = 4
+Output: 6
+Explanation: The given array is the same as example 1. We have the new array [1, 2, 3, 3, 4, 5, 6, 7, 9, 10]. The sum of the numbers from index le = 3 to ri = 4 is 3 + 3 = 6.
+
+ +

Example 3:

+ +
Input: nums = [1,2,3,4], n = 4, left = 1, right = 10
+Output: 50
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= nums.length <= 1000
  • +
  • 1 <= nums[i] <= 100
  • +
  • 1 <= left <= right <= n * (n + 1) / 2
  • +
+
\ No newline at end of file diff --git a/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.py b/problems/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.py similarity index 100% rename from 1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.py rename to problems/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves.py diff --git a/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/NOTES.md b/problems/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/NOTES.md similarity index 100% rename from 1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/NOTES.md rename to problems/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/NOTES.md diff --git a/problems/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/README.md b/problems/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/README.md new file mode 100644 index 000000000..ea8a7485a --- /dev/null +++ b/problems/1509-minimum-difference-between-largest-and-smallest-value-in-three-moves/README.md @@ -0,0 +1,48 @@ +

1509. Minimum Difference Between Largest and Smallest Value in Three Moves

Medium


You are given an integer array nums.

+ +

In one move, you can choose one element of nums and change it to any value.

+ +

Return the minimum difference between the largest and smallest value of nums after performing at most three moves.

+ +

 

+

Example 1:

+ +
Input: nums = [5,3,2,4]
+Output: 0
+Explanation: We can make at most 3 moves.
+In the first move, change 2 to 3. nums becomes [5,3,3,4].
+In the second move, change 4 to 3. nums becomes [5,3,3,3].
+In the third move, change 5 to 3. nums becomes [3,3,3,3].
+After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0.
+
+ +

Example 2:

+ +
Input: nums = [1,5,0,10,14]
+Output: 1
+Explanation: We can make at most 3 moves.
+In the first move, change 5 to 0. nums becomes [1,0,0,10,14].
+In the second move, change 10 to 0. nums becomes [1,0,0,0,14].
+In the third move, change 14 to 1. nums becomes [1,0,0,0,1].
+After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 1.
+It can be shown that there is no way to make the difference 0 in 3 moves.
+ +

Example 3:

+ +
Input: nums = [3,100,20]
+Output: 0
+Explanation: We can make at most 3 moves.
+In the first move, change 100 to 7. nums becomes [3,7,20].
+In the second move, change 20 to 7. nums becomes [3,7,7].
+In the third move, change 3 to 7. nums becomes [7,7,7].
+After performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/1512-number-of-good-pairs/1512-number-of-good-pairs.py b/problems/1512-number-of-good-pairs/1512-number-of-good-pairs.py similarity index 100% rename from 1512-number-of-good-pairs/1512-number-of-good-pairs.py rename to problems/1512-number-of-good-pairs/1512-number-of-good-pairs.py diff --git a/1512-number-of-good-pairs/NOTES.md b/problems/1512-number-of-good-pairs/NOTES.md similarity index 100% rename from 1512-number-of-good-pairs/NOTES.md rename to problems/1512-number-of-good-pairs/NOTES.md diff --git a/problems/1512-number-of-good-pairs/README.md b/problems/1512-number-of-good-pairs/README.md new file mode 100644 index 000000000..8cdeb85f7 --- /dev/null +++ b/problems/1512-number-of-good-pairs/README.md @@ -0,0 +1,33 @@ +

1512. Number of Good Pairs

Easy


Given an array of integers nums, return the number of good pairs.

+ +

A pair (i, j) is called good if nums[i] == nums[j] and i < j.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,1,1,3]
+Output: 4
+Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
+
+ +

Example 2:

+ +
Input: nums = [1,1,1,1]
+Output: 6
+Explanation: Each pair in the array are good.
+
+ +

Example 3:

+ +
Input: nums = [1,2,3]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 1 <= nums[i] <= 100
  • +
+
\ No newline at end of file diff --git a/1518-water-bottles/1518-water-bottles.py b/problems/1518-water-bottles/1518-water-bottles.py similarity index 100% rename from 1518-water-bottles/1518-water-bottles.py rename to problems/1518-water-bottles/1518-water-bottles.py diff --git a/1518-water-bottles/NOTES.md b/problems/1518-water-bottles/NOTES.md similarity index 100% rename from 1518-water-bottles/NOTES.md rename to problems/1518-water-bottles/NOTES.md diff --git a/problems/1518-water-bottles/README.md b/problems/1518-water-bottles/README.md new file mode 100644 index 000000000..cb5e9b9e2 --- /dev/null +++ b/problems/1518-water-bottles/README.md @@ -0,0 +1,31 @@ +

1518. Water Bottles

Easy


There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle.

+ +

The operation of drinking a full water bottle turns it into an empty bottle.

+ +

Given the two integers numBottles and numExchange, return the maximum number of water bottles you can drink.

+ +

 

+

Example 1:

+ +
Input: numBottles = 9, numExchange = 3
+Output: 13
+Explanation: You can exchange 3 empty bottles to get 1 full water bottle.
+Number of water bottles you can drink: 9 + 3 + 1 = 13.
+
+ +

Example 2:

+ +
Input: numBottles = 15, numExchange = 4
+Output: 19
+Explanation: You can exchange 4 empty bottles to get 1 full water bottle. 
+Number of water bottles you can drink: 15 + 3 + 1 = 19.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= numBottles <= 100
  • +
  • 2 <= numExchange <= 100
  • +
+
\ No newline at end of file diff --git a/1530-number-of-good-leaf-nodes-pairs/1530-number-of-good-leaf-nodes-pairs.py b/problems/1530-number-of-good-leaf-nodes-pairs/1530-number-of-good-leaf-nodes-pairs.py similarity index 100% rename from 1530-number-of-good-leaf-nodes-pairs/1530-number-of-good-leaf-nodes-pairs.py rename to problems/1530-number-of-good-leaf-nodes-pairs/1530-number-of-good-leaf-nodes-pairs.py diff --git a/1530-number-of-good-leaf-nodes-pairs/NOTES.md b/problems/1530-number-of-good-leaf-nodes-pairs/NOTES.md similarity index 100% rename from 1530-number-of-good-leaf-nodes-pairs/NOTES.md rename to problems/1530-number-of-good-leaf-nodes-pairs/NOTES.md diff --git a/problems/1530-number-of-good-leaf-nodes-pairs/README.md b/problems/1530-number-of-good-leaf-nodes-pairs/README.md new file mode 100644 index 000000000..23988e673 --- /dev/null +++ b/problems/1530-number-of-good-leaf-nodes-pairs/README.md @@ -0,0 +1,35 @@ +

1530. Number of Good Leaf Nodes Pairs

Medium


You are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance.

+ +

Return the number of good leaf node pairs in the tree.

+ +

 

+

Example 1:

+ +
Input: root = [1,2,3,null,4], distance = 3
+Output: 1
+Explanation: The leaf nodes of the tree are 3 and 4 and the length of the shortest path between them is 3. This is the only good pair.
+
+ +

Example 2:

+ +
Input: root = [1,2,3,4,5,6,7], distance = 3
+Output: 2
+Explanation: The good pairs are [4,5] and [6,7] with shortest path = 2. The pair [4,6] is not good because the length of ther shortest path between them is 4.
+
+ +

Example 3:

+ +
Input: root = [7,1,4,6,null,5,3,null,null,null,null,null,2], distance = 3
+Output: 1
+Explanation: The only good pair is [2,5].
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 210].
  • +
  • 1 <= Node.val <= 100
  • +
  • 1 <= distance <= 10
  • +
+
\ No newline at end of file diff --git a/1531-string-compression-ii/1531-string-compression-ii.py b/problems/1531-string-compression-ii/1531-string-compression-ii.py similarity index 100% rename from 1531-string-compression-ii/1531-string-compression-ii.py rename to problems/1531-string-compression-ii/1531-string-compression-ii.py diff --git a/1531-string-compression-ii/NOTES.md b/problems/1531-string-compression-ii/NOTES.md similarity index 100% rename from 1531-string-compression-ii/NOTES.md rename to problems/1531-string-compression-ii/NOTES.md diff --git a/problems/1531-string-compression-ii/README.md b/problems/1531-string-compression-ii/README.md new file mode 100644 index 000000000..74ed32f74 --- /dev/null +++ b/problems/1531-string-compression-ii/README.md @@ -0,0 +1,38 @@ +

1531. String Compression II

Hard


Run-length encoding is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters (length of the run). For example, to compress the string "aabccc" we replace "aa" by "a2" and replace "ccc" by "c3". Thus the compressed string becomes "a2bc3".

+ +

Notice that in this problem, we are not adding '1' after single characters.

+ +

Given a string s and an integer k. You need to delete at most k characters from s such that the run-length encoded version of s has minimum length.

+ +

Find the minimum length of the run-length encoded version of s after deleting at most k characters.

+ +

 

+

Example 1:

+ +
Input: s = "aaabcccd", k = 2
+Output: 4
+Explanation: Compressing s without deleting anything will give us "a3bc3d" of length 6. Deleting any of the characters 'a' or 'c' would at most decrease the length of the compressed string to 5, for instance delete 2 'a' then we will have s = "abcccd" which compressed is abc3d. Therefore, the optimal way is to delete 'b' and 'd', then the compressed version of s will be "a3c3" of length 4.
+ +

Example 2:

+ +
Input: s = "aabbaa", k = 2
+Output: 2
+Explanation: If we delete both 'b' characters, the resulting compressed string would be "a4" of length 2.
+
+ +

Example 3:

+ +
Input: s = "aaaaaaaaaaa", k = 0
+Output: 3
+Explanation: Since k is zero, we cannot delete anything. The compressed string is "a11" of length 3.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • 0 <= k <= s.length
  • +
  • s contains only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1535-find-the-winner-of-an-array-game/1535-find-the-winner-of-an-array-game.py b/problems/1535-find-the-winner-of-an-array-game/1535-find-the-winner-of-an-array-game.py similarity index 100% rename from 1535-find-the-winner-of-an-array-game/1535-find-the-winner-of-an-array-game.py rename to problems/1535-find-the-winner-of-an-array-game/1535-find-the-winner-of-an-array-game.py diff --git a/1535-find-the-winner-of-an-array-game/NOTES.md b/problems/1535-find-the-winner-of-an-array-game/NOTES.md similarity index 100% rename from 1535-find-the-winner-of-an-array-game/NOTES.md rename to problems/1535-find-the-winner-of-an-array-game/NOTES.md diff --git a/problems/1535-find-the-winner-of-an-array-game/README.md b/problems/1535-find-the-winner-of-an-array-game/README.md new file mode 100644 index 000000000..d3a4980ee --- /dev/null +++ b/problems/1535-find-the-winner-of-an-array-game/README.md @@ -0,0 +1,39 @@ +

1535. Find the Winner of an Array Game

Medium


Given an integer array arr of distinct integers and an integer k.

+ +

A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.

+ +

Return the integer which will win the game.

+ +

It is guaranteed that there will be a winner of the game.

+ +

 

+

Example 1:

+ +
Input: arr = [2,1,3,5,4,6,7], k = 2
+Output: 5
+Explanation: Let's see the rounds of the game:
+Round |       arr       | winner | win_count
+  1   | [2,1,3,5,4,6,7] | 2      | 1
+  2   | [2,3,5,4,6,7,1] | 3      | 1
+  3   | [3,5,4,6,7,1,2] | 5      | 1
+  4   | [5,4,6,7,1,2,3] | 5      | 2
+So we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.
+
+ +

Example 2:

+ +
Input: arr = [3,2,1], k = 10
+Output: 3
+Explanation: 3 will win the first 10 rounds consecutively.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= arr.length <= 105
  • +
  • 1 <= arr[i] <= 106
  • +
  • arr contains distinct integers.
  • +
  • 1 <= k <= 109
  • +
+
\ No newline at end of file diff --git a/1544-make-the-string-great/1544-make-the-string-great.py b/problems/1544-make-the-string-great/1544-make-the-string-great.py similarity index 100% rename from 1544-make-the-string-great/1544-make-the-string-great.py rename to problems/1544-make-the-string-great/1544-make-the-string-great.py diff --git a/1544-make-the-string-great/NOTES.md b/problems/1544-make-the-string-great/NOTES.md similarity index 100% rename from 1544-make-the-string-great/NOTES.md rename to problems/1544-make-the-string-great/NOTES.md diff --git a/problems/1544-make-the-string-great/README.md b/problems/1544-make-the-string-great/README.md new file mode 100644 index 000000000..4ce6592e2 --- /dev/null +++ b/problems/1544-make-the-string-great/README.md @@ -0,0 +1,46 @@ +

1544. Make The String Great

Easy


Given a string s of lower and upper case English letters.

+ +

A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:

+ +
    +
  • 0 <= i <= s.length - 2
  • +
  • s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa.
  • +
+ +

To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good.

+ +

Return the string after making it good. The answer is guaranteed to be unique under the given constraints.

+ +

Notice that an empty string is also good.

+ +

 

+

Example 1:

+ +
Input: s = "leEeetcode"
+Output: "leetcode"
+Explanation: In the first step, either you choose i = 1 or i = 2, both will result "leEeetcode" to be reduced to "leetcode".
+
+ +

Example 2:

+ +
Input: s = "abBAcC"
+Output: ""
+Explanation: We have many possible scenarios, and all lead to the same answer. For example:
+"abBAcC" --> "aAcC" --> "cC" --> ""
+"abBAcC" --> "abBA" --> "aA" --> ""
+
+ +

Example 3:

+ +
Input: s = "s"
+Output: "s"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s contains only lower and upper case English letters.
  • +
+
\ No newline at end of file diff --git a/1550-three-consecutive-odds/1550-three-consecutive-odds.py b/problems/1550-three-consecutive-odds/1550-three-consecutive-odds.py similarity index 100% rename from 1550-three-consecutive-odds/1550-three-consecutive-odds.py rename to problems/1550-three-consecutive-odds/1550-three-consecutive-odds.py diff --git a/problems/1550-three-consecutive-odds/README.md b/problems/1550-three-consecutive-odds/README.md new file mode 100644 index 000000000..6efb9b868 --- /dev/null +++ b/problems/1550-three-consecutive-odds/README.md @@ -0,0 +1,24 @@ +

1550. Three Consecutive Odds

Easy


Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false. +

 

+

Example 1:

+ +
Input: arr = [2,6,4,1]
+Output: false
+Explanation: There are no three consecutive odds.
+
+ +

Example 2:

+ +
Input: arr = [1,2,34,3,4,5,7,23,12]
+Output: true
+Explanation: [5,7,23] are three consecutive odds.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 1000
  • +
  • 1 <= arr[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/1552-magnetic-force-between-two-balls/1552-magnetic-force-between-two-balls.py b/problems/1552-magnetic-force-between-two-balls/1552-magnetic-force-between-two-balls.py similarity index 100% rename from 1552-magnetic-force-between-two-balls/1552-magnetic-force-between-two-balls.py rename to problems/1552-magnetic-force-between-two-balls/1552-magnetic-force-between-two-balls.py diff --git a/1552-magnetic-force-between-two-balls/NOTES.md b/problems/1552-magnetic-force-between-two-balls/NOTES.md similarity index 100% rename from 1552-magnetic-force-between-two-balls/NOTES.md rename to problems/1552-magnetic-force-between-two-balls/NOTES.md diff --git a/problems/1552-magnetic-force-between-two-balls/README.md b/problems/1552-magnetic-force-between-two-balls/README.md new file mode 100644 index 000000000..eee52ed48 --- /dev/null +++ b/problems/1552-magnetic-force-between-two-balls/README.md @@ -0,0 +1,32 @@ +

1552. Magnetic Force Between Two Balls

Medium


In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.

+ +

Rick stated that magnetic force between two different balls at positions x and y is |x - y|.

+ +

Given the integer array position and the integer m. Return the required force.

+ +

 

+

Example 1:

+ +
Input: position = [1,2,3,4,7], m = 3
+Output: 3
+Explanation: Distributing the 3 balls into baskets 1, 4 and 7 will make the magnetic force between ball pairs [3, 3, 6]. The minimum magnetic force is 3. We cannot achieve a larger minimum magnetic force than 3.
+
+ +

Example 2:

+ +
Input: position = [5,4,3,2,1,1000000000], m = 2
+Output: 999999999
+Explanation: We can use baskets 1 and 1000000000.
+
+ +

 

+

Constraints:

+ +
    +
  • n == position.length
  • +
  • 2 <= n <= 105
  • +
  • 1 <= position[i] <= 109
  • +
  • All integers in position are distinct.
  • +
  • 2 <= m <= position.length
  • +
+
\ No newline at end of file diff --git a/1561-maximum-number-of-coins-you-can-get/1561-maximum-number-of-coins-you-can-get.py b/problems/1561-maximum-number-of-coins-you-can-get/1561-maximum-number-of-coins-you-can-get.py similarity index 100% rename from 1561-maximum-number-of-coins-you-can-get/1561-maximum-number-of-coins-you-can-get.py rename to problems/1561-maximum-number-of-coins-you-can-get/1561-maximum-number-of-coins-you-can-get.py diff --git a/1561-maximum-number-of-coins-you-can-get/NOTES.md b/problems/1561-maximum-number-of-coins-you-can-get/NOTES.md similarity index 100% rename from 1561-maximum-number-of-coins-you-can-get/NOTES.md rename to problems/1561-maximum-number-of-coins-you-can-get/NOTES.md diff --git a/problems/1561-maximum-number-of-coins-you-can-get/README.md b/problems/1561-maximum-number-of-coins-you-can-get/README.md new file mode 100644 index 000000000..0b632f7e6 --- /dev/null +++ b/problems/1561-maximum-number-of-coins-you-can-get/README.md @@ -0,0 +1,46 @@ +

1561. Maximum Number of Coins You Can Get

Medium


There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:

+ +
    +
  • In each step, you will choose any 3 piles of coins (not necessarily consecutive).
  • +
  • Of your choice, Alice will pick the pile with the maximum number of coins.
  • +
  • You will pick the next pile with the maximum number of coins.
  • +
  • Your friend Bob will pick the last pile.
  • +
  • Repeat until there are no more piles of coins.
  • +
+ +

Given an array of integers piles where piles[i] is the number of coins in the ith pile.

+ +

Return the maximum number of coins that you can have.

+ +

 

+

Example 1:

+ +
Input: piles = [2,4,1,2,7,8]
+Output: 9
+Explanation: Choose the triplet (2, 7, 8), Alice Pick the pile with 8 coins, you the pile with 7 coins and Bob the last one.
+Choose the triplet (1, 2, 4), Alice Pick the pile with 4 coins, you the pile with 2 coins and Bob the last one.
+The maximum number of coins which you can have are: 7 + 2 = 9.
+On the other hand if we choose this arrangement (1, 2, 8), (2, 4, 7) you only get 2 + 4 = 6 coins which is not optimal.
+
+ +

Example 2:

+ +
Input: piles = [2,4,5]
+Output: 4
+
+ +

Example 3:

+ +
Input: piles = [9,8,7,6,5,1,2,3,4]
+Output: 18
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= piles.length <= 105
  • +
  • piles.length % 3 == 0
  • +
  • 1 <= piles[i] <= 104
  • +
+
\ No newline at end of file diff --git a/1568-minimum-number-of-days-to-disconnect-island/1568-minimum-number-of-days-to-disconnect-island.py b/problems/1568-minimum-number-of-days-to-disconnect-island/1568-minimum-number-of-days-to-disconnect-island.py similarity index 100% rename from 1568-minimum-number-of-days-to-disconnect-island/1568-minimum-number-of-days-to-disconnect-island.py rename to problems/1568-minimum-number-of-days-to-disconnect-island/1568-minimum-number-of-days-to-disconnect-island.py diff --git a/1568-minimum-number-of-days-to-disconnect-island/NOTES.md b/problems/1568-minimum-number-of-days-to-disconnect-island/NOTES.md similarity index 100% rename from 1568-minimum-number-of-days-to-disconnect-island/NOTES.md rename to problems/1568-minimum-number-of-days-to-disconnect-island/NOTES.md diff --git a/problems/1568-minimum-number-of-days-to-disconnect-island/README.md b/problems/1568-minimum-number-of-days-to-disconnect-island/README.md new file mode 100644 index 000000000..652dcb78c --- /dev/null +++ b/problems/1568-minimum-number-of-days-to-disconnect-island/README.md @@ -0,0 +1,35 @@ +

1568. Minimum Number of Days to Disconnect Island

Hard


You are given an m x n binary grid grid where 1 represents land and 0 represents water. An island is a maximal 4-directionally (horizontal or vertical) connected group of 1's.

+ +

The grid is said to be connected if we have exactly one island, otherwise is said disconnected.

+ +

In one day, we are allowed to change any single land cell (1) into a water cell (0).

+ +

Return the minimum number of days to disconnect the grid.

+ +

 

+

Example 1:

+ +
Input: grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]
+
+Output: 2
+Explanation: We need at least 2 days to get a disconnected grid.
+Change land grid[1][1] and grid[0][2] to water and get 2 disconnected island.
+
+ +

Example 2:

+ +
Input: grid = [[1,1]]
+Output: 2
+Explanation: Grid of full water is also disconnected ([[1,1]] -> [[0,0]]), 0 islands.
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 30
  • +
  • grid[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/1578-minimum-time-to-make-rope-colorful/1578-minimum-time-to-make-rope-colorful.py b/problems/1578-minimum-time-to-make-rope-colorful/1578-minimum-time-to-make-rope-colorful.py similarity index 100% rename from 1578-minimum-time-to-make-rope-colorful/1578-minimum-time-to-make-rope-colorful.py rename to problems/1578-minimum-time-to-make-rope-colorful/1578-minimum-time-to-make-rope-colorful.py diff --git a/1578-minimum-time-to-make-rope-colorful/NOTES.md b/problems/1578-minimum-time-to-make-rope-colorful/NOTES.md similarity index 100% rename from 1578-minimum-time-to-make-rope-colorful/NOTES.md rename to problems/1578-minimum-time-to-make-rope-colorful/NOTES.md diff --git a/problems/1578-minimum-time-to-make-rope-colorful/README.md b/problems/1578-minimum-time-to-make-rope-colorful/README.md new file mode 100644 index 000000000..6e5e854ae --- /dev/null +++ b/problems/1578-minimum-time-to-make-rope-colorful/README.md @@ -0,0 +1,40 @@ +

1578. Minimum Time to Make Rope Colorful

Medium


Alice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon.

+ +

Alice wants the rope to be colorful. She does not want two consecutive balloons to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it colorful. You are given a 0-indexed integer array neededTime where neededTime[i] is the time (in seconds) that Bob needs to remove the ith balloon from the rope.

+ +

Return the minimum time Bob needs to make the rope colorful.

+ +

 

+

Example 1:

+ +
Input: colors = "abaac", neededTime = [1,2,3,4,5]
+Output: 3
+Explanation: In the above image, 'a' is blue, 'b' is red, and 'c' is green.
+Bob can remove the blue balloon at index 2. This takes 3 seconds.
+There are no longer two consecutive balloons of the same color. Total time = 3.
+ +

Example 2:

+ +
Input: colors = "abc", neededTime = [1,2,3]
+Output: 0
+Explanation: The rope is already colorful. Bob does not need to remove any balloons from the rope.
+
+ +

Example 3:

+ +
Input: colors = "aabaa", neededTime = [1,2,3,4,1]
+Output: 2
+Explanation: Bob will remove the ballons at indices 0 and 4. Each ballon takes 1 second to remove.
+There are no longer two consecutive balloons of the same color. Total time = 1 + 1 = 2.
+
+ +

 

+

Constraints:

+ +
    +
  • n == colors.length == neededTime.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= neededTime[i] <= 104
  • +
  • colors contains only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable.py b/problems/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable.py similarity index 100% rename from 1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable.py rename to problems/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable.py diff --git a/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/NOTES.md b/problems/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/NOTES.md similarity index 100% rename from 1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/NOTES.md rename to problems/1579-remove-max-number-of-edges-to-keep-graph-fully-traversable/NOTES.md diff --git a/1580-put-boxes-into-the-warehouse-ii/1580-put-boxes-into-the-warehouse-ii.py b/problems/1580-put-boxes-into-the-warehouse-ii/1580-put-boxes-into-the-warehouse-ii.py similarity index 100% rename from 1580-put-boxes-into-the-warehouse-ii/1580-put-boxes-into-the-warehouse-ii.py rename to problems/1580-put-boxes-into-the-warehouse-ii/1580-put-boxes-into-the-warehouse-ii.py diff --git a/1580-put-boxes-into-the-warehouse-ii/NOTES.md b/problems/1580-put-boxes-into-the-warehouse-ii/NOTES.md similarity index 100% rename from 1580-put-boxes-into-the-warehouse-ii/NOTES.md rename to problems/1580-put-boxes-into-the-warehouse-ii/NOTES.md diff --git a/problems/1580-put-boxes-into-the-warehouse-ii/README.md b/problems/1580-put-boxes-into-the-warehouse-ii/README.md new file mode 100644 index 000000000..421eefd6a --- /dev/null +++ b/problems/1580-put-boxes-into-the-warehouse-ii/README.md @@ -0,0 +1,47 @@ +

1580. Put Boxes Into the Warehouse II

Medium


You are given two arrays of positive integers, boxes and warehouse, representing the heights of some boxes of unit width and the heights of n rooms in a warehouse respectively. The warehouse's rooms are labeled from 0 to n - 1 from left to right where warehouse[i] (0-indexed) is the height of the ith room.

+ +

Boxes are put into the warehouse by the following rules:

+ +
    +
  • Boxes cannot be stacked.
  • +
  • You can rearrange the insertion order of the boxes.
  • +
  • Boxes can be pushed into the warehouse from either side (left or right)
  • +
  • If the height of some room in the warehouse is less than the height of a box, then that box and all other boxes behind it will be stopped before that room.
  • +
+ +

Return the maximum number of boxes you can put into the warehouse.

+ +

 

+

Example 1:

+ +
Input: boxes = [1,2,2,3,4], warehouse = [3,4,1,2]
+Output: 4
+Explanation:
+
+We can store the boxes in the following order:
+1- Put the yellow box in room 2 from either the left or right side.
+2- Put the orange box in room 3 from the right side.
+3- Put the green box in room 1 from the left side.
+4- Put the red box in room 0 from the left side.
+Notice that there are other valid ways to put 4 boxes such as swapping the red and green boxes or the red and orange boxes.
+
+ +

Example 2:

+ +
Input: boxes = [3,5,5,2], warehouse = [2,1,3,4,5]
+Output: 3
+Explanation:
+
+It is not possible to put the two boxes of height 5 in the warehouse since there's only 1 room of height >= 5.
+Other valid solutions are to put the green box in room 2 or to put the orange box first in room 2 before putting the green and red boxes.
+
+ +

 

+

Constraints:

+ +
    +
  • n == warehouse.length
  • +
  • 1 <= boxes.length, warehouse.length <= 105
  • +
  • 1 <= boxes[i], warehouse[i] <= 109
  • +
+
\ No newline at end of file diff --git a/1582-special-positions-in-a-binary-matrix/1582-special-positions-in-a-binary-matrix.py b/problems/1582-special-positions-in-a-binary-matrix/1582-special-positions-in-a-binary-matrix.py similarity index 100% rename from 1582-special-positions-in-a-binary-matrix/1582-special-positions-in-a-binary-matrix.py rename to problems/1582-special-positions-in-a-binary-matrix/1582-special-positions-in-a-binary-matrix.py diff --git a/1582-special-positions-in-a-binary-matrix/NOTES.md b/problems/1582-special-positions-in-a-binary-matrix/NOTES.md similarity index 100% rename from 1582-special-positions-in-a-binary-matrix/NOTES.md rename to problems/1582-special-positions-in-a-binary-matrix/NOTES.md diff --git a/problems/1582-special-positions-in-a-binary-matrix/README.md b/problems/1582-special-positions-in-a-binary-matrix/README.md new file mode 100644 index 000000000..c973d9144 --- /dev/null +++ b/problems/1582-special-positions-in-a-binary-matrix/README.md @@ -0,0 +1,29 @@ +

1582. Special Positions in a Binary Matrix

Easy


Given an m x n binary matrix mat, return the number of special positions in mat.

+ +

A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed).

+ +

 

+

Example 1:

+ +
Input: mat = [[1,0,0],[0,0,1],[1,0,0]]
+Output: 1
+Explanation: (1, 2) is a special position because mat[1][2] == 1 and all other elements in row 1 and column 2 are 0.
+
+ +

Example 2:

+ +
Input: mat = [[1,0,0],[0,1,0],[0,0,1]]
+Output: 3
+Explanation: (0, 0), (1, 1) and (2, 2) are special positions.
+
+ +

 

+

Constraints:

+ +
    +
  • m == mat.length
  • +
  • n == mat[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • mat[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/1584-min-cost-to-connect-all-points/1584-min-cost-to-connect-all-points.py b/problems/1584-min-cost-to-connect-all-points/1584-min-cost-to-connect-all-points.py similarity index 100% rename from 1584-min-cost-to-connect-all-points/1584-min-cost-to-connect-all-points.py rename to problems/1584-min-cost-to-connect-all-points/1584-min-cost-to-connect-all-points.py diff --git a/1584-min-cost-to-connect-all-points/NOTES.md b/problems/1584-min-cost-to-connect-all-points/NOTES.md similarity index 100% rename from 1584-min-cost-to-connect-all-points/NOTES.md rename to problems/1584-min-cost-to-connect-all-points/NOTES.md diff --git a/problems/1584-min-cost-to-connect-all-points/README.md b/problems/1584-min-cost-to-connect-all-points/README.md new file mode 100644 index 000000000..87d9ecda2 --- /dev/null +++ b/problems/1584-min-cost-to-connect-all-points/README.md @@ -0,0 +1,32 @@ +

1584. Min Cost to Connect All Points

Medium


You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].

+ +

The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.

+ +

Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.

+ +

 

+

Example 1:

+ +
Input: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]
+Output: 20
+Explanation: 
+
+We can connect the points as shown above to get the minimum cost of 20.
+Notice that there is a unique path between every pair of points.
+
+ +

Example 2:

+ +
Input: points = [[3,12],[-2,5],[-4,1]]
+Output: 18
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= points.length <= 1000
  • +
  • -106 <= xi, yi <= 106
  • +
  • All pairs (xi, yi) are distinct.
  • +
+
\ No newline at end of file diff --git a/1598-crawler-log-folder/1598-crawler-log-folder.py b/problems/1598-crawler-log-folder/1598-crawler-log-folder.py similarity index 100% rename from 1598-crawler-log-folder/1598-crawler-log-folder.py rename to problems/1598-crawler-log-folder/1598-crawler-log-folder.py diff --git a/problems/1598-crawler-log-folder/README.md b/problems/1598-crawler-log-folder/README.md new file mode 100644 index 000000000..09137a6e3 --- /dev/null +++ b/problems/1598-crawler-log-folder/README.md @@ -0,0 +1,51 @@ +

1598. Crawler Log Folder

Easy


The Leetcode file system keeps a log each time some user performs a change folder operation.

+ +

The operations are described below:

+ +
    +
  • "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder).
  • +
  • "./" : Remain in the same folder.
  • +
  • "x/" : Move to the child folder named x (This folder is guaranteed to always exist).
  • +
+ +

You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step.

+ +

The file system starts in the main folder, then the operations in logs are performed.

+ +

Return the minimum number of operations needed to go back to the main folder after the change folder operations.

+ +

 

+

Example 1:

+ +

+ +
Input: logs = ["d1/","d2/","../","d21/","./"]
+Output: 2
+Explanation: Use this change folder operation "../" 2 times and go back to the main folder.
+
+ +

Example 2:

+ +

+ +
Input: logs = ["d1/","d2/","./","d3/","../","d31/"]
+Output: 3
+
+ +

Example 3:

+ +
Input: logs = ["d1/","../","../","../"]
+Output: 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= logs.length <= 103
  • +
  • 2 <= logs[i].length <= 10
  • +
  • logs[i] contains lowercase English letters, digits, '.', and '/'.
  • +
  • logs[i] follows the format described in the statement.
  • +
  • Folder names consist of lowercase English letters and digits.
  • +
+
\ No newline at end of file diff --git a/1605-find-valid-matrix-given-row-and-column-sums/1605-find-valid-matrix-given-row-and-column-sums.py b/problems/1605-find-valid-matrix-given-row-and-column-sums/1605-find-valid-matrix-given-row-and-column-sums.py similarity index 100% rename from 1605-find-valid-matrix-given-row-and-column-sums/1605-find-valid-matrix-given-row-and-column-sums.py rename to problems/1605-find-valid-matrix-given-row-and-column-sums/1605-find-valid-matrix-given-row-and-column-sums.py diff --git a/1605-find-valid-matrix-given-row-and-column-sums/NOTES.md b/problems/1605-find-valid-matrix-given-row-and-column-sums/NOTES.md similarity index 100% rename from 1605-find-valid-matrix-given-row-and-column-sums/NOTES.md rename to problems/1605-find-valid-matrix-given-row-and-column-sums/NOTES.md diff --git a/problems/1605-find-valid-matrix-given-row-and-column-sums/README.md b/problems/1605-find-valid-matrix-given-row-and-column-sums/README.md new file mode 100644 index 000000000..fc6d87f01 --- /dev/null +++ b/problems/1605-find-valid-matrix-given-row-and-column-sums/README.md @@ -0,0 +1,39 @@ +

1605. Find Valid Matrix Given Row and Column Sums

Medium


You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the ith row and colSum[j] is the sum of the elements of the jth column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row and column.

+ +

Find any matrix of non-negative integers of size rowSum.length x colSum.length that satisfies the rowSum and colSum requirements.

+ +

Return a 2D array representing any matrix that fulfills the requirements. It's guaranteed that at least one matrix that fulfills the requirements exists.

+ +

 

+

Example 1:

+ +
Input: rowSum = [3,8], colSum = [4,7]
+Output: [[3,0],
+         [1,7]]
+Explanation: 
+0th row: 3 + 0 = 3 == rowSum[0]
+1st row: 1 + 7 = 8 == rowSum[1]
+0th column: 3 + 1 = 4 == colSum[0]
+1st column: 0 + 7 = 7 == colSum[1]
+The row and column sums match, and all matrix elements are non-negative.
+Another possible matrix is: [[1,2],
+                             [3,5]]
+
+ +

Example 2:

+ +
Input: rowSum = [5,7,10], colSum = [8,6,8]
+Output: [[0,5,0],
+         [6,1,0],
+         [2,0,8]]
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= rowSum.length, colSum.length <= 500
  • +
  • 0 <= rowSum[i], colSum[i] <= 108
  • +
  • sum(rowSum) == sum(colSum)
  • +
+
\ No newline at end of file diff --git a/1608-special-array-with-x-elements-greater-than-or-equal-x/1608-special-array-with-x-elements-greater-than-or-equal-x.py b/problems/1608-special-array-with-x-elements-greater-than-or-equal-x/1608-special-array-with-x-elements-greater-than-or-equal-x.py similarity index 100% rename from 1608-special-array-with-x-elements-greater-than-or-equal-x/1608-special-array-with-x-elements-greater-than-or-equal-x.py rename to problems/1608-special-array-with-x-elements-greater-than-or-equal-x/1608-special-array-with-x-elements-greater-than-or-equal-x.py diff --git a/problems/1608-special-array-with-x-elements-greater-than-or-equal-x/README.md b/problems/1608-special-array-with-x-elements-greater-than-or-equal-x/README.md new file mode 100644 index 000000000..6ccc00386 --- /dev/null +++ b/problems/1608-special-array-with-x-elements-greater-than-or-equal-x/README.md @@ -0,0 +1,40 @@ +

1608. Special Array With X Elements Greater Than or Equal X

Easy


You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x.

+ +

Notice that x does not have to be an element in nums.

+ +

Return x if the array is special, otherwise, return -1. It can be proven that if nums is special, the value for x is unique.

+ +

 

+

Example 1:

+ +
Input: nums = [3,5]
+Output: 2
+Explanation: There are 2 values (3 and 5) that are greater than or equal to 2.
+
+ +

Example 2:

+ +
Input: nums = [0,0]
+Output: -1
+Explanation: No numbers fit the criteria for x.
+If x = 0, there should be 0 numbers >= x, but there are 2.
+If x = 1, there should be 1 number >= x, but there are 0.
+If x = 2, there should be 2 numbers >= x, but there are 0.
+x cannot be greater since there are only 2 numbers in nums.
+
+ +

Example 3:

+ +
Input: nums = [0,4,3,0,4]
+Output: 3
+Explanation: There are 3 values that are greater than or equal to 3.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 1000
  • +
+
\ No newline at end of file diff --git a/1609-even-odd-tree/1609-even-odd-tree.py b/problems/1609-even-odd-tree/1609-even-odd-tree.py similarity index 100% rename from 1609-even-odd-tree/1609-even-odd-tree.py rename to problems/1609-even-odd-tree/1609-even-odd-tree.py diff --git a/1609-even-odd-tree/NOTES.md b/problems/1609-even-odd-tree/NOTES.md similarity index 100% rename from 1609-even-odd-tree/NOTES.md rename to problems/1609-even-odd-tree/NOTES.md diff --git a/problems/1609-even-odd-tree/README.md b/problems/1609-even-odd-tree/README.md new file mode 100644 index 000000000..706e4f8f9 --- /dev/null +++ b/problems/1609-even-odd-tree/README.md @@ -0,0 +1,49 @@ +

1609. Even Odd Tree

Medium


A binary tree is named Even-Odd if it meets the following conditions:

+ +
    +
  • The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.
  • +
  • For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).
  • +
  • For every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).
  • +
+ +

Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.

+ +

 

+

Example 1:

+ +
Input: root = [1,10,4,3,null,7,9,12,8,6,null,null,2]
+Output: true
+Explanation: The node values on each level are:
+Level 0: [1]
+Level 1: [10,4]
+Level 2: [3,7,9]
+Level 3: [12,8,6,2]
+Since levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.
+
+ +

Example 2:

+ +
Input: root = [5,4,2,3,3,7]
+Output: false
+Explanation: The node values on each level are:
+Level 0: [5]
+Level 1: [4,2]
+Level 2: [3,3,7]
+Node values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.
+
+ +

Example 3:

+ +
Input: root = [5,9,1,3,5,7]
+Output: false
+Explanation: Node values in the level 1 should be even integers.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 105].
  • +
  • 1 <= Node.val <= 106
  • +
+
\ No newline at end of file diff --git a/1611-minimum-one-bit-operations-to-make-integers-zero/1611-minimum-one-bit-operations-to-make-integers-zero.py b/problems/1611-minimum-one-bit-operations-to-make-integers-zero/1611-minimum-one-bit-operations-to-make-integers-zero.py similarity index 100% rename from 1611-minimum-one-bit-operations-to-make-integers-zero/1611-minimum-one-bit-operations-to-make-integers-zero.py rename to problems/1611-minimum-one-bit-operations-to-make-integers-zero/1611-minimum-one-bit-operations-to-make-integers-zero.py diff --git a/1611-minimum-one-bit-operations-to-make-integers-zero/NOTES.md b/problems/1611-minimum-one-bit-operations-to-make-integers-zero/NOTES.md similarity index 100% rename from 1611-minimum-one-bit-operations-to-make-integers-zero/NOTES.md rename to problems/1611-minimum-one-bit-operations-to-make-integers-zero/NOTES.md diff --git a/problems/1611-minimum-one-bit-operations-to-make-integers-zero/README.md b/problems/1611-minimum-one-bit-operations-to-make-integers-zero/README.md new file mode 100644 index 000000000..550b6f95c --- /dev/null +++ b/problems/1611-minimum-one-bit-operations-to-make-integers-zero/README.md @@ -0,0 +1,37 @@ +

1611. Minimum One Bit Operations to Make Integers Zero

Hard


Given an integer n, you must transform it into 0 using the following operations any number of times:

+ +
    +
  • Change the rightmost (0th) bit in the binary representation of n.
  • +
  • Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.
  • +
+ +

Return the minimum number of operations to transform n into 0.

+ +

 

+

Example 1:

+ +
Input: n = 3
+Output: 2
+Explanation: The binary representation of 3 is "11".
+"11" -> "01" with the 2nd operation since the 0th bit is 1.
+"01" -> "00" with the 1st operation.
+
+ +

Example 2:

+ +
Input: n = 6
+Output: 4
+Explanation: The binary representation of 6 is "110".
+"110" -> "010" with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.
+"010" -> "011" with the 1st operation.
+"011" -> "001" with the 2nd operation since the 0th bit is 1.
+"001" -> "000" with the 1st operation.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= n <= 109
  • +
+
\ No newline at end of file diff --git a/1614-maximum-nesting-depth-of-the-parentheses/1614-maximum-nesting-depth-of-the-parentheses.py b/problems/1614-maximum-nesting-depth-of-the-parentheses/1614-maximum-nesting-depth-of-the-parentheses.py similarity index 100% rename from 1614-maximum-nesting-depth-of-the-parentheses/1614-maximum-nesting-depth-of-the-parentheses.py rename to problems/1614-maximum-nesting-depth-of-the-parentheses/1614-maximum-nesting-depth-of-the-parentheses.py diff --git a/1614-maximum-nesting-depth-of-the-parentheses/NOTES.md b/problems/1614-maximum-nesting-depth-of-the-parentheses/NOTES.md similarity index 100% rename from 1614-maximum-nesting-depth-of-the-parentheses/NOTES.md rename to problems/1614-maximum-nesting-depth-of-the-parentheses/NOTES.md diff --git a/problems/1614-maximum-nesting-depth-of-the-parentheses/README.md b/problems/1614-maximum-nesting-depth-of-the-parentheses/README.md new file mode 100644 index 000000000..b636dfcb4 --- /dev/null +++ b/problems/1614-maximum-nesting-depth-of-the-parentheses/README.md @@ -0,0 +1,44 @@ +

1614. Maximum Nesting Depth of the Parentheses

Easy


A string is a valid parentheses string (denoted VPS) if it meets one of the following:

+ +
    +
  • It is an empty string "", or a single character not equal to "(" or ")",
  • +
  • It can be written as AB (A concatenated with B), where A and B are VPS's, or
  • +
  • It can be written as (A), where A is a VPS.
  • +
+ +

We can similarly define the nesting depth depth(S) of any VPS S as follows:

+ +
    +
  • depth("") = 0
  • +
  • depth(C) = 0, where C is a string with a single character not equal to "(" or ")".
  • +
  • depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's.
  • +
  • depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
  • +
+ +

For example, "", "()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.

+ +

Given a VPS represented as string s, return the nesting depth of s.

+ +

 

+

Example 1:

+ +
Input: s = "(1+(2*3)+((8)/4))+1"
+Output: 3
+Explanation: Digit 8 is inside of 3 nested parentheses in the string.
+
+ +

Example 2:

+ +
Input: s = "(1)+((2))+(((3)))"
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s consists of digits 0-9 and characters '+', '-', '*', '/', '(', and ')'.
  • +
  • It is guaranteed that parentheses expression s is a VPS.
  • +
+
\ No newline at end of file diff --git a/1615-maximal-network-rank/1615-maximal-network-rank.py b/problems/1615-maximal-network-rank/1615-maximal-network-rank.py similarity index 100% rename from 1615-maximal-network-rank/1615-maximal-network-rank.py rename to problems/1615-maximal-network-rank/1615-maximal-network-rank.py diff --git a/1615-maximal-network-rank/NOTES.md b/problems/1615-maximal-network-rank/NOTES.md similarity index 100% rename from 1615-maximal-network-rank/NOTES.md rename to problems/1615-maximal-network-rank/NOTES.md diff --git a/problems/1615-maximal-network-rank/README.md b/problems/1615-maximal-network-rank/README.md new file mode 100644 index 000000000..70897096b --- /dev/null +++ b/problems/1615-maximal-network-rank/README.md @@ -0,0 +1,46 @@ +

1615. Maximal Network Rank

Medium


There is an infrastructure of n cities with some number of roads connecting these cities. Each roads[i] = [ai, bi] indicates that there is a bidirectional road between cities ai and bi.

+ +

The network rank of two different cities is defined as the total number of directly connected roads to either city. If a road is directly connected to both cities, it is only counted once.

+ +

The maximal network rank of the infrastructure is the maximum network rank of all pairs of different cities.

+ +

Given the integer n and the array roads, return the maximal network rank of the entire infrastructure.

+ +

 

+

Example 1:

+ +

+ +
Input: n = 4, roads = [[0,1],[0,3],[1,2],[1,3]]
+Output: 4
+Explanation: The network rank of cities 0 and 1 is 4 as there are 4 roads that are connected to either 0 or 1. The road between 0 and 1 is only counted once.
+
+ +

Example 2:

+ +

+ +
Input: n = 5, roads = [[0,1],[0,3],[1,2],[1,3],[2,3],[2,4]]
+Output: 5
+Explanation: There are 5 roads that are connected to cities 1 or 2.
+
+ +

Example 3:

+ +
Input: n = 8, roads = [[0,1],[1,2],[2,3],[2,4],[5,6],[5,7]]
+Output: 5
+Explanation: The network rank of 2 and 5 is 5. Notice that all the cities do not have to be connected.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 100
  • +
  • 0 <= roads.length <= n * (n - 1) / 2
  • +
  • roads[i].length == 2
  • +
  • 0 <= ai, bi <= n-1
  • +
  • ai != bi
  • +
  • Each pair of cities has at most one road connecting them.
  • +
+
\ No newline at end of file diff --git a/1624-largest-substring-between-two-equal-characters/1624-largest-substring-between-two-equal-characters.py b/problems/1624-largest-substring-between-two-equal-characters/1624-largest-substring-between-two-equal-characters.py similarity index 100% rename from 1624-largest-substring-between-two-equal-characters/1624-largest-substring-between-two-equal-characters.py rename to problems/1624-largest-substring-between-two-equal-characters/1624-largest-substring-between-two-equal-characters.py diff --git a/1624-largest-substring-between-two-equal-characters/NOTES.md b/problems/1624-largest-substring-between-two-equal-characters/NOTES.md similarity index 100% rename from 1624-largest-substring-between-two-equal-characters/NOTES.md rename to problems/1624-largest-substring-between-two-equal-characters/NOTES.md diff --git a/problems/1624-largest-substring-between-two-equal-characters/README.md b/problems/1624-largest-substring-between-two-equal-characters/README.md new file mode 100644 index 000000000..cfc9757d7 --- /dev/null +++ b/problems/1624-largest-substring-between-two-equal-characters/README.md @@ -0,0 +1,33 @@ +

1624. Largest Substring Between Two Equal Characters

Easy


Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1.

+ +

A substring is a contiguous sequence of characters within a string.

+ +

 

+

Example 1:

+ +
Input: s = "aa"
+Output: 0
+Explanation: The optimal substring here is an empty substring between the two 'a's.
+ +

Example 2:

+ +
Input: s = "abca"
+Output: 2
+Explanation: The optimal substring here is "bc".
+
+ +

Example 3:

+ +
Input: s = "cbzxy"
+Output: -1
+Explanation: There are no characters that appear twice in s.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 300
  • +
  • s contains only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1630-arithmetic-subarrays/1630-arithmetic-subarrays.py b/problems/1630-arithmetic-subarrays/1630-arithmetic-subarrays.py similarity index 100% rename from 1630-arithmetic-subarrays/1630-arithmetic-subarrays.py rename to problems/1630-arithmetic-subarrays/1630-arithmetic-subarrays.py diff --git a/1630-arithmetic-subarrays/NOTES.md b/problems/1630-arithmetic-subarrays/NOTES.md similarity index 100% rename from 1630-arithmetic-subarrays/NOTES.md rename to problems/1630-arithmetic-subarrays/NOTES.md diff --git a/problems/1630-arithmetic-subarrays/README.md b/problems/1630-arithmetic-subarrays/README.md new file mode 100644 index 000000000..80df29f31 --- /dev/null +++ b/problems/1630-arithmetic-subarrays/README.md @@ -0,0 +1,45 @@ +

1630. Arithmetic Subarrays

Medium


A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.

+ +

For example, these are arithmetic sequences:

+ +
1, 3, 5, 7, 9
+7, 7, 7, 7
+3, -1, -5, -9
+ +

The following sequence is not arithmetic:

+ +
1, 1, 2, 5, 7
+ +

You are given an array of n integers, nums, and two arrays of m integers each, l and r, representing the m range queries, where the ith query is the range [l[i], r[i]]. All the arrays are 0-indexed.

+ +

Return a list of boolean elements answer, where answer[i] is true if the subarray nums[l[i]], nums[l[i]+1], ... , nums[r[i]] can be rearranged to form an arithmetic sequence, and false otherwise.

+ +

 

+

Example 1:

+ +
Input: nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]
+Output: [true,false,true]
+Explanation:
+In the 0th query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence.
+In the 1st query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.
+In the 2nd query, the subarray is [5,9,3,7]. This can be rearranged as [3,5,7,9], which is an arithmetic sequence.
+ +

Example 2:

+ +
Input: nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]
+Output: [false,true,false,false,true,true]
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • m == l.length
  • +
  • m == r.length
  • +
  • 2 <= n <= 500
  • +
  • 1 <= m <= 500
  • +
  • 0 <= l[i] < r[i] < n
  • +
  • -105 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/1631-path-with-minimum-effort/1631-path-with-minimum-effort.py b/problems/1631-path-with-minimum-effort/1631-path-with-minimum-effort.py similarity index 100% rename from 1631-path-with-minimum-effort/1631-path-with-minimum-effort.py rename to problems/1631-path-with-minimum-effort/1631-path-with-minimum-effort.py diff --git a/1631-path-with-minimum-effort/NOTES.md b/problems/1631-path-with-minimum-effort/NOTES.md similarity index 100% rename from 1631-path-with-minimum-effort/NOTES.md rename to problems/1631-path-with-minimum-effort/NOTES.md diff --git a/problems/1631-path-with-minimum-effort/README.md b/problems/1631-path-with-minimum-effort/README.md new file mode 100644 index 000000000..f355c88fb --- /dev/null +++ b/problems/1631-path-with-minimum-effort/README.md @@ -0,0 +1,42 @@ +

1631. Path With Minimum Effort

Medium


You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e., 0-indexed). You can move up, down, left, or right, and you wish to find a route that requires the minimum effort.

+ +

A route's effort is the maximum absolute difference in heights between two consecutive cells of the route.

+ +

Return the minimum effort required to travel from the top-left cell to the bottom-right cell.

+ +

 

+

Example 1:

+ +

+ +
Input: heights = [[1,2,2],[3,8,2],[5,3,5]]
+Output: 2
+Explanation: The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells.
+This is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.
+
+ +

Example 2:

+ +

+ +
Input: heights = [[1,2,3],[3,8,4],[5,3,5]]
+Output: 1
+Explanation: The route of [1,2,3,4,5] has a maximum absolute difference of 1 in consecutive cells, which is better than route [1,3,5,3,5].
+
+ +

Example 3:

+ +
Input: heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]
+Output: 0
+Explanation: This route does not require any effort.
+
+ +

 

+

Constraints:

+ +
    +
  • rows == heights.length
  • +
  • columns == heights[i].length
  • +
  • 1 <= rows, columns <= 100
  • +
  • 1 <= heights[i][j] <= 106
  • +
\ No newline at end of file diff --git a/1636-sort-array-by-increasing-frequency/1636-sort-array-by-increasing-frequency.py b/problems/1636-sort-array-by-increasing-frequency/1636-sort-array-by-increasing-frequency.py similarity index 100% rename from 1636-sort-array-by-increasing-frequency/1636-sort-array-by-increasing-frequency.py rename to problems/1636-sort-array-by-increasing-frequency/1636-sort-array-by-increasing-frequency.py diff --git a/problems/1636-sort-array-by-increasing-frequency/README.md b/problems/1636-sort-array-by-increasing-frequency/README.md new file mode 100644 index 000000000..cfe5e97ae --- /dev/null +++ b/problems/1636-sort-array-by-increasing-frequency/README.md @@ -0,0 +1,32 @@ +

1636. Sort Array by Increasing Frequency

Easy


Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order.

+ +

Return the sorted array.

+ +

 

+

Example 1:

+ +
Input: nums = [1,1,2,2,2,3]
+Output: [3,1,1,2,2,2]
+Explanation: '3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3.
+
+ +

Example 2:

+ +
Input: nums = [2,3,1,3,2]
+Output: [1,3,3,2,2]
+Explanation: '2' and '3' both have a frequency of 2, so they are sorted in decreasing order.
+
+ +

Example 3:

+ +
Input: nums = [-1,1,-6,4,5,-6,1,4,1]
+Output: [5,-1,4,4,-6,-6,1,1,1]
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • -100 <= nums[i] <= 100
  • +
+
\ No newline at end of file diff --git a/1637-widest-vertical-area-between-two-points-containing-no-points/1637-widest-vertical-area-between-two-points-containing-no-points.py b/problems/1637-widest-vertical-area-between-two-points-containing-no-points/1637-widest-vertical-area-between-two-points-containing-no-points.py similarity index 100% rename from 1637-widest-vertical-area-between-two-points-containing-no-points/1637-widest-vertical-area-between-two-points-containing-no-points.py rename to problems/1637-widest-vertical-area-between-two-points-containing-no-points/1637-widest-vertical-area-between-two-points-containing-no-points.py diff --git a/1637-widest-vertical-area-between-two-points-containing-no-points/NOTES.md b/problems/1637-widest-vertical-area-between-two-points-containing-no-points/NOTES.md similarity index 100% rename from 1637-widest-vertical-area-between-two-points-containing-no-points/NOTES.md rename to problems/1637-widest-vertical-area-between-two-points-containing-no-points/NOTES.md diff --git a/1642-furthest-building-you-can-reach/1642-furthest-building-you-can-reach.py b/problems/1642-furthest-building-you-can-reach/1642-furthest-building-you-can-reach.py similarity index 100% rename from 1642-furthest-building-you-can-reach/1642-furthest-building-you-can-reach.py rename to problems/1642-furthest-building-you-can-reach/1642-furthest-building-you-can-reach.py diff --git a/1642-furthest-building-you-can-reach/NOTES.md b/problems/1642-furthest-building-you-can-reach/NOTES.md similarity index 100% rename from 1642-furthest-building-you-can-reach/NOTES.md rename to problems/1642-furthest-building-you-can-reach/NOTES.md diff --git a/problems/1642-furthest-building-you-can-reach/README.md b/problems/1642-furthest-building-you-can-reach/README.md new file mode 100644 index 000000000..57d2a1ebd --- /dev/null +++ b/problems/1642-furthest-building-you-can-reach/README.md @@ -0,0 +1,48 @@ +

1642. Furthest Building You Can Reach

Medium


You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.

+ +

You start your journey from building 0 and move to the next building by possibly using bricks or ladders.

+ +

While moving from building i to building i+1 (0-indexed),

+ +
    +
  • If the current building's height is greater than or equal to the next building's height, you do not need a ladder or bricks.
  • +
  • If the current building's height is less than the next building's height, you can either use one ladder or (h[i+1] - h[i]) bricks.
  • +
+ +

Return the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.

+ +

 

+

Example 1:

+ +
Input: heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1
+Output: 4
+Explanation: Starting at building 0, you can follow these steps:
+- Go to building 1 without using ladders nor bricks since 4 >= 2.
+- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.
+- Go to building 3 without using ladders nor bricks since 7 >= 6.
+- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.
+It is impossible to go beyond building 4 because you do not have any more bricks or ladders.
+
+ +

Example 2:

+ +
Input: heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2
+Output: 7
+
+ +

Example 3:

+ +
Input: heights = [14,3,19,3], bricks = 17, ladders = 0
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= heights.length <= 105
  • +
  • 1 <= heights[i] <= 106
  • +
  • 0 <= bricks <= 109
  • +
  • 0 <= ladders <= heights.length
  • +
+
\ No newline at end of file diff --git a/1647-minimum-deletions-to-make-character-frequencies-unique/1647-minimum-deletions-to-make-character-frequencies-unique.py b/problems/1647-minimum-deletions-to-make-character-frequencies-unique/1647-minimum-deletions-to-make-character-frequencies-unique.py similarity index 100% rename from 1647-minimum-deletions-to-make-character-frequencies-unique/1647-minimum-deletions-to-make-character-frequencies-unique.py rename to problems/1647-minimum-deletions-to-make-character-frequencies-unique/1647-minimum-deletions-to-make-character-frequencies-unique.py diff --git a/1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md b/problems/1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md similarity index 100% rename from 1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md rename to problems/1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md diff --git a/problems/1647-minimum-deletions-to-make-character-frequencies-unique/README.md b/problems/1647-minimum-deletions-to-make-character-frequencies-unique/README.md new file mode 100644 index 000000000..3cf42be1f --- /dev/null +++ b/problems/1647-minimum-deletions-to-make-character-frequencies-unique/README.md @@ -0,0 +1,37 @@ +

1647. Minimum Deletions to Make Character Frequencies Unique

Medium


A string s is called good if there are no two different characters in s that have the same frequency.

+ +

Given a string s, return the minimum number of characters you need to delete to make s good.

+ +

The frequency of a character in a string is the number of times it appears in the string. For example, in the string "aab", the frequency of 'a' is 2, while the frequency of 'b' is 1.

+ +

 

+

Example 1:

+ +
Input: s = "aab"
+Output: 0
+Explanation: s is already good.
+
+ +

Example 2:

+ +
Input: s = "aaabbbcc"
+Output: 2
+Explanation: You can delete two 'b's resulting in the good string "aaabcc".
+Another way it to delete one 'b' and one 'c' resulting in the good string "aaabbc".
+ +

Example 3:

+ +
Input: s = "ceabaacb"
+Output: 2
+Explanation: You can delete both 'c's resulting in the good string "eabaab".
+Note that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s contains only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1653-minimum-deletions-to-make-string-balanced/1653-minimum-deletions-to-make-string-balanced.py b/problems/1653-minimum-deletions-to-make-string-balanced/1653-minimum-deletions-to-make-string-balanced.py similarity index 100% rename from 1653-minimum-deletions-to-make-string-balanced/1653-minimum-deletions-to-make-string-balanced.py rename to problems/1653-minimum-deletions-to-make-string-balanced/1653-minimum-deletions-to-make-string-balanced.py diff --git a/problems/1653-minimum-deletions-to-make-string-balanced/README.md b/problems/1653-minimum-deletions-to-make-string-balanced/README.md new file mode 100644 index 000000000..8dc82bd2d --- /dev/null +++ b/problems/1653-minimum-deletions-to-make-string-balanced/README.md @@ -0,0 +1,31 @@ +

1653. Minimum Deletions to Make String Balanced

Medium


You are given a string s consisting only of characters 'a' and 'b'​​​​.

+ +

You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.

+ +

Return the minimum number of deletions needed to make s balanced.

+ +

 

+

Example 1:

+ +
Input: s = "aababbab"
+Output: 2
+Explanation: You can either:
+Delete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or
+Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
+
+ +

Example 2:

+ +
Input: s = "bbaaaaabb"
+Output: 2
+Explanation: The only solution is to delete the first two characters.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s[i] is 'a' or 'b'​​.
  • +
+
\ No newline at end of file diff --git a/1657-determine-if-two-strings-are-close/1657-determine-if-two-strings-are-close.py b/problems/1657-determine-if-two-strings-are-close/1657-determine-if-two-strings-are-close.py similarity index 100% rename from 1657-determine-if-two-strings-are-close/1657-determine-if-two-strings-are-close.py rename to problems/1657-determine-if-two-strings-are-close/1657-determine-if-two-strings-are-close.py diff --git a/1657-determine-if-two-strings-are-close/NOTES.md b/problems/1657-determine-if-two-strings-are-close/NOTES.md similarity index 100% rename from 1657-determine-if-two-strings-are-close/NOTES.md rename to problems/1657-determine-if-two-strings-are-close/NOTES.md diff --git a/problems/1657-determine-if-two-strings-are-close/README.md b/problems/1657-determine-if-two-strings-are-close/README.md new file mode 100644 index 000000000..fb38a7bb9 --- /dev/null +++ b/problems/1657-determine-if-two-strings-are-close/README.md @@ -0,0 +1,55 @@ +

1657. Determine if Two Strings Are Close

Medium


Two strings are considered close if you can attain one from the other using the following operations:

+ +
    +
  • Operation 1: Swap any two existing characters. + +
      +
    • For example, abcde -> aecdb
    • +
    +
  • +
  • Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character. +
      +
    • For example, aacabb -> bbcbaa (all a's turn into b's, and all b's turn into a's)
    • +
    +
  • +
+ +

You can use the operations on either string as many times as necessary.

+ +

Given two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.

+ +

 

+

Example 1:

+ +
Input: word1 = "abc", word2 = "bca"
+Output: true
+Explanation: You can attain word2 from word1 in 2 operations.
+Apply Operation 1: "abc" -> "acb"
+Apply Operation 1: "acb" -> "bca"
+
+ +

Example 2:

+ +
Input: word1 = "a", word2 = "aa"
+Output: false
+Explanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.
+
+ +

Example 3:

+ +
Input: word1 = "cabbba", word2 = "abbccc"
+Output: true
+Explanation: You can attain word2 from word1 in 3 operations.
+Apply Operation 1: "cabbba" -> "caabbb"
+Apply Operation 2: "caabbb" -> "baaccc"
+Apply Operation 2: "baaccc" -> "abbccc"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word1.length, word2.length <= 105
  • +
  • word1 and word2 contain only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1658-minimum-operations-to-reduce-x-to-zero/1658-minimum-operations-to-reduce-x-to-zero.py b/problems/1658-minimum-operations-to-reduce-x-to-zero/1658-minimum-operations-to-reduce-x-to-zero.py similarity index 100% rename from 1658-minimum-operations-to-reduce-x-to-zero/1658-minimum-operations-to-reduce-x-to-zero.py rename to problems/1658-minimum-operations-to-reduce-x-to-zero/1658-minimum-operations-to-reduce-x-to-zero.py diff --git a/1658-minimum-operations-to-reduce-x-to-zero/NOTES.md b/problems/1658-minimum-operations-to-reduce-x-to-zero/NOTES.md similarity index 100% rename from 1658-minimum-operations-to-reduce-x-to-zero/NOTES.md rename to problems/1658-minimum-operations-to-reduce-x-to-zero/NOTES.md diff --git a/problems/1658-minimum-operations-to-reduce-x-to-zero/README.md b/problems/1658-minimum-operations-to-reduce-x-to-zero/README.md new file mode 100644 index 000000000..5a819240b --- /dev/null +++ b/problems/1658-minimum-operations-to-reduce-x-to-zero/README.md @@ -0,0 +1,34 @@ +

1658. Minimum Operations to Reduce X to Zero

Medium


You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.

+ +

Return the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1.

+ +

 

+

Example 1:

+ +
Input: nums = [1,1,4,2,3], x = 5
+Output: 2
+Explanation: The optimal solution is to remove the last two elements to reduce x to zero.
+
+ +

Example 2:

+ +
Input: nums = [5,6,7,8,9], x = 4
+Output: -1
+
+ +

Example 3:

+ +
Input: nums = [3,2,20,1,1,3], x = 10
+Output: 5
+Explanation: The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 104
  • +
  • 1 <= x <= 109
  • +
+
\ No newline at end of file diff --git a/1660-correct-a-binary-tree/1660-correct-a-binary-tree.py b/problems/1660-correct-a-binary-tree/1660-correct-a-binary-tree.py similarity index 100% rename from 1660-correct-a-binary-tree/1660-correct-a-binary-tree.py rename to problems/1660-correct-a-binary-tree/1660-correct-a-binary-tree.py diff --git a/1660-correct-a-binary-tree/NOTES.md b/problems/1660-correct-a-binary-tree/NOTES.md similarity index 100% rename from 1660-correct-a-binary-tree/NOTES.md rename to problems/1660-correct-a-binary-tree/NOTES.md diff --git a/problems/1660-correct-a-binary-tree/README.md b/problems/1660-correct-a-binary-tree/README.md new file mode 100644 index 000000000..4c3c3d0e4 --- /dev/null +++ b/problems/1660-correct-a-binary-tree/README.md @@ -0,0 +1,47 @@ +

1660. Correct a Binary Tree

Medium


You have a binary tree with a small defect. There is exactly one invalid node where its right child incorrectly points to another node at the same depth but to the invalid node's right.

+ +

Given the root of the binary tree with this defect, root, return the root of the binary tree after removing this invalid node and every node underneath it (minus the node it incorrectly points to).

+ +

Custom testing:

+ +

The test input is read as 3 lines:

+ +
    +
  • TreeNode root
  • +
  • int fromNode (not available to correctBinaryTree)
  • +
  • int toNode (not available to correctBinaryTree)
  • +
+ +

After the binary tree rooted at root is parsed, the TreeNode with value of fromNode will have its right child pointer pointing to the TreeNode with a value of toNode. Then, root is passed to correctBinaryTree.

+ +

 

+

Example 1:

+ +

+ +
Input: root = [1,2,3], fromNode = 2, toNode = 3
+Output: [1,null,3]
+Explanation: The node with value 2 is invalid, so remove it.
+
+ +

Example 2:

+ +

+ +
Input: root = [8,3,1,7,null,9,4,2,null,null,null,5,6], fromNode = 7, toNode = 4
+Output: [8,3,1,null,null,9,4,null,null,5,6]
+Explanation: The node with value 7 is invalid, so remove it and the node underneath it, node 2.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [3, 104].
  • +
  • -109 <= Node.val <= 109
  • +
  • All Node.val are unique.
  • +
  • fromNode != toNode
  • +
  • fromNode and toNode will exist in the tree and will be on the same depth.
  • +
  • toNode is to the right of fromNode.
  • +
  • fromNode.right is null in the initial tree from the test data.
  • +
\ No newline at end of file diff --git a/1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.py b/problems/1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.py similarity index 100% rename from 1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.py rename to problems/1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.py diff --git a/1662-check-if-two-string-arrays-are-equivalent/NOTES.md b/problems/1662-check-if-two-string-arrays-are-equivalent/NOTES.md similarity index 100% rename from 1662-check-if-two-string-arrays-are-equivalent/NOTES.md rename to problems/1662-check-if-two-string-arrays-are-equivalent/NOTES.md diff --git a/problems/1662-check-if-two-string-arrays-are-equivalent/README.md b/problems/1662-check-if-two-string-arrays-are-equivalent/README.md new file mode 100644 index 000000000..da59236b5 --- /dev/null +++ b/problems/1662-check-if-two-string-arrays-are-equivalent/README.md @@ -0,0 +1,36 @@ +

1662. Check If Two String Arrays are Equivalent

Easy


Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.

+ +

A string is represented by an array if the array elements concatenated in order forms the string.

+ +

 

+

Example 1:

+ +
Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
+Output: true
+Explanation:
+word1 represents string "ab" + "c" -> "abc"
+word2 represents string "a" + "bc" -> "abc"
+The strings are the same, so return true.
+ +

Example 2:

+ +
Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
+Output: false
+
+ +

Example 3:

+ +
Input: word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]
+Output: true
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word1.length, word2.length <= 103
  • +
  • 1 <= word1[i].length, word2[i].length <= 103
  • +
  • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
  • +
  • word1[i] and word2[i] consist of lowercase letters.
  • +
+
\ No newline at end of file diff --git a/1669-merge-in-between-linked-lists/1669-merge-in-between-linked-lists.py b/problems/1669-merge-in-between-linked-lists/1669-merge-in-between-linked-lists.py similarity index 100% rename from 1669-merge-in-between-linked-lists/1669-merge-in-between-linked-lists.py rename to problems/1669-merge-in-between-linked-lists/1669-merge-in-between-linked-lists.py diff --git a/1669-merge-in-between-linked-lists/NOTES.md b/problems/1669-merge-in-between-linked-lists/NOTES.md similarity index 100% rename from 1669-merge-in-between-linked-lists/NOTES.md rename to problems/1669-merge-in-between-linked-lists/NOTES.md diff --git a/problems/1669-merge-in-between-linked-lists/README.md b/problems/1669-merge-in-between-linked-lists/README.md new file mode 100644 index 000000000..80ce1897a --- /dev/null +++ b/problems/1669-merge-in-between-linked-lists/README.md @@ -0,0 +1,32 @@ +

1669. Merge In Between Linked Lists

Medium


You are given two linked lists: list1 and list2 of sizes n and m respectively.

+ +

Remove list1's nodes from the ath node to the bth node, and put list2 in their place.

+ +

The blue edges and nodes in the following figure indicate the result:

+ +

Build the result list and return its head.

+ +

 

+

Example 1:

+ +
Input: list1 = [10,1,13,6,9,5], a = 3, b = 4, list2 = [1000000,1000001,1000002]
+Output: [10,1,13,1000000,1000001,1000002,5]
+Explanation: We remove the nodes 3 and 4 and put the entire list2 in their place. The blue edges and nodes in the above figure indicate the result.
+
+ +

Example 2:

+ +
Input: list1 = [0,1,2,3,4,5,6], a = 2, b = 5, list2 = [1000000,1000001,1000002,1000003,1000004]
+Output: [0,1,1000000,1000001,1000002,1000003,1000004,6]
+Explanation: The blue edges and nodes in the above figure indicate the result.
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= list1.length <= 104
  • +
  • 1 <= a <= b < list1.length - 1
  • +
  • 1 <= list2.length <= 104
  • +
+
\ No newline at end of file diff --git a/1683-invalid-tweets/1683-invalid-tweets.sql b/problems/1683-invalid-tweets/1683-invalid-tweets.sql similarity index 100% rename from 1683-invalid-tweets/1683-invalid-tweets.sql rename to problems/1683-invalid-tweets/1683-invalid-tweets.sql diff --git a/1683-invalid-tweets/NOTES.md b/problems/1683-invalid-tweets/NOTES.md similarity index 100% rename from 1683-invalid-tweets/NOTES.md rename to problems/1683-invalid-tweets/NOTES.md diff --git a/problems/1683-invalid-tweets/README.md b/problems/1683-invalid-tweets/README.md new file mode 100644 index 000000000..ffab3320c --- /dev/null +++ b/problems/1683-invalid-tweets/README.md @@ -0,0 +1,42 @@ +

1683. Invalid Tweets

Easy


Table: Tweets

+ +
+----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| tweet_id       | int     |
+| content        | varchar |
++----------------+---------+
+tweet_id is the primary key (column with unique values) for this table.
+This table contains all the tweets in a social media app.
+
+ +

 

+ +

Write a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
Input: 
+Tweets table:
++----------+----------------------------------+
+| tweet_id | content                          |
++----------+----------------------------------+
+| 1        | Vote for Biden                   |
+| 2        | Let us make America great again! |
++----------+----------------------------------+
+Output: 
++----------+
+| tweet_id |
++----------+
+| 2        |
++----------+
+Explanation: 
+Tweet 1 has length = 14. It is a valid tweet.
+Tweet 2 has length = 32. It is an invalid tweet.
+
+
\ No newline at end of file diff --git a/1685-sum-of-absolute-differences-in-a-sorted-array/1685-sum-of-absolute-differences-in-a-sorted-array.py b/problems/1685-sum-of-absolute-differences-in-a-sorted-array/1685-sum-of-absolute-differences-in-a-sorted-array.py similarity index 100% rename from 1685-sum-of-absolute-differences-in-a-sorted-array/1685-sum-of-absolute-differences-in-a-sorted-array.py rename to problems/1685-sum-of-absolute-differences-in-a-sorted-array/1685-sum-of-absolute-differences-in-a-sorted-array.py diff --git a/1685-sum-of-absolute-differences-in-a-sorted-array/NOTES.md b/problems/1685-sum-of-absolute-differences-in-a-sorted-array/NOTES.md similarity index 100% rename from 1685-sum-of-absolute-differences-in-a-sorted-array/NOTES.md rename to problems/1685-sum-of-absolute-differences-in-a-sorted-array/NOTES.md diff --git a/problems/1685-sum-of-absolute-differences-in-a-sorted-array/README.md b/problems/1685-sum-of-absolute-differences-in-a-sorted-array/README.md new file mode 100644 index 000000000..4208404a5 --- /dev/null +++ b/problems/1685-sum-of-absolute-differences-in-a-sorted-array/README.md @@ -0,0 +1,31 @@ +

1685. Sum of Absolute Differences in a Sorted Array

Medium


You are given an integer array nums sorted in non-decreasing order.

+ +

Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array.

+ +

In other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 <= j < nums.length and j != i (0-indexed).

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,5]
+Output: [4,3,5]
+Explanation: Assuming the arrays are 0-indexed, then
+result[0] = |2-2| + |2-3| + |2-5| = 0 + 1 + 3 = 4,
+result[1] = |3-2| + |3-3| + |3-5| = 1 + 0 + 2 = 3,
+result[2] = |5-2| + |5-3| + |5-5| = 3 + 2 + 0 = 5.
+
+ +

Example 2:

+ +
Input: nums = [1,4,6,8,10]
+Output: [24,15,13,15,21]
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= nums[i + 1] <= 104
  • +
+
\ No newline at end of file diff --git a/1688-count-of-matches-in-tournament/1688-count-of-matches-in-tournament.py b/problems/1688-count-of-matches-in-tournament/1688-count-of-matches-in-tournament.py similarity index 100% rename from 1688-count-of-matches-in-tournament/1688-count-of-matches-in-tournament.py rename to problems/1688-count-of-matches-in-tournament/1688-count-of-matches-in-tournament.py diff --git a/1688-count-of-matches-in-tournament/NOTES.md b/problems/1688-count-of-matches-in-tournament/NOTES.md similarity index 100% rename from 1688-count-of-matches-in-tournament/NOTES.md rename to problems/1688-count-of-matches-in-tournament/NOTES.md diff --git a/problems/1688-count-of-matches-in-tournament/README.md b/problems/1688-count-of-matches-in-tournament/README.md new file mode 100644 index 000000000..9994faf59 --- /dev/null +++ b/problems/1688-count-of-matches-in-tournament/README.md @@ -0,0 +1,40 @@ +

1688. Count of Matches in Tournament

Easy


You are given an integer n, the number of teams in a tournament that has strange rules:

+ +
    +
  • If the current number of teams is even, each team gets paired with another team. A total of n / 2 matches are played, and n / 2 teams advance to the next round.
  • +
  • If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance to the next round.
  • +
+ +

Return the number of matches played in the tournament until a winner is decided.

+ +

 

+

Example 1:

+ +
Input: n = 7
+Output: 6
+Explanation: Details of the tournament: 
+- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
+- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
+- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
+Total number of matches = 3 + 2 + 1 = 6.
+
+ +

Example 2:

+ +
Input: n = 14
+Output: 13
+Explanation: Details of the tournament:
+- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
+- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
+- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
+- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
+Total number of matches = 7 + 3 + 2 + 1 = 13.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 200
  • +
+
\ No newline at end of file diff --git a/1700-number-of-students-unable-to-eat-lunch/1700-number-of-students-unable-to-eat-lunch.py b/problems/1700-number-of-students-unable-to-eat-lunch/1700-number-of-students-unable-to-eat-lunch.py similarity index 100% rename from 1700-number-of-students-unable-to-eat-lunch/1700-number-of-students-unable-to-eat-lunch.py rename to problems/1700-number-of-students-unable-to-eat-lunch/1700-number-of-students-unable-to-eat-lunch.py diff --git a/1700-number-of-students-unable-to-eat-lunch/NOTES.md b/problems/1700-number-of-students-unable-to-eat-lunch/NOTES.md similarity index 100% rename from 1700-number-of-students-unable-to-eat-lunch/NOTES.md rename to problems/1700-number-of-students-unable-to-eat-lunch/NOTES.md diff --git a/problems/1700-number-of-students-unable-to-eat-lunch/README.md b/problems/1700-number-of-students-unable-to-eat-lunch/README.md new file mode 100644 index 000000000..6d5621602 --- /dev/null +++ b/problems/1700-number-of-students-unable-to-eat-lunch/README.md @@ -0,0 +1,46 @@ +

1700. Number of Students Unable to Eat Lunch

Easy


The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.

+ +

The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a stack. At each step:

+ +
    +
  • If the student at the front of the queue prefers the sandwich on the top of the stack, they will take it and leave the queue.
  • +
  • Otherwise, they will leave it and go to the queue's end.
  • +
+ +

This continues until none of the queue students want to take the top sandwich and are thus unable to eat.

+ +

You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the i​​​​​​th sandwich in the stack (i = 0 is the top of the stack) and students[j] is the preference of the j​​​​​​th student in the initial queue (j = 0 is the front of the queue). Return the number of students that are unable to eat.

+ +

 

+

Example 1:

+ +
Input: students = [1,1,0,0], sandwiches = [0,1,0,1]
+Output: 0 
+Explanation:
+- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].
+- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].
+- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].
+- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].
+- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].
+- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].
+- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].
+- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].
+Hence all students are able to eat.
+
+ +

Example 2:

+ +
Input: students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= students.length, sandwiches.length <= 100
  • +
  • students.length == sandwiches.length
  • +
  • sandwiches[i] is 0 or 1.
  • +
  • students[i] is 0 or 1.
  • +
+
\ No newline at end of file diff --git a/1701-average-waiting-time/1701-average-waiting-time.py b/problems/1701-average-waiting-time/1701-average-waiting-time.py similarity index 100% rename from 1701-average-waiting-time/1701-average-waiting-time.py rename to problems/1701-average-waiting-time/1701-average-waiting-time.py diff --git a/1701-average-waiting-time/NOTES.md b/problems/1701-average-waiting-time/NOTES.md similarity index 100% rename from 1701-average-waiting-time/NOTES.md rename to problems/1701-average-waiting-time/NOTES.md diff --git a/problems/1701-average-waiting-time/README.md b/problems/1701-average-waiting-time/README.md new file mode 100644 index 000000000..1bc0b3660 --- /dev/null +++ b/problems/1701-average-waiting-time/README.md @@ -0,0 +1,44 @@ +

1701. Average Waiting Time

Medium


There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]:

+ +
    +
  • arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order.
  • +
  • timei is the time needed to prepare the order of the ith customer.
  • +
+ +

When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input.

+ +

Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted.

+ +

 

+

Example 1:

+ +
Input: customers = [[1,2],[2,5],[4,3]]
+Output: 5.00000
+Explanation:
+1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.
+2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.
+3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.
+So the average waiting time = (2 + 6 + 7) / 3 = 5.
+
+ +

Example 2:

+ +
Input: customers = [[5,2],[5,4],[10,3],[20,1]]
+Output: 3.25000
+Explanation:
+1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.
+2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.
+3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.
+4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.
+So the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= customers.length <= 105
  • +
  • 1 <= arrivali, timei <= 104
  • +
  • arrival<= arrivali+1
  • +
+
\ No newline at end of file diff --git a/1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.py b/problems/1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.py similarity index 100% rename from 1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.py rename to problems/1704-determine-if-string-halves-are-alike/1704-determine-if-string-halves-are-alike.py diff --git a/1704-determine-if-string-halves-are-alike/NOTES.md b/problems/1704-determine-if-string-halves-are-alike/NOTES.md similarity index 100% rename from 1704-determine-if-string-halves-are-alike/NOTES.md rename to problems/1704-determine-if-string-halves-are-alike/NOTES.md diff --git a/problems/1704-determine-if-string-halves-are-alike/README.md b/problems/1704-determine-if-string-halves-are-alike/README.md new file mode 100644 index 000000000..a3be67872 --- /dev/null +++ b/problems/1704-determine-if-string-halves-are-alike/README.md @@ -0,0 +1,31 @@ +

1704. Determine if String Halves Are Alike

Easy


You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.

+ +

Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.

+ +

Return true if a and b are alike. Otherwise, return false.

+ +

 

+

Example 1:

+ +
Input: s = "book"
+Output: true
+Explanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel. Therefore, they are alike.
+
+ +

Example 2:

+ +
Input: s = "textbook"
+Output: false
+Explanation: a = "text" and b = "book". a has 1 vowel whereas b has 2. Therefore, they are not alike.
+Notice that the vowel o is counted twice.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= s.length <= 1000
  • +
  • s.length is even.
  • +
  • s consists of uppercase and lowercase letters.
  • +
+
\ No newline at end of file diff --git a/1716-calculate-money-in-leetcode-bank/1716-calculate-money-in-leetcode-bank.py b/problems/1716-calculate-money-in-leetcode-bank/1716-calculate-money-in-leetcode-bank.py similarity index 100% rename from 1716-calculate-money-in-leetcode-bank/1716-calculate-money-in-leetcode-bank.py rename to problems/1716-calculate-money-in-leetcode-bank/1716-calculate-money-in-leetcode-bank.py diff --git a/1716-calculate-money-in-leetcode-bank/NOTES.md b/problems/1716-calculate-money-in-leetcode-bank/NOTES.md similarity index 100% rename from 1716-calculate-money-in-leetcode-bank/NOTES.md rename to problems/1716-calculate-money-in-leetcode-bank/NOTES.md diff --git a/problems/1716-calculate-money-in-leetcode-bank/README.md b/problems/1716-calculate-money-in-leetcode-bank/README.md new file mode 100644 index 000000000..3ebe921b5 --- /dev/null +++ b/problems/1716-calculate-money-in-leetcode-bank/README.md @@ -0,0 +1,35 @@ +

1716. Calculate Money in Leetcode Bank

Easy


Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.

+ +

He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.

+ +

Given n, return the total amount of money he will have in the Leetcode bank at the end of the nth day.

+ +

 

+

Example 1:

+ +
Input: n = 4
+Output: 10
+Explanation: After the 4th day, the total is 1 + 2 + 3 + 4 = 10.
+
+ +

Example 2:

+ +
Input: n = 10
+Output: 37
+Explanation: After the 10th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4) = 37. Notice that on the 2nd Monday, Hercy only puts in $2.
+
+ +

Example 3:

+ +
Input: n = 20
+Output: 96
+Explanation: After the 20th day, the total is (1 + 2 + 3 + 4 + 5 + 6 + 7) + (2 + 3 + 4 + 5 + 6 + 7 + 8) + (3 + 4 + 5 + 6 + 7 + 8) = 96.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1000
  • +
+
\ No newline at end of file diff --git a/1717-maximum-score-from-removing-substrings/1717-maximum-score-from-removing-substrings.py b/problems/1717-maximum-score-from-removing-substrings/1717-maximum-score-from-removing-substrings.py similarity index 100% rename from 1717-maximum-score-from-removing-substrings/1717-maximum-score-from-removing-substrings.py rename to problems/1717-maximum-score-from-removing-substrings/1717-maximum-score-from-removing-substrings.py diff --git a/1717-maximum-score-from-removing-substrings/NOTES.md b/problems/1717-maximum-score-from-removing-substrings/NOTES.md similarity index 100% rename from 1717-maximum-score-from-removing-substrings/NOTES.md rename to problems/1717-maximum-score-from-removing-substrings/NOTES.md diff --git a/problems/1717-maximum-score-from-removing-substrings/README.md b/problems/1717-maximum-score-from-removing-substrings/README.md new file mode 100644 index 000000000..5cb76a0df --- /dev/null +++ b/problems/1717-maximum-score-from-removing-substrings/README.md @@ -0,0 +1,45 @@ +

1717. Maximum Score From Removing Substrings

Medium


You are given a string s and two integers x and y. You can perform two types of operations any number of times.

+ +
    +
  • Remove substring "ab" and gain x points. + +
      +
    • For example, when removing "ab" from "cabxbae" it becomes "cxbae".
    • +
    +
  • +
  • Remove substring "ba" and gain y points. +
      +
    • For example, when removing "ba" from "cabxbae" it becomes "cabxe".
    • +
    +
  • +
+ +

Return the maximum points you can gain after applying the above operations on s.

+ +

 

+

Example 1:

+ +
Input: s = "cdbcbbaaabab", x = 4, y = 5
+Output: 19
+Explanation:
+- Remove the "ba" underlined in "cdbcbbaaabab". Now, s = "cdbcbbaaab" and 5 points are added to the score.
+- Remove the "ab" underlined in "cdbcbbaaab". Now, s = "cdbcbbaa" and 4 points are added to the score.
+- Remove the "ba" underlined in "cdbcbbaa". Now, s = "cdbcba" and 5 points are added to the score.
+- Remove the "ba" underlined in "cdbcba". Now, s = "cdbc" and 5 points are added to the score.
+Total score = 5 + 4 + 5 + 5 = 19.
+ +

Example 2:

+ +
Input: s = "aabbaaxybbaabb", x = 5, y = 4
+Output: 20
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • 1 <= x, y <= 104
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1727-largest-submatrix-with-rearrangements/1727-largest-submatrix-with-rearrangements.py b/problems/1727-largest-submatrix-with-rearrangements/1727-largest-submatrix-with-rearrangements.py similarity index 100% rename from 1727-largest-submatrix-with-rearrangements/1727-largest-submatrix-with-rearrangements.py rename to problems/1727-largest-submatrix-with-rearrangements/1727-largest-submatrix-with-rearrangements.py diff --git a/1727-largest-submatrix-with-rearrangements/NOTES.md b/problems/1727-largest-submatrix-with-rearrangements/NOTES.md similarity index 100% rename from 1727-largest-submatrix-with-rearrangements/NOTES.md rename to problems/1727-largest-submatrix-with-rearrangements/NOTES.md diff --git a/problems/1727-largest-submatrix-with-rearrangements/README.md b/problems/1727-largest-submatrix-with-rearrangements/README.md new file mode 100644 index 000000000..e30720f4f --- /dev/null +++ b/problems/1727-largest-submatrix-with-rearrangements/README.md @@ -0,0 +1,38 @@ +

1727. Largest Submatrix With Rearrangements

Medium


You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.

+ +

Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.

+ +

 

+

Example 1:

+ +
Input: matrix = [[0,0,1],[1,1,1],[1,0,1]]
+Output: 4
+Explanation: You can rearrange the columns as shown above.
+The largest submatrix of 1s, in bold, has an area of 4.
+
+ +

Example 2:

+ +
Input: matrix = [[1,0,1,0,1]]
+Output: 3
+Explanation: You can rearrange the columns as shown above.
+The largest submatrix of 1s, in bold, has an area of 3.
+
+ +

Example 3:

+ +
Input: matrix = [[1,1,0],[1,0,1]]
+Output: 2
+Explanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2.
+
+ +

 

+

Constraints:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m * n <= 105
  • +
  • matrix[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/1740-find-distance-in-a-binary-tree/1740-find-distance-in-a-binary-tree.py b/problems/1740-find-distance-in-a-binary-tree/1740-find-distance-in-a-binary-tree.py similarity index 100% rename from 1740-find-distance-in-a-binary-tree/1740-find-distance-in-a-binary-tree.py rename to problems/1740-find-distance-in-a-binary-tree/1740-find-distance-in-a-binary-tree.py diff --git a/1740-find-distance-in-a-binary-tree/NOTES.md b/problems/1740-find-distance-in-a-binary-tree/NOTES.md similarity index 100% rename from 1740-find-distance-in-a-binary-tree/NOTES.md rename to problems/1740-find-distance-in-a-binary-tree/NOTES.md diff --git a/problems/1740-find-distance-in-a-binary-tree/README.md b/problems/1740-find-distance-in-a-binary-tree/README.md new file mode 100644 index 000000000..e02de46ad --- /dev/null +++ b/problems/1740-find-distance-in-a-binary-tree/README.md @@ -0,0 +1,33 @@ +

1740. Find Distance in a Binary Tree

Medium


Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree.

+ +

The distance between two nodes is the number of edges on the path from one to the other.

+ +

 

+

Example 1:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 0
+Output: 3
+Explanation: There are 3 edges between 5 and 0: 5-3-1-0.
+ +

Example 2:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 7
+Output: 2
+Explanation: There are 2 edges between 5 and 7: 5-2-7.
+ +

Example 3:

+ +
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 5
+Output: 0
+Explanation: The distance between a node and itself is 0.
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 104].
  • +
  • 0 <= Node.val <= 109
  • +
  • All Node.val are unique.
  • +
  • p and q are values in the tree.
  • +
+
\ No newline at end of file diff --git a/1743-restore-the-array-from-adjacent-pairs/1743-restore-the-array-from-adjacent-pairs.py b/problems/1743-restore-the-array-from-adjacent-pairs/1743-restore-the-array-from-adjacent-pairs.py similarity index 100% rename from 1743-restore-the-array-from-adjacent-pairs/1743-restore-the-array-from-adjacent-pairs.py rename to problems/1743-restore-the-array-from-adjacent-pairs/1743-restore-the-array-from-adjacent-pairs.py diff --git a/1743-restore-the-array-from-adjacent-pairs/NOTES.md b/problems/1743-restore-the-array-from-adjacent-pairs/NOTES.md similarity index 100% rename from 1743-restore-the-array-from-adjacent-pairs/NOTES.md rename to problems/1743-restore-the-array-from-adjacent-pairs/NOTES.md diff --git a/problems/1743-restore-the-array-from-adjacent-pairs/README.md b/problems/1743-restore-the-array-from-adjacent-pairs/README.md new file mode 100644 index 000000000..0c83a514a --- /dev/null +++ b/problems/1743-restore-the-array-from-adjacent-pairs/README.md @@ -0,0 +1,43 @@ +

1743. Restore the Array From Adjacent Pairs

Medium


There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.

+ +

You are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums.

+ +

It is guaranteed that every adjacent pair of elements nums[i] and nums[i+1] will exist in adjacentPairs, either as [nums[i], nums[i+1]] or [nums[i+1], nums[i]]. The pairs can appear in any order.

+ +

Return the original array nums. If there are multiple solutions, return any of them.

+ +

 

+

Example 1:

+ +
Input: adjacentPairs = [[2,1],[3,4],[3,2]]
+Output: [1,2,3,4]
+Explanation: This array has all its adjacent pairs in adjacentPairs.
+Notice that adjacentPairs[i] may not be in left-to-right order.
+
+ +

Example 2:

+ +
Input: adjacentPairs = [[4,-2],[1,4],[-3,1]]
+Output: [-2,4,1,-3]
+Explanation: There can be negative numbers.
+Another solution is [-3,1,4,-2], which would also be accepted.
+
+ +

Example 3:

+ +
Input: adjacentPairs = [[100000,-100000]]
+Output: [100000,-100000]
+
+ +

 

+

Constraints:

+ +
    +
  • nums.length == n
  • +
  • adjacentPairs.length == n - 1
  • +
  • adjacentPairs[i].length == 2
  • +
  • 2 <= n <= 105
  • +
  • -105 <= nums[i], ui, vi <= 105
  • +
  • There exists some nums that has adjacentPairs as its pairs.
  • +
+
\ No newline at end of file diff --git a/1750-minimum-length-of-string-after-deleting-similar-ends/1750-minimum-length-of-string-after-deleting-similar-ends.py b/problems/1750-minimum-length-of-string-after-deleting-similar-ends/1750-minimum-length-of-string-after-deleting-similar-ends.py similarity index 100% rename from 1750-minimum-length-of-string-after-deleting-similar-ends/1750-minimum-length-of-string-after-deleting-similar-ends.py rename to problems/1750-minimum-length-of-string-after-deleting-similar-ends/1750-minimum-length-of-string-after-deleting-similar-ends.py diff --git a/1750-minimum-length-of-string-after-deleting-similar-ends/NOTES.md b/problems/1750-minimum-length-of-string-after-deleting-similar-ends/NOTES.md similarity index 100% rename from 1750-minimum-length-of-string-after-deleting-similar-ends/NOTES.md rename to problems/1750-minimum-length-of-string-after-deleting-similar-ends/NOTES.md diff --git a/problems/1750-minimum-length-of-string-after-deleting-similar-ends/README.md b/problems/1750-minimum-length-of-string-after-deleting-similar-ends/README.md new file mode 100644 index 000000000..c64aa7976 --- /dev/null +++ b/problems/1750-minimum-length-of-string-after-deleting-similar-ends/README.md @@ -0,0 +1,47 @@ +

1750. Minimum Length of String After Deleting Similar Ends

Medium


Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:

+ +
    +
  1. Pick a non-empty prefix from the string s where all the characters in the prefix are equal.
  2. +
  3. Pick a non-empty suffix from the string s where all the characters in this suffix are equal.
  4. +
  5. The prefix and the suffix should not intersect at any index.
  6. +
  7. The characters from the prefix and suffix must be the same.
  8. +
  9. Delete both the prefix and the suffix.
  10. +
+ +

Return the minimum length of s after performing the above operation any number of times (possibly zero times).

+ +

 

+

Example 1:

+ +
Input: s = "ca"
+Output: 2
+Explanation: You can't remove any characters, so the string stays as is.
+
+ +

Example 2:

+ +
Input: s = "cabaabac"
+Output: 0
+Explanation: An optimal sequence of operations is:
+- Take prefix = "c" and suffix = "c" and remove them, s = "abaaba".
+- Take prefix = "a" and suffix = "a" and remove them, s = "baab".
+- Take prefix = "b" and suffix = "b" and remove them, s = "aa".
+- Take prefix = "a" and suffix = "a" and remove them, s = "".
+ +

Example 3:

+ +
Input: s = "aabccabba"
+Output: 3
+Explanation: An optimal sequence of operations is:
+- Take prefix = "aa" and suffix = "a" and remove them, s = "bccabb".
+- Take prefix = "b" and suffix = "bb" and remove them, s = "cca".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s only consists of characters 'a', 'b', and 'c'.
  • +
+
\ No newline at end of file diff --git a/1757-recyclable-and-low-fat-products/1757-recyclable-and-low-fat-products.sql b/problems/1757-recyclable-and-low-fat-products/1757-recyclable-and-low-fat-products.sql similarity index 100% rename from 1757-recyclable-and-low-fat-products/1757-recyclable-and-low-fat-products.sql rename to problems/1757-recyclable-and-low-fat-products/1757-recyclable-and-low-fat-products.sql diff --git a/1757-recyclable-and-low-fat-products/NOTES.md b/problems/1757-recyclable-and-low-fat-products/NOTES.md similarity index 100% rename from 1757-recyclable-and-low-fat-products/NOTES.md rename to problems/1757-recyclable-and-low-fat-products/NOTES.md diff --git a/problems/1757-recyclable-and-low-fat-products/README.md b/problems/1757-recyclable-and-low-fat-products/README.md new file mode 100644 index 000000000..24f669f17 --- /dev/null +++ b/problems/1757-recyclable-and-low-fat-products/README.md @@ -0,0 +1,45 @@ +

1757. Recyclable and Low Fat Products

Easy


Table: Products

+ +
+-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| product_id  | int     |
+| low_fats    | enum    |
+| recyclable  | enum    |
++-------------+---------+
+In SQL, product_id is the primary key for this table.
+low_fats is an ENUM of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
+recyclable is an ENUM of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
+ +

 

+ +

Find the ids of products that are both low fat and recyclable.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
Input: 
+Products table:
++-------------+----------+------------+
+| product_id  | low_fats | recyclable |
++-------------+----------+------------+
+| 0           | Y        | N          |
+| 1           | Y        | Y          |
+| 2           | N        | Y          |
+| 3           | Y        | Y          |
+| 4           | N        | N          |
++-------------+----------+------------+
+Output: 
++-------------+
+| product_id  |
++-------------+
+| 1           |
+| 3           |
++-------------+
+Explanation: Only products 1 and 3 are both low fat and recyclable.
+
+
\ No newline at end of file diff --git a/1758-minimum-changes-to-make-alternating-binary-string/1758-minimum-changes-to-make-alternating-binary-string.py b/problems/1758-minimum-changes-to-make-alternating-binary-string/1758-minimum-changes-to-make-alternating-binary-string.py similarity index 100% rename from 1758-minimum-changes-to-make-alternating-binary-string/1758-minimum-changes-to-make-alternating-binary-string.py rename to problems/1758-minimum-changes-to-make-alternating-binary-string/1758-minimum-changes-to-make-alternating-binary-string.py diff --git a/1758-minimum-changes-to-make-alternating-binary-string/NOTES.md b/problems/1758-minimum-changes-to-make-alternating-binary-string/NOTES.md similarity index 100% rename from 1758-minimum-changes-to-make-alternating-binary-string/NOTES.md rename to problems/1758-minimum-changes-to-make-alternating-binary-string/NOTES.md diff --git a/problems/1758-minimum-changes-to-make-alternating-binary-string/README.md b/problems/1758-minimum-changes-to-make-alternating-binary-string/README.md new file mode 100644 index 000000000..960678e9d --- /dev/null +++ b/problems/1758-minimum-changes-to-make-alternating-binary-string/README.md @@ -0,0 +1,36 @@ +

1758. Minimum Changes To Make Alternating Binary String

Easy


You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.

+ +

The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not.

+ +

Return the minimum number of operations needed to make s alternating.

+ +

 

+

Example 1:

+ +
Input: s = "0100"
+Output: 1
+Explanation: If you change the last character to '1', s will be "0101", which is alternating.
+
+ +

Example 2:

+ +
Input: s = "10"
+Output: 0
+Explanation: s is already alternating.
+
+ +

Example 3:

+ +
Input: s = "1111"
+Output: 2
+Explanation: You need two operations to reach "0101" or "1010".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 104
  • +
  • s[i] is either '0' or '1'.
  • +
+
\ No newline at end of file diff --git a/1759-count-number-of-homogenous-substrings/1759-count-number-of-homogenous-substrings.py b/problems/1759-count-number-of-homogenous-substrings/1759-count-number-of-homogenous-substrings.py similarity index 100% rename from 1759-count-number-of-homogenous-substrings/1759-count-number-of-homogenous-substrings.py rename to problems/1759-count-number-of-homogenous-substrings/1759-count-number-of-homogenous-substrings.py diff --git a/problems/1759-count-number-of-homogenous-substrings/README.md b/problems/1759-count-number-of-homogenous-substrings/README.md new file mode 100644 index 000000000..2e82ed3b9 --- /dev/null +++ b/problems/1759-count-number-of-homogenous-substrings/README.md @@ -0,0 +1,40 @@ +

1759. Count Number of Homogenous Substrings

Medium


Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.

+ +

A string is homogenous if all the characters of the string are the same.

+ +

A substring is a contiguous sequence of characters within a string.

+ +

 

+

Example 1:

+ +
Input: s = "abbcccaa"
+Output: 13
+Explanation: The homogenous substrings are listed as below:
+"a"   appears 3 times.
+"aa"  appears 1 time.
+"b"   appears 2 times.
+"bb"  appears 1 time.
+"c"   appears 3 times.
+"cc"  appears 2 times.
+"ccc" appears 1 time.
+3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.
+ +

Example 2:

+ +
Input: s = "xy"
+Output: 2
+Explanation: The homogenous substrings are "x" and "y".
+ +

Example 3:

+ +
Input: s = "zzzzz"
+Output: 15
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s consists of lowercase letters.
  • +
\ No newline at end of file diff --git a/1768-merge-strings-alternately/1768-merge-strings-alternately.py b/problems/1768-merge-strings-alternately/1768-merge-strings-alternately.py similarity index 100% rename from 1768-merge-strings-alternately/1768-merge-strings-alternately.py rename to problems/1768-merge-strings-alternately/1768-merge-strings-alternately.py diff --git a/1768-merge-strings-alternately/NOTES.md b/problems/1768-merge-strings-alternately/NOTES.md similarity index 100% rename from 1768-merge-strings-alternately/NOTES.md rename to problems/1768-merge-strings-alternately/NOTES.md diff --git a/problems/1768-merge-strings-alternately/README.md b/problems/1768-merge-strings-alternately/README.md new file mode 100644 index 000000000..2d0d18985 --- /dev/null +++ b/problems/1768-merge-strings-alternately/README.md @@ -0,0 +1,42 @@ +

1768. Merge Strings Alternately

Easy


You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.

+ +

Return the merged string.

+ +

 

+

Example 1:

+ +
Input: word1 = "abc", word2 = "pqr"
+Output: "apbqcr"
+Explanation: The merged string will be merged as so:
+word1:  a   b   c
+word2:    p   q   r
+merged: a p b q c r
+
+ +

Example 2:

+ +
Input: word1 = "ab", word2 = "pqrs"
+Output: "apbqrs"
+Explanation: Notice that as word2 is longer, "rs" is appended to the end.
+word1:  a   b 
+word2:    p   q   r   s
+merged: a p b q   r   s
+
+ +

Example 3:

+ +
Input: word1 = "abcd", word2 = "pq"
+Output: "apbqcd"
+Explanation: Notice that as word1 is longer, "cd" is appended to the end.
+word1:  a   b   c   d
+word2:    p   q 
+merged: a p b q c   d
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word1.length, word2.length <= 100
  • +
  • word1 and word2 consist of lowercase English letters.
  • +
\ No newline at end of file diff --git a/1791-find-center-of-star-graph/1791-find-center-of-star-graph.py b/problems/1791-find-center-of-star-graph/1791-find-center-of-star-graph.py similarity index 100% rename from 1791-find-center-of-star-graph/1791-find-center-of-star-graph.py rename to problems/1791-find-center-of-star-graph/1791-find-center-of-star-graph.py diff --git a/problems/1791-find-center-of-star-graph/README.md b/problems/1791-find-center-of-star-graph/README.md new file mode 100644 index 000000000..fc958c584 --- /dev/null +++ b/problems/1791-find-center-of-star-graph/README.md @@ -0,0 +1,30 @@ +

1791. Find Center of Star Graph

Easy


There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.

+ +

You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.

+ +

 

+

Example 1:

+ +
Input: edges = [[1,2],[2,3],[4,2]]
+Output: 2
+Explanation: As shown in the figure above, node 2 is connected to every other node, so 2 is the center.
+
+ +

Example 2:

+ +
Input: edges = [[1,2],[5,1],[1,3],[1,4]]
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= n <= 105
  • +
  • edges.length == n - 1
  • +
  • edges[i].length == 2
  • +
  • 1 <= ui, vi <= n
  • +
  • ui != vi
  • +
  • The given edges represent a valid star graph.
  • +
+
\ No newline at end of file diff --git a/1793-maximum-score-of-a-good-subarray/1793-maximum-score-of-a-good-subarray.py b/problems/1793-maximum-score-of-a-good-subarray/1793-maximum-score-of-a-good-subarray.py similarity index 100% rename from 1793-maximum-score-of-a-good-subarray/1793-maximum-score-of-a-good-subarray.py rename to problems/1793-maximum-score-of-a-good-subarray/1793-maximum-score-of-a-good-subarray.py diff --git a/1793-maximum-score-of-a-good-subarray/NOTES.md b/problems/1793-maximum-score-of-a-good-subarray/NOTES.md similarity index 100% rename from 1793-maximum-score-of-a-good-subarray/NOTES.md rename to problems/1793-maximum-score-of-a-good-subarray/NOTES.md diff --git a/problems/1793-maximum-score-of-a-good-subarray/README.md b/problems/1793-maximum-score-of-a-good-subarray/README.md new file mode 100644 index 000000000..d32c4f68c --- /dev/null +++ b/problems/1793-maximum-score-of-a-good-subarray/README.md @@ -0,0 +1,30 @@ +

1793. Maximum Score of a Good Subarray

Hard


You are given an array of integers nums (0-indexed) and an integer k.

+ +

The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.

+ +

Return the maximum possible score of a good subarray.

+ +

 

+

Example 1:

+ +
Input: nums = [1,4,3,7,4,5], k = 3
+Output: 15
+Explanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. 
+
+ +

Example 2:

+ +
Input: nums = [5,5,4,5,4,1,1,1], k = 0
+Output: 20
+Explanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 2 * 104
  • +
  • 0 <= k < nums.length
  • +
+
\ No newline at end of file diff --git a/1802-maximum-value-at-a-given-index-in-a-bounded-array/1802-maximum-value-at-a-given-index-in-a-bounded-array.py b/problems/1802-maximum-value-at-a-given-index-in-a-bounded-array/1802-maximum-value-at-a-given-index-in-a-bounded-array.py similarity index 100% rename from 1802-maximum-value-at-a-given-index-in-a-bounded-array/1802-maximum-value-at-a-given-index-in-a-bounded-array.py rename to problems/1802-maximum-value-at-a-given-index-in-a-bounded-array/1802-maximum-value-at-a-given-index-in-a-bounded-array.py diff --git a/1802-maximum-value-at-a-given-index-in-a-bounded-array/NOTES.md b/problems/1802-maximum-value-at-a-given-index-in-a-bounded-array/NOTES.md similarity index 100% rename from 1802-maximum-value-at-a-given-index-in-a-bounded-array/NOTES.md rename to problems/1802-maximum-value-at-a-given-index-in-a-bounded-array/NOTES.md diff --git a/problems/1802-maximum-value-at-a-given-index-in-a-bounded-array/README.md b/problems/1802-maximum-value-at-a-given-index-in-a-bounded-array/README.md new file mode 100644 index 000000000..9cfd57cde --- /dev/null +++ b/problems/1802-maximum-value-at-a-given-index-in-a-bounded-array/README.md @@ -0,0 +1,37 @@ +

1802. Maximum Value at a Given Index in a Bounded Array

Medium


You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:

+ +
    +
  • nums.length == n
  • +
  • nums[i] is a positive integer where 0 <= i < n.
  • +
  • abs(nums[i] - nums[i+1]) <= 1 where 0 <= i < n-1.
  • +
  • The sum of all the elements of nums does not exceed maxSum.
  • +
  • nums[index] is maximized.
  • +
+ +

Return nums[index] of the constructed array.

+ +

Note that abs(x) equals x if x >= 0, and -x otherwise.

+ +

 

+

Example 1:

+ +
Input: n = 4, index = 2,  maxSum = 6
+Output: 2
+Explanation: nums = [1,2,2,1] is one array that satisfies all the conditions.
+There are no arrays that satisfy all the conditions and have nums[2] == 3, so 2 is the maximum nums[2].
+
+ +

Example 2:

+ +
Input: n = 6, index = 1,  maxSum = 10
+Output: 3
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= maxSum <= 109
  • +
  • 0 <= index < n
  • +
+
\ No newline at end of file diff --git a/1804-implement-trie-ii-prefix-tree/1804-implement-trie-ii-prefix-tree.py b/problems/1804-implement-trie-ii-prefix-tree/1804-implement-trie-ii-prefix-tree.py similarity index 100% rename from 1804-implement-trie-ii-prefix-tree/1804-implement-trie-ii-prefix-tree.py rename to problems/1804-implement-trie-ii-prefix-tree/1804-implement-trie-ii-prefix-tree.py diff --git a/1804-implement-trie-ii-prefix-tree/NOTES.md b/problems/1804-implement-trie-ii-prefix-tree/NOTES.md similarity index 100% rename from 1804-implement-trie-ii-prefix-tree/NOTES.md rename to problems/1804-implement-trie-ii-prefix-tree/NOTES.md diff --git a/problems/1804-implement-trie-ii-prefix-tree/README.md b/problems/1804-implement-trie-ii-prefix-tree/README.md new file mode 100644 index 000000000..bd0ffd5bd --- /dev/null +++ b/problems/1804-implement-trie-ii-prefix-tree/README.md @@ -0,0 +1,44 @@ +

1804. Implement Trie II (Prefix Tree)

Medium


A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.

+ +

Implement the Trie class:

+ +
    +
  • Trie() Initializes the trie object.
  • +
  • void insert(String word) Inserts the string word into the trie.
  • +
  • int countWordsEqualTo(String word) Returns the number of instances of the string word in the trie.
  • +
  • int countWordsStartingWith(String prefix) Returns the number of strings in the trie that have the string prefix as a prefix.
  • +
  • void erase(String word) Erases the string word from the trie.
  • +
+ +

 

+

Example 1:

+ +
Input
+["Trie", "insert", "insert", "countWordsEqualTo", "countWordsStartingWith", "erase", "countWordsEqualTo", "countWordsStartingWith", "erase", "countWordsStartingWith"]
+[[], ["apple"], ["apple"], ["apple"], ["app"], ["apple"], ["apple"], ["app"], ["apple"], ["app"]]
+Output
+[null, null, null, 2, 2, null, 1, 1, null, 0]
+
+Explanation
+Trie trie = new Trie();
+trie.insert("apple");               // Inserts "apple".
+trie.insert("apple");               // Inserts another "apple".
+trie.countWordsEqualTo("apple");    // There are two instances of "apple" so return 2.
+trie.countWordsStartingWith("app"); // "app" is a prefix of "apple" so return 2.
+trie.erase("apple");                // Erases one "apple".
+trie.countWordsEqualTo("apple");    // Now there is only one instance of "apple" so return 1.
+trie.countWordsStartingWith("app"); // return 1
+trie.erase("apple");                // Erases "apple". Now the trie is empty.
+trie.countWordsStartingWith("app"); // return 0
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word.length, prefix.length <= 2000
  • +
  • word and prefix consist only of lowercase English letters.
  • +
  • At most 3 * 104 calls in total will be made to insert, countWordsEqualTo, countWordsStartingWith, and erase.
  • +
  • It is guaranteed that for any function call to erase, the string word will exist in the trie.
  • +
+
\ No newline at end of file diff --git a/1814-count-nice-pairs-in-an-array/1814-count-nice-pairs-in-an-array.py b/problems/1814-count-nice-pairs-in-an-array/1814-count-nice-pairs-in-an-array.py similarity index 100% rename from 1814-count-nice-pairs-in-an-array/1814-count-nice-pairs-in-an-array.py rename to problems/1814-count-nice-pairs-in-an-array/1814-count-nice-pairs-in-an-array.py diff --git a/problems/1814-count-nice-pairs-in-an-array/README.md b/problems/1814-count-nice-pairs-in-an-array/README.md new file mode 100644 index 000000000..1a56ce841 --- /dev/null +++ b/problems/1814-count-nice-pairs-in-an-array/README.md @@ -0,0 +1,33 @@ +

1814. Count Nice Pairs in an Array

Medium


You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of the following conditions:

+ +
    +
  • 0 <= i < j < nums.length
  • +
  • nums[i] + rev(nums[j]) == nums[j] + rev(nums[i])
  • +
+ +

Return the number of nice pairs of indices. Since that number can be too large, return it modulo 109 + 7.

+ +

 

+

Example 1:

+ +
Input: nums = [42,11,1,97]
+Output: 2
+Explanation: The two pairs are:
+ - (0,3) : 42 + rev(97) = 42 + 79 = 121, 97 + rev(42) = 97 + 24 = 121.
+ - (1,2) : 11 + rev(1) = 11 + 1 = 12, 1 + rev(11) = 1 + 11 = 12.
+
+ +

Example 2:

+ +
Input: nums = [13,10,35,24,76]
+Output: 4
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/1823-find-the-winner-of-the-circular-game/1823-find-the-winner-of-the-circular-game.py b/problems/1823-find-the-winner-of-the-circular-game/1823-find-the-winner-of-the-circular-game.py similarity index 100% rename from 1823-find-the-winner-of-the-circular-game/1823-find-the-winner-of-the-circular-game.py rename to problems/1823-find-the-winner-of-the-circular-game/1823-find-the-winner-of-the-circular-game.py diff --git a/1823-find-the-winner-of-the-circular-game/NOTES.md b/problems/1823-find-the-winner-of-the-circular-game/NOTES.md similarity index 100% rename from 1823-find-the-winner-of-the-circular-game/NOTES.md rename to problems/1823-find-the-winner-of-the-circular-game/NOTES.md diff --git a/problems/1823-find-the-winner-of-the-circular-game/README.md b/problems/1823-find-the-winner-of-the-circular-game/README.md new file mode 100644 index 000000000..e62bea9d1 --- /dev/null +++ b/problems/1823-find-the-winner-of-the-circular-game/README.md @@ -0,0 +1,49 @@ +

1823. Find the Winner of the Circular Game

Medium


There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.

+ +

The rules of the game are as follows:

+ +
    +
  1. Start at the 1st friend.
  2. +
  3. Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.
  4. +
  5. The last friend you counted leaves the circle and loses the game.
  6. +
  7. If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.
  8. +
  9. Else, the last friend in the circle wins the game.
  10. +
+ +

Given the number of friends, n, and an integer k, return the winner of the game.

+ +

 

+

Example 1:

+ +
Input: n = 5, k = 2
+Output: 3
+Explanation: Here are the steps of the game:
+1) Start at friend 1.
+2) Count 2 friends clockwise, which are friends 1 and 2.
+3) Friend 2 leaves the circle. Next start is friend 3.
+4) Count 2 friends clockwise, which are friends 3 and 4.
+5) Friend 4 leaves the circle. Next start is friend 5.
+6) Count 2 friends clockwise, which are friends 5 and 1.
+7) Friend 1 leaves the circle. Next start is friend 3.
+8) Count 2 friends clockwise, which are friends 3 and 5.
+9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.
+ +

Example 2:

+ +
Input: n = 6, k = 5
+Output: 1
+Explanation: The friends leave in this order: 5, 4, 6, 2, 3. The winner is friend 1.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= n <= 500
  • +
+ +

 

+

Follow up:

+ +

Could you solve this problem in linear time with constant space?

+
\ No newline at end of file diff --git a/1836-remove-duplicates-from-an-unsorted-linked-list/1836-remove-duplicates-from-an-unsorted-linked-list.py b/problems/1836-remove-duplicates-from-an-unsorted-linked-list/1836-remove-duplicates-from-an-unsorted-linked-list.py similarity index 100% rename from 1836-remove-duplicates-from-an-unsorted-linked-list/1836-remove-duplicates-from-an-unsorted-linked-list.py rename to problems/1836-remove-duplicates-from-an-unsorted-linked-list/1836-remove-duplicates-from-an-unsorted-linked-list.py diff --git a/1836-remove-duplicates-from-an-unsorted-linked-list/NOTES.md b/problems/1836-remove-duplicates-from-an-unsorted-linked-list/NOTES.md similarity index 100% rename from 1836-remove-duplicates-from-an-unsorted-linked-list/NOTES.md rename to problems/1836-remove-duplicates-from-an-unsorted-linked-list/NOTES.md diff --git a/problems/1836-remove-duplicates-from-an-unsorted-linked-list/README.md b/problems/1836-remove-duplicates-from-an-unsorted-linked-list/README.md new file mode 100644 index 000000000..d0080452f --- /dev/null +++ b/problems/1836-remove-duplicates-from-an-unsorted-linked-list/README.md @@ -0,0 +1,33 @@ +

1836. Remove Duplicates From an Unsorted Linked List

Medium


Given the head of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values.

+ +

Return the linked list after the deletions.

+ +

 

+

Example 1:

+ +
Input: head = [1,2,3,2]
+Output: [1,3]
+Explanation: 2 appears twice in the linked list, so all 2's should be deleted. After deleting all 2's, we are left with [1,3].
+
+ +

Example 2:

+ +
Input: head = [2,1,1,2]
+Output: []
+Explanation: 2 and 1 both appear twice. All the elements should be deleted.
+
+ +

Example 3:

+ +
Input: head = [3,2,2,1,3,2,4]
+Output: [1,4]
+Explanation: 3 appears twice and 2 appears three times. After deleting all 3's and 2's, we are left with [1,4].
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 105]
  • +
  • 1 <= Node.val <= 105
  • +
\ No newline at end of file diff --git a/1838-frequency-of-the-most-frequent-element/1838-frequency-of-the-most-frequent-element.py b/problems/1838-frequency-of-the-most-frequent-element/1838-frequency-of-the-most-frequent-element.py similarity index 100% rename from 1838-frequency-of-the-most-frequent-element/1838-frequency-of-the-most-frequent-element.py rename to problems/1838-frequency-of-the-most-frequent-element/1838-frequency-of-the-most-frequent-element.py diff --git a/1838-frequency-of-the-most-frequent-element/NOTES.md b/problems/1838-frequency-of-the-most-frequent-element/NOTES.md similarity index 100% rename from 1838-frequency-of-the-most-frequent-element/NOTES.md rename to problems/1838-frequency-of-the-most-frequent-element/NOTES.md diff --git a/problems/1838-frequency-of-the-most-frequent-element/README.md b/problems/1838-frequency-of-the-most-frequent-element/README.md new file mode 100644 index 000000000..9347d0b0f --- /dev/null +++ b/problems/1838-frequency-of-the-most-frequent-element/README.md @@ -0,0 +1,39 @@ +

1838. Frequency of the Most Frequent Element

Medium


The frequency of an element is the number of times it occurs in an array.

+ +

You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.

+ +

Return the maximum possible frequency of an element after performing at most k operations.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,4], k = 5
+Output: 3
+Explanation: Increment the first element three times and the second element two times to make nums = [4,4,4].
+4 has a frequency of 3.
+ +

Example 2:

+ +
Input: nums = [1,4,8,13], k = 5
+Output: 2
+Explanation: There are multiple optimal solutions:
+- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.
+- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.
+- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.
+
+ +

Example 3:

+ +
Input: nums = [3,9,6], k = 2
+Output: 1
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 105
  • +
  • 1 <= k <= 105
  • +
+
\ No newline at end of file diff --git a/1845-seat-reservation-manager/1845-seat-reservation-manager.py b/problems/1845-seat-reservation-manager/1845-seat-reservation-manager.py similarity index 100% rename from 1845-seat-reservation-manager/1845-seat-reservation-manager.py rename to problems/1845-seat-reservation-manager/1845-seat-reservation-manager.py diff --git a/1845-seat-reservation-manager/NOTES.md b/problems/1845-seat-reservation-manager/NOTES.md similarity index 100% rename from 1845-seat-reservation-manager/NOTES.md rename to problems/1845-seat-reservation-manager/NOTES.md diff --git a/problems/1845-seat-reservation-manager/README.md b/problems/1845-seat-reservation-manager/README.md new file mode 100644 index 000000000..889dd7023 --- /dev/null +++ b/problems/1845-seat-reservation-manager/README.md @@ -0,0 +1,42 @@ +

1845. Seat Reservation Manager

Medium


Design a system that manages the reservation state of n seats that are numbered from 1 to n.

+ +

Implement the SeatManager class:

+ +
    +
  • SeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available.
  • +
  • int reserve() Fetches the smallest-numbered unreserved seat, reserves it, and returns its number.
  • +
  • void unreserve(int seatNumber) Unreserves the seat with the given seatNumber.
  • +
+ +

 

+

Example 1:

+ +
Input
+["SeatManager", "reserve", "reserve", "unreserve", "reserve", "reserve", "reserve", "reserve", "unreserve"]
+[[5], [], [], [2], [], [], [], [], [5]]
+Output
+[null, 1, 2, null, 2, 3, 4, 5, null]
+
+Explanation
+SeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats.
+seatManager.reserve();    // All seats are available, so return the lowest numbered seat, which is 1.
+seatManager.reserve();    // The available seats are [2,3,4,5], so return the lowest of them, which is 2.
+seatManager.unreserve(2); // Unreserve seat 2, so now the available seats are [2,3,4,5].
+seatManager.reserve();    // The available seats are [2,3,4,5], so return the lowest of them, which is 2.
+seatManager.reserve();    // The available seats are [3,4,5], so return the lowest of them, which is 3.
+seatManager.reserve();    // The available seats are [4,5], so return the lowest of them, which is 4.
+seatManager.reserve();    // The only available seat is seat 5, so return 5.
+seatManager.unreserve(5); // Unreserve seat 5, so now the available seats are [5].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 105
  • +
  • 1 <= seatNumber <= n
  • +
  • For each call to reserve, it is guaranteed that there will be at least one unreserved seat.
  • +
  • For each call to unreserve, it is guaranteed that seatNumber will be reserved.
  • +
  • At most 105 calls in total will be made to reserve and unreserve.
  • +
+
\ No newline at end of file diff --git a/1846-maximum-element-after-decreasing-and-rearranging/1846-maximum-element-after-decreasing-and-rearranging.py b/problems/1846-maximum-element-after-decreasing-and-rearranging/1846-maximum-element-after-decreasing-and-rearranging.py similarity index 100% rename from 1846-maximum-element-after-decreasing-and-rearranging/1846-maximum-element-after-decreasing-and-rearranging.py rename to problems/1846-maximum-element-after-decreasing-and-rearranging/1846-maximum-element-after-decreasing-and-rearranging.py diff --git a/1846-maximum-element-after-decreasing-and-rearranging/NOTES.md b/problems/1846-maximum-element-after-decreasing-and-rearranging/NOTES.md similarity index 100% rename from 1846-maximum-element-after-decreasing-and-rearranging/NOTES.md rename to problems/1846-maximum-element-after-decreasing-and-rearranging/NOTES.md diff --git a/problems/1846-maximum-element-after-decreasing-and-rearranging/README.md b/problems/1846-maximum-element-after-decreasing-and-rearranging/README.md new file mode 100644 index 000000000..cc83a9762 --- /dev/null +++ b/problems/1846-maximum-element-after-decreasing-and-rearranging/README.md @@ -0,0 +1,54 @@ +

1846. Maximum Element After Decreasing and Rearranging

Medium


You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:

+ +
    +
  • The value of the first element in arr must be 1.
  • +
  • The absolute difference between any 2 adjacent elements must be less than or equal to 1. In other words, abs(arr[i] - arr[i - 1]) <= 1 for each i where 1 <= i < arr.length (0-indexed). abs(x) is the absolute value of x.
  • +
+ +

There are 2 types of operations that you can perform any number of times:

+ +
    +
  • Decrease the value of any element of arr to a smaller positive integer.
  • +
  • Rearrange the elements of arr to be in any order.
  • +
+ +

Return the maximum possible value of an element in arr after performing the operations to satisfy the conditions.

+ +

 

+

Example 1:

+ +
Input: arr = [2,2,1,2,1]
+Output: 2
+Explanation: 
+We can satisfy the conditions by rearranging arr so it becomes [1,2,2,2,1].
+The largest element in arr is 2.
+
+ +

Example 2:

+ +
Input: arr = [100,1,1000]
+Output: 3
+Explanation: 
+One possible way to satisfy the conditions is by doing the following:
+1. Rearrange arr so it becomes [1,100,1000].
+2. Decrease the value of the second element to 2.
+3. Decrease the value of the third element to 3.
+Now arr = [1,2,3], which satisfies the conditions.
+The largest element in arr is 3.
+
+ +

Example 3:

+ +
Input: arr = [1,2,3,4,5]
+Output: 5
+Explanation: The array already satisfies the conditions, and the largest element is 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 105
  • +
  • 1 <= arr[i] <= 109
  • +
+
\ No newline at end of file diff --git a/1863-sum-of-all-subset-xor-totals/1863-sum-of-all-subset-xor-totals.py b/problems/1863-sum-of-all-subset-xor-totals/1863-sum-of-all-subset-xor-totals.py similarity index 100% rename from 1863-sum-of-all-subset-xor-totals/1863-sum-of-all-subset-xor-totals.py rename to problems/1863-sum-of-all-subset-xor-totals/1863-sum-of-all-subset-xor-totals.py diff --git a/problems/1863-sum-of-all-subset-xor-totals/README.md b/problems/1863-sum-of-all-subset-xor-totals/README.md new file mode 100644 index 000000000..4468942a5 --- /dev/null +++ b/problems/1863-sum-of-all-subset-xor-totals/README.md @@ -0,0 +1,56 @@ +

1863. Sum of All Subset XOR Totals

Easy


The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.

+ +
    +
  • For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.
  • +
+ +

Given an array nums, return the sum of all XOR totals for every subset of nums

+ +

Note: Subsets with the same elements should be counted multiple times.

+ +

An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3]
+Output: 6
+Explanation: The 4 subsets of [1,3] are:
+- The empty subset has an XOR total of 0.
+- [1] has an XOR total of 1.
+- [3] has an XOR total of 3.
+- [1,3] has an XOR total of 1 XOR 3 = 2.
+0 + 1 + 3 + 2 = 6
+
+ +

Example 2:

+ +
Input: nums = [5,1,6]
+Output: 28
+Explanation: The 8 subsets of [5,1,6] are:
+- The empty subset has an XOR total of 0.
+- [5] has an XOR total of 5.
+- [1] has an XOR total of 1.
+- [6] has an XOR total of 6.
+- [5,1] has an XOR total of 5 XOR 1 = 4.
+- [5,6] has an XOR total of 5 XOR 6 = 3.
+- [1,6] has an XOR total of 1 XOR 6 = 7.
+- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.
+0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28
+
+ +

Example 3:

+ +
Input: nums = [3,4,5,6,7,8]
+Output: 480
+Explanation: The sum of all XOR totals for every subset is 480.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 12
  • +
  • 1 <= nums[i] <= 20
  • +
+
\ No newline at end of file diff --git a/1870-minimum-speed-to-arrive-on-time/1870-minimum-speed-to-arrive-on-time.py b/problems/1870-minimum-speed-to-arrive-on-time/1870-minimum-speed-to-arrive-on-time.py similarity index 100% rename from 1870-minimum-speed-to-arrive-on-time/1870-minimum-speed-to-arrive-on-time.py rename to problems/1870-minimum-speed-to-arrive-on-time/1870-minimum-speed-to-arrive-on-time.py diff --git a/1870-minimum-speed-to-arrive-on-time/NOTES.md b/problems/1870-minimum-speed-to-arrive-on-time/NOTES.md similarity index 100% rename from 1870-minimum-speed-to-arrive-on-time/NOTES.md rename to problems/1870-minimum-speed-to-arrive-on-time/NOTES.md diff --git a/problems/1870-minimum-speed-to-arrive-on-time/README.md b/problems/1870-minimum-speed-to-arrive-on-time/README.md new file mode 100644 index 000000000..49497e4cc --- /dev/null +++ b/problems/1870-minimum-speed-to-arrive-on-time/README.md @@ -0,0 +1,53 @@ +

1870. Minimum Speed to Arrive on Time

Medium


You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describes the distance (in kilometers) of the ith train ride.

+ +

Each train can only depart at an integer hour, so you may need to wait in between each train ride.

+ +
    +
  • For example, if the 1st train ride takes 1.5 hours, you must wait for an additional 0.5 hours before you can depart on the 2nd train ride at the 2 hour mark.
  • +
+ +

Return the minimum positive integer speed (in kilometers per hour) that all the trains must travel at for you to reach the office on time, or -1 if it is impossible to be on time.

+ +

Tests are generated such that the answer will not exceed 107 and hour will have at most two digits after the decimal point.

+ +

 

+

Example 1:

+ +
Input: dist = [1,3,2], hour = 6
+Output: 1
+Explanation: At speed 1:
+- The first train ride takes 1/1 = 1 hour.
+- Since we are already at an integer hour, we depart immediately at the 1 hour mark. The second train takes 3/1 = 3 hours.
+- Since we are already at an integer hour, we depart immediately at the 4 hour mark. The third train takes 2/1 = 2 hours.
+- You will arrive at exactly the 6 hour mark.
+
+ +

Example 2:

+ +
Input: dist = [1,3,2], hour = 2.7
+Output: 3
+Explanation: At speed 3:
+- The first train ride takes 1/3 = 0.33333 hours.
+- Since we are not at an integer hour, we wait until the 1 hour mark to depart. The second train ride takes 3/3 = 1 hour.
+- Since we are already at an integer hour, we depart immediately at the 2 hour mark. The third train takes 2/3 = 0.66667 hours.
+- You will arrive at the 2.66667 hour mark.
+
+ +

Example 3:

+ +
Input: dist = [1,3,2], hour = 1.9
+Output: -1
+Explanation: It is impossible because the earliest the third train can depart is at the 2 hour mark.
+
+ +

 

+

Constraints:

+ +
    +
  • n == dist.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= dist[i] <= 105
  • +
  • 1 <= hour <= 109
  • +
  • There will be at most two digits after the decimal point in hour.
  • +
+
\ No newline at end of file diff --git a/1877-minimize-maximum-pair-sum-in-array/1877-minimize-maximum-pair-sum-in-array.py b/problems/1877-minimize-maximum-pair-sum-in-array/1877-minimize-maximum-pair-sum-in-array.py similarity index 100% rename from 1877-minimize-maximum-pair-sum-in-array/1877-minimize-maximum-pair-sum-in-array.py rename to problems/1877-minimize-maximum-pair-sum-in-array/1877-minimize-maximum-pair-sum-in-array.py diff --git a/1877-minimize-maximum-pair-sum-in-array/NOTES.md b/problems/1877-minimize-maximum-pair-sum-in-array/NOTES.md similarity index 100% rename from 1877-minimize-maximum-pair-sum-in-array/NOTES.md rename to problems/1877-minimize-maximum-pair-sum-in-array/NOTES.md diff --git a/problems/1877-minimize-maximum-pair-sum-in-array/README.md b/problems/1877-minimize-maximum-pair-sum-in-array/README.md new file mode 100644 index 000000000..f49c9aa10 --- /dev/null +++ b/problems/1877-minimize-maximum-pair-sum-in-array/README.md @@ -0,0 +1,41 @@ +

1877. Minimize Maximum Pair Sum in Array

Medium


The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.

+ +
    +
  • For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.
  • +
+ +

Given an array nums of even length n, pair up the elements of nums into n / 2 pairs such that:

+ +
    +
  • Each element of nums is in exactly one pair, and
  • +
  • The maximum pair sum is minimized.
  • +
+ +

Return the minimized maximum pair sum after optimally pairing up the elements.

+ +

 

+

Example 1:

+ +
Input: nums = [3,5,2,3]
+Output: 7
+Explanation: The elements can be paired up into pairs (3,3) and (5,2).
+The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.
+
+ +

Example 2:

+ +
Input: nums = [3,5,4,2,4,6]
+Output: 8
+Explanation: The elements can be paired up into pairs (3,5), (4,4), and (6,2).
+The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 2 <= n <= 105
  • +
  • n is even.
  • +
  • 1 <= nums[i] <= 105
  • +
\ No newline at end of file diff --git a/1885-count-pairs-in-two-arrays/1885-count-pairs-in-two-arrays.py b/problems/1885-count-pairs-in-two-arrays/1885-count-pairs-in-two-arrays.py similarity index 100% rename from 1885-count-pairs-in-two-arrays/1885-count-pairs-in-two-arrays.py rename to problems/1885-count-pairs-in-two-arrays/1885-count-pairs-in-two-arrays.py diff --git a/1885-count-pairs-in-two-arrays/NOTES.md b/problems/1885-count-pairs-in-two-arrays/NOTES.md similarity index 100% rename from 1885-count-pairs-in-two-arrays/NOTES.md rename to problems/1885-count-pairs-in-two-arrays/NOTES.md diff --git a/problems/1885-count-pairs-in-two-arrays/README.md b/problems/1885-count-pairs-in-two-arrays/README.md new file mode 100644 index 000000000..06e4f15a3 --- /dev/null +++ b/problems/1885-count-pairs-in-two-arrays/README.md @@ -0,0 +1,33 @@ +

1885. Count Pairs in Two Arrays

Medium


Given two integer arrays nums1 and nums2 of length n, count the pairs of indices (i, j) such that i < j and nums1[i] + nums1[j] > nums2[i] + nums2[j].

+ +

Return the number of pairs satisfying the condition.

+ +

 

+

Example 1:

+ +
Input: nums1 = [2,1,2,1], nums2 = [1,2,1,2]
+Output: 1
+Explanation: The pairs satisfying the condition are:
+- (0, 2) where 2 + 2 > 1 + 1.
+ +

Example 2:

+ +
Input: nums1 = [1,10,6,2], nums2 = [1,4,1,5]
+Output: 5
+Explanation: The pairs satisfying the condition are:
+- (0, 1) where 1 + 10 > 1 + 4.
+- (0, 2) where 1 + 6 > 1 + 1.
+- (1, 2) where 10 + 6 > 4 + 1.
+- (1, 3) where 10 + 2 > 4 + 5.
+- (2, 3) where 6 + 2 > 1 + 5.
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums1.length == nums2.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= nums1[i], nums2[i] <= 105
  • +
+
\ No newline at end of file diff --git a/1887-reduction-operations-to-make-the-array-elements-equal/1887-reduction-operations-to-make-the-array-elements-equal.py b/problems/1887-reduction-operations-to-make-the-array-elements-equal/1887-reduction-operations-to-make-the-array-elements-equal.py similarity index 100% rename from 1887-reduction-operations-to-make-the-array-elements-equal/1887-reduction-operations-to-make-the-array-elements-equal.py rename to problems/1887-reduction-operations-to-make-the-array-elements-equal/1887-reduction-operations-to-make-the-array-elements-equal.py diff --git a/1887-reduction-operations-to-make-the-array-elements-equal/NOTES.md b/problems/1887-reduction-operations-to-make-the-array-elements-equal/NOTES.md similarity index 100% rename from 1887-reduction-operations-to-make-the-array-elements-equal/NOTES.md rename to problems/1887-reduction-operations-to-make-the-array-elements-equal/NOTES.md diff --git a/problems/1887-reduction-operations-to-make-the-array-elements-equal/README.md b/problems/1887-reduction-operations-to-make-the-array-elements-equal/README.md new file mode 100644 index 000000000..a2eb1b38d --- /dev/null +++ b/problems/1887-reduction-operations-to-make-the-array-elements-equal/README.md @@ -0,0 +1,47 @@ +

1887. Reduction Operations to Make the Array Elements Equal

Medium


Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:

+ +
    +
  1. Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with the largest value, pick the smallest i.
  2. +
  3. Find the next largest value in nums strictly smaller than largest. Let its value be nextLargest.
  4. +
  5. Reduce nums[i] to nextLargest.
  6. +
+ +

Return the number of operations to make all elements in nums equal.

+ +

 

+

Example 1:

+ +
Input: nums = [5,1,3]
+Output: 3
+Explanation: It takes 3 operations to make all elements in nums equal:
+1. largest = 5 at index 0. nextLargest = 3. Reduce nums[0] to 3. nums = [3,1,3].
+2. largest = 3 at index 0. nextLargest = 1. Reduce nums[0] to 1. nums = [1,1,3].
+3. largest = 3 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1].
+
+ +

Example 2:

+ +
Input: nums = [1,1,1]
+Output: 0
+Explanation: All elements in nums are already equal.
+
+ +

Example 3:

+ +
Input: nums = [1,1,2,2,3]
+Output: 4
+Explanation: It takes 4 operations to make all elements in nums equal:
+1. largest = 3 at index 4. nextLargest = 2. Reduce nums[4] to 2. nums = [1,1,2,2,2].
+2. largest = 2 at index 2. nextLargest = 1. Reduce nums[2] to 1. nums = [1,1,1,2,2].
+3. largest = 2 at index 3. nextLargest = 1. Reduce nums[3] to 1. nums = [1,1,1,1,2].
+4. largest = 2 at index 4. nextLargest = 1. Reduce nums[4] to 1. nums = [1,1,1,1,1].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 5 * 104
  • +
  • 1 <= nums[i] <= 5 * 104
  • +
+
\ No newline at end of file diff --git a/1897-redistribute-characters-to-make-all-strings-equal/1897-redistribute-characters-to-make-all-strings-equal.py b/problems/1897-redistribute-characters-to-make-all-strings-equal/1897-redistribute-characters-to-make-all-strings-equal.py similarity index 100% rename from 1897-redistribute-characters-to-make-all-strings-equal/1897-redistribute-characters-to-make-all-strings-equal.py rename to problems/1897-redistribute-characters-to-make-all-strings-equal/1897-redistribute-characters-to-make-all-strings-equal.py diff --git a/1897-redistribute-characters-to-make-all-strings-equal/NOTES.md b/problems/1897-redistribute-characters-to-make-all-strings-equal/NOTES.md similarity index 100% rename from 1897-redistribute-characters-to-make-all-strings-equal/NOTES.md rename to problems/1897-redistribute-characters-to-make-all-strings-equal/NOTES.md diff --git a/problems/1897-redistribute-characters-to-make-all-strings-equal/README.md b/problems/1897-redistribute-characters-to-make-all-strings-equal/README.md new file mode 100644 index 000000000..a493914d0 --- /dev/null +++ b/problems/1897-redistribute-characters-to-make-all-strings-equal/README.md @@ -0,0 +1,32 @@ +

1897. Redistribute Characters to Make All Strings Equal

Easy


You are given an array of strings words (0-indexed).

+ +

In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j].

+ +

Return true if you can make every string in words equal using any number of operations, and false otherwise.

+ +

 

+

Example 1:

+ +
Input: words = ["abc","aabc","bc"]
+Output: true
+Explanation: Move the first 'a' in words[1] to the front of words[2],
+to make words[1] = "abc" and words[2] = "abc".
+All the strings are now equal to "abc", so return true.
+
+ +

Example 2:

+ +
Input: words = ["ab","a"]
+Output: false
+Explanation: It is impossible to make all the strings equal using the operation.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 100
  • +
  • 1 <= words[i].length <= 100
  • +
  • words[i] consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1903-largest-odd-number-in-string/1903-largest-odd-number-in-string.py b/problems/1903-largest-odd-number-in-string/1903-largest-odd-number-in-string.py similarity index 100% rename from 1903-largest-odd-number-in-string/1903-largest-odd-number-in-string.py rename to problems/1903-largest-odd-number-in-string/1903-largest-odd-number-in-string.py diff --git a/1903-largest-odd-number-in-string/NOTES.md b/problems/1903-largest-odd-number-in-string/NOTES.md similarity index 100% rename from 1903-largest-odd-number-in-string/NOTES.md rename to problems/1903-largest-odd-number-in-string/NOTES.md diff --git a/problems/1903-largest-odd-number-in-string/README.md b/problems/1903-largest-odd-number-in-string/README.md new file mode 100644 index 000000000..0def66fae --- /dev/null +++ b/problems/1903-largest-odd-number-in-string/README.md @@ -0,0 +1,34 @@ +

1903. Largest Odd Number in String

Easy


You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists.

+ +

A substring is a contiguous sequence of characters within a string.

+ +

 

+

Example 1:

+ +
Input: num = "52"
+Output: "5"
+Explanation: The only non-empty substrings are "5", "2", and "52". "5" is the only odd number.
+
+ +

Example 2:

+ +
Input: num = "4206"
+Output: ""
+Explanation: There are no odd numbers in "4206".
+
+ +

Example 3:

+ +
Input: num = "35427"
+Output: "35427"
+Explanation: "35427" is already an odd number.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= num.length <= 105
  • +
  • num only consists of digits and does not contain any leading zeros.
  • +
+
\ No newline at end of file diff --git a/1913-maximum-product-difference-between-two-pairs/1913-maximum-product-difference-between-two-pairs.py b/problems/1913-maximum-product-difference-between-two-pairs/1913-maximum-product-difference-between-two-pairs.py similarity index 100% rename from 1913-maximum-product-difference-between-two-pairs/1913-maximum-product-difference-between-two-pairs.py rename to problems/1913-maximum-product-difference-between-two-pairs/1913-maximum-product-difference-between-two-pairs.py diff --git a/1913-maximum-product-difference-between-two-pairs/NOTES.md b/problems/1913-maximum-product-difference-between-two-pairs/NOTES.md similarity index 100% rename from 1913-maximum-product-difference-between-two-pairs/NOTES.md rename to problems/1913-maximum-product-difference-between-two-pairs/NOTES.md diff --git a/problems/1913-maximum-product-difference-between-two-pairs/README.md b/problems/1913-maximum-product-difference-between-two-pairs/README.md new file mode 100644 index 000000000..3b05b9edb --- /dev/null +++ b/problems/1913-maximum-product-difference-between-two-pairs/README.md @@ -0,0 +1,34 @@ +

1913. Maximum Product Difference Between Two Pairs

Easy


The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).

+ +
    +
  • For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.
  • +
+ +

Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.

+ +

Return the maximum such product difference.

+ +

 

+

Example 1:

+ +
Input: nums = [5,6,2,7,4]
+Output: 34
+Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
+The product difference is (6 * 7) - (2 * 4) = 34.
+
+ +

Example 2:

+ +
Input: nums = [4,2,5,9,7,4,8]
+Output: 64
+Explanation: We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).
+The product difference is (9 * 8) - (2 * 4) = 64.
+
+ +

 

+

Constraints:

+ +
    +
  • 4 <= nums.length <= 104
  • +
  • 1 <= nums[i] <= 104
  • +
\ No newline at end of file diff --git a/1915-number-of-wonderful-substrings/1915-number-of-wonderful-substrings.py b/problems/1915-number-of-wonderful-substrings/1915-number-of-wonderful-substrings.py similarity index 100% rename from 1915-number-of-wonderful-substrings/1915-number-of-wonderful-substrings.py rename to problems/1915-number-of-wonderful-substrings/1915-number-of-wonderful-substrings.py diff --git a/problems/1915-number-of-wonderful-substrings/README.md b/problems/1915-number-of-wonderful-substrings/README.md new file mode 100644 index 000000000..c19d9e1f8 --- /dev/null +++ b/problems/1915-number-of-wonderful-substrings/README.md @@ -0,0 +1,54 @@ +

1915. Number of Wonderful Substrings

Medium


A wonderful string is a string where at most one letter appears an odd number of times.

+ +
    +
  • For example, "ccjjc" and "abab" are wonderful, but "ab" is not.
  • +
+ +

Given a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately.

+ +

A substring is a contiguous sequence of characters in a string.

+ +

 

+

Example 1:

+ +
Input: word = "aba"
+Output: 4
+Explanation: The four wonderful substrings are underlined below:
+- "aba" -> "a"
+- "aba" -> "b"
+- "aba" -> "a"
+- "aba" -> "aba"
+
+ +

Example 2:

+ +
Input: word = "aabb"
+Output: 9
+Explanation: The nine wonderful substrings are underlined below:
+- "aabb" -> "a"
+- "aabb" -> "aa"
+- "aabb" -> "aab"
+- "aabb" -> "aabb"
+- "aabb" -> "a"
+- "aabb" -> "abb"
+- "aabb" -> "b"
+- "aabb" -> "bb"
+- "aabb" -> "b"
+
+ +

Example 3:

+ +
Input: word = "he"
+Output: 2
+Explanation: The two wonderful substrings are underlined below:
+- "he" -> "h"
+- "he" -> "e"
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word.length <= 105
  • +
  • word consists of lowercase English letters from 'a' to 'j'.
  • +
\ No newline at end of file diff --git a/1920-build-array-from-permutation/1920-build-array-from-permutation.cpp b/problems/1920-build-array-from-permutation/1920-build-array-from-permutation.cpp similarity index 100% rename from 1920-build-array-from-permutation/1920-build-array-from-permutation.cpp rename to problems/1920-build-array-from-permutation/1920-build-array-from-permutation.cpp diff --git a/1920-build-array-from-permutation/NOTES.md b/problems/1920-build-array-from-permutation/NOTES.md similarity index 100% rename from 1920-build-array-from-permutation/NOTES.md rename to problems/1920-build-array-from-permutation/NOTES.md diff --git a/problems/1920-build-array-from-permutation/README.md b/problems/1920-build-array-from-permutation/README.md new file mode 100644 index 000000000..5e7e95239 --- /dev/null +++ b/problems/1920-build-array-from-permutation/README.md @@ -0,0 +1,35 @@ +

1920. Build Array from Permutation

Easy


Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.

+ +

A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).

+ +

 

+

Example 1:

+ +
Input: nums = [0,2,1,5,3,4]
+Output: [0,1,2,4,5,3]
+Explanation: The array ans is built as follows: 
+ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
+    = [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
+    = [0,1,2,4,5,3]
+ +

Example 2:

+ +
Input: nums = [5,0,1,2,3,4]
+Output: [4,5,0,1,2,3]
+Explanation: The array ans is built as follows:
+ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
+    = [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]
+    = [4,5,0,1,2,3]
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • 0 <= nums[i] < nums.length
  • +
  • The elements in nums are distinct.
  • +
+ +

 

+

Follow-up: Can you solve it without using an extra space (i.e., O(1) memory)?

+
\ No newline at end of file diff --git a/1921-eliminate-maximum-number-of-monsters/1921-eliminate-maximum-number-of-monsters.py b/problems/1921-eliminate-maximum-number-of-monsters/1921-eliminate-maximum-number-of-monsters.py similarity index 100% rename from 1921-eliminate-maximum-number-of-monsters/1921-eliminate-maximum-number-of-monsters.py rename to problems/1921-eliminate-maximum-number-of-monsters/1921-eliminate-maximum-number-of-monsters.py diff --git a/1921-eliminate-maximum-number-of-monsters/NOTES.md b/problems/1921-eliminate-maximum-number-of-monsters/NOTES.md similarity index 100% rename from 1921-eliminate-maximum-number-of-monsters/NOTES.md rename to problems/1921-eliminate-maximum-number-of-monsters/NOTES.md diff --git a/problems/1921-eliminate-maximum-number-of-monsters/README.md b/problems/1921-eliminate-maximum-number-of-monsters/README.md new file mode 100644 index 000000000..53ce33378 --- /dev/null +++ b/problems/1921-eliminate-maximum-number-of-monsters/README.md @@ -0,0 +1,50 @@ +

1921. Eliminate Maximum Number of Monsters

Medium


You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the ith monster from the city.

+ +

The monsters walk toward the city at a constant speed. The speed of each monster is given to you in an integer array speed of size n, where speed[i] is the speed of the ith monster in kilometers per minute.

+ +

You have a weapon that, once fully charged, can eliminate a single monster. However, the weapon takes one minute to charge. The weapon is fully charged at the very start.

+ +

You lose when any monster reaches your city. If a monster reaches the city at the exact moment the weapon is fully charged, it counts as a loss, and the game ends before you can use your weapon.

+ +

Return the maximum number of monsters that you can eliminate before you lose, or n if you can eliminate all the monsters before they reach the city.

+ +

 

+

Example 1:

+ +
Input: dist = [1,3,4], speed = [1,1,1]
+Output: 3
+Explanation:
+In the beginning, the distances of the monsters are [1,3,4]. You eliminate the first monster.
+After a minute, the distances of the monsters are [X,2,3]. You eliminate the second monster.
+After a minute, the distances of the monsters are [X,X,2]. You eliminate the thrid monster.
+All 3 monsters can be eliminated.
+ +

Example 2:

+ +
Input: dist = [1,1,2,3], speed = [1,1,1,1]
+Output: 1
+Explanation:
+In the beginning, the distances of the monsters are [1,1,2,3]. You eliminate the first monster.
+After a minute, the distances of the monsters are [X,0,1,2], so you lose.
+You can only eliminate 1 monster.
+
+ +

Example 3:

+ +
Input: dist = [3,2,4], speed = [5,3,2]
+Output: 1
+Explanation:
+In the beginning, the distances of the monsters are [3,2,4]. You eliminate the first monster.
+After a minute, the distances of the monsters are [X,0,2], so you lose.
+You can only eliminate 1 monster.
+
+ +

 

+

Constraints:

+ +
    +
  • n == dist.length == speed.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= dist[i], speed[i] <= 105
  • +
+
\ No newline at end of file diff --git a/1930-unique-length-3-palindromic-subsequences/1930-unique-length-3-palindromic-subsequences.py b/problems/1930-unique-length-3-palindromic-subsequences/1930-unique-length-3-palindromic-subsequences.py similarity index 100% rename from 1930-unique-length-3-palindromic-subsequences/1930-unique-length-3-palindromic-subsequences.py rename to problems/1930-unique-length-3-palindromic-subsequences/1930-unique-length-3-palindromic-subsequences.py diff --git a/1930-unique-length-3-palindromic-subsequences/NOTES.md b/problems/1930-unique-length-3-palindromic-subsequences/NOTES.md similarity index 100% rename from 1930-unique-length-3-palindromic-subsequences/NOTES.md rename to problems/1930-unique-length-3-palindromic-subsequences/NOTES.md diff --git a/problems/1930-unique-length-3-palindromic-subsequences/README.md b/problems/1930-unique-length-3-palindromic-subsequences/README.md new file mode 100644 index 000000000..099bc405d --- /dev/null +++ b/problems/1930-unique-length-3-palindromic-subsequences/README.md @@ -0,0 +1,49 @@ +

1930. Unique Length-3 Palindromic Subsequences

Medium


Given a string s, return the number of unique palindromes of length three that are a subsequence of s.

+ +

Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once.

+ +

A palindrome is a string that reads the same forwards and backwards.

+ +

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

+ +
    +
  • For example, "ace" is a subsequence of "abcde".
  • +
+ +

 

+

Example 1:

+ +
Input: s = "aabca"
+Output: 3
+Explanation: The 3 palindromic subsequences of length 3 are:
+- "aba" (subsequence of "aabca")
+- "aaa" (subsequence of "aabca")
+- "aca" (subsequence of "aabca")
+
+ +

Example 2:

+ +
Input: s = "adc"
+Output: 0
+Explanation: There are no palindromic subsequences of length 3 in "adc".
+
+ +

Example 3:

+ +
Input: s = "bbcbaba"
+Output: 4
+Explanation: The 4 palindromic subsequences of length 3 are:
+- "bbb" (subsequence of "bbcbaba")
+- "bcb" (subsequence of "bbcbaba")
+- "bab" (subsequence of "bbcbaba")
+- "aba" (subsequence of "bbcbaba")
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= s.length <= 105
  • +
  • s consists of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/1937-maximum-number-of-points-with-cost/1937-maximum-number-of-points-with-cost.py b/problems/1937-maximum-number-of-points-with-cost/1937-maximum-number-of-points-with-cost.py similarity index 100% rename from 1937-maximum-number-of-points-with-cost/1937-maximum-number-of-points-with-cost.py rename to problems/1937-maximum-number-of-points-with-cost/1937-maximum-number-of-points-with-cost.py diff --git a/1937-maximum-number-of-points-with-cost/NOTES.md b/problems/1937-maximum-number-of-points-with-cost/NOTES.md similarity index 100% rename from 1937-maximum-number-of-points-with-cost/NOTES.md rename to problems/1937-maximum-number-of-points-with-cost/NOTES.md diff --git a/problems/1937-maximum-number-of-points-with-cost/README.md b/problems/1937-maximum-number-of-points-with-cost/README.md new file mode 100644 index 000000000..d07098621 --- /dev/null +++ b/problems/1937-maximum-number-of-points-with-cost/README.md @@ -0,0 +1,49 @@ +

1937. Maximum Number of Points with Cost

Medium


You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix.

+ +

To gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score.

+ +

However, you will lose points if you pick a cell too far from the cell that you picked in the previous row. For every two adjacent rows r and r + 1 (where 0 <= r < m - 1), picking cells at coordinates (r, c1) and (r + 1, c2) will subtract abs(c1 - c2) from your score.

+ +

Return the maximum number of points you can achieve.

+ +

abs(x) is defined as:

+ +
    +
  • x for x >= 0.
  • +
  • -x for x < 0.
  • +
+ +

 

+

Example 1:

+ +
Input: points = [[1,2,3],[1,5,1],[3,1,1]]
+Output: 9
+Explanation:
+The blue cells denote the optimal cells to pick, which have coordinates (0, 2), (1, 1), and (2, 0).
+You add 3 + 5 + 3 = 11 to your score.
+However, you must subtract abs(2 - 1) + abs(1 - 0) = 2 from your score.
+Your final score is 11 - 2 = 9.
+
+ +

Example 2:

+ +
Input: points = [[1,5],[2,3],[4,2]]
+Output: 11
+Explanation:
+The blue cells denote the optimal cells to pick, which have coordinates (0, 1), (1, 1), and (2, 0).
+You add 5 + 3 + 4 = 12 to your score.
+However, you must subtract abs(1 - 1) + abs(1 - 0) = 1 from your score.
+Your final score is 12 - 1 = 11.
+
+ +

 

+

Constraints:

+ +
    +
  • m == points.length
  • +
  • n == points[r].length
  • +
  • 1 <= m, n <= 105
  • +
  • 1 <= m * n <= 105
  • +
  • 0 <= points[r][c] <= 105
  • +
+
\ No newline at end of file diff --git a/1940-longest-common-subsequence-between-sorted-arrays/1940-longest-common-subsequence-between-sorted-arrays.py b/problems/1940-longest-common-subsequence-between-sorted-arrays/1940-longest-common-subsequence-between-sorted-arrays.py similarity index 100% rename from 1940-longest-common-subsequence-between-sorted-arrays/1940-longest-common-subsequence-between-sorted-arrays.py rename to problems/1940-longest-common-subsequence-between-sorted-arrays/1940-longest-common-subsequence-between-sorted-arrays.py diff --git a/1940-longest-common-subsequence-between-sorted-arrays/NOTES.md b/problems/1940-longest-common-subsequence-between-sorted-arrays/NOTES.md similarity index 100% rename from 1940-longest-common-subsequence-between-sorted-arrays/NOTES.md rename to problems/1940-longest-common-subsequence-between-sorted-arrays/NOTES.md diff --git a/problems/1940-longest-common-subsequence-between-sorted-arrays/README.md b/problems/1940-longest-common-subsequence-between-sorted-arrays/README.md new file mode 100644 index 000000000..57a49d48b --- /dev/null +++ b/problems/1940-longest-common-subsequence-between-sorted-arrays/README.md @@ -0,0 +1,40 @@ +

1940. Longest Common Subsequence Between Sorted Arrays

Medium


Given an array of integer arrays arrays where each arrays[i] is sorted in strictly increasing order, return an integer array representing the longest common subsequence between all the arrays.

+ +

A subsequence is a sequence that can be derived from another sequence by deleting some elements (possibly none) without changing the order of the remaining elements.

+ +

 

+

Example 1:

+ +
Input: arrays = [[1,3,4],
+                 [1,4,7,9]]
+Output: [1,4]
+Explanation: The longest common subsequence in the two arrays is [1,4].
+
+ +

Example 2:

+ +
Input: arrays = [[2,3,6,8],
+                 [1,2,3,5,6,7,10],
+                 [2,3,4,6,9]]
+Output: [2,3,6]
+Explanation: The longest common subsequence in all three arrays is [2,3,6].
+
+ +

Example 3:

+ +
Input: arrays = [[1,2,3,4,5],
+                 [6,7,8]]
+Output: []
+Explanation: There is no common subsequence between the two arrays.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= arrays.length <= 100
  • +
  • 1 <= arrays[i].length <= 100
  • +
  • 1 <= arrays[i][j] <= 100
  • +
  • arrays[i] is sorted in strictly increasing order.
  • +
+
\ No newline at end of file diff --git a/1971-find-if-path-exists-in-graph/1971-find-if-path-exists-in-graph.py b/problems/1971-find-if-path-exists-in-graph/1971-find-if-path-exists-in-graph.py similarity index 100% rename from 1971-find-if-path-exists-in-graph/1971-find-if-path-exists-in-graph.py rename to problems/1971-find-if-path-exists-in-graph/1971-find-if-path-exists-in-graph.py diff --git a/1971-find-if-path-exists-in-graph/NOTES.md b/problems/1971-find-if-path-exists-in-graph/NOTES.md similarity index 100% rename from 1971-find-if-path-exists-in-graph/NOTES.md rename to problems/1971-find-if-path-exists-in-graph/NOTES.md diff --git a/problems/1971-find-if-path-exists-in-graph/README.md b/problems/1971-find-if-path-exists-in-graph/README.md new file mode 100644 index 000000000..d95edbe40 --- /dev/null +++ b/problems/1971-find-if-path-exists-in-graph/README.md @@ -0,0 +1,37 @@ +

1971. Find if Path Exists in Graph

Easy


There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.

+ +

You want to determine if there is a valid path that exists from vertex source to vertex destination.

+ +

Given edges and the integers n, source, and destination, return true if there is a valid path from source to destination, or false otherwise.

+ +

 

+

Example 1:

+ +
Input: n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2
+Output: true
+Explanation: There are two paths from vertex 0 to vertex 2:
+- 0 → 1 → 2
+- 0 → 2
+
+ +

Example 2:

+ +
Input: n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5
+Output: false
+Explanation: There is no path from vertex 0 to vertex 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 2 * 105
  • +
  • 0 <= edges.length <= 2 * 105
  • +
  • edges[i].length == 2
  • +
  • 0 <= ui, vi <= n - 1
  • +
  • ui != vi
  • +
  • 0 <= source, destination <= n - 1
  • +
  • There are no duplicate edges.
  • +
  • There are no self edges.
  • +
+
\ No newline at end of file diff --git a/1973-count-nodes-equal-to-sum-of-descendants/1973-count-nodes-equal-to-sum-of-descendants.py b/problems/1973-count-nodes-equal-to-sum-of-descendants/1973-count-nodes-equal-to-sum-of-descendants.py similarity index 100% rename from 1973-count-nodes-equal-to-sum-of-descendants/1973-count-nodes-equal-to-sum-of-descendants.py rename to problems/1973-count-nodes-equal-to-sum-of-descendants/1973-count-nodes-equal-to-sum-of-descendants.py diff --git a/1973-count-nodes-equal-to-sum-of-descendants/NOTES.md b/problems/1973-count-nodes-equal-to-sum-of-descendants/NOTES.md similarity index 100% rename from 1973-count-nodes-equal-to-sum-of-descendants/NOTES.md rename to problems/1973-count-nodes-equal-to-sum-of-descendants/NOTES.md diff --git a/problems/1973-count-nodes-equal-to-sum-of-descendants/README.md b/problems/1973-count-nodes-equal-to-sum-of-descendants/README.md new file mode 100644 index 000000000..b424a0165 --- /dev/null +++ b/problems/1973-count-nodes-equal-to-sum-of-descendants/README.md @@ -0,0 +1,37 @@ +

1973. Count Nodes Equal to Sum of Descendants

Medium


Given the root of a binary tree, return the number of nodes where the value of the node is equal to the sum of the values of its descendants.

+ +

A descendant of a node x is any node that is on the path from node x to some leaf node. The sum is considered to be 0 if the node has no descendants.

+ +

 

+

Example 1:

+ +
Input: root = [10,3,4,2,1]
+Output: 2
+Explanation:
+For the node with value 10: The sum of its descendants is 3+4+2+1 = 10.
+For the node with value 3: The sum of its descendants is 2+1 = 3.
+
+ +

Example 2:

+ +
Input: root = [2,3,null,2,null]
+Output: 0
+Explanation:
+No node has a value that is equal to the sum of its descendants.
+
+ +

Example 3:

+ +
Input: root = [0]
+Output: 1
+For the node with value 0: The sum of its descendants is 0 since it has no descendants.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 105].
  • +
  • 0 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/1980-find-unique-binary-string/1980-find-unique-binary-string.py b/problems/1980-find-unique-binary-string/1980-find-unique-binary-string.py similarity index 100% rename from 1980-find-unique-binary-string/1980-find-unique-binary-string.py rename to problems/1980-find-unique-binary-string/1980-find-unique-binary-string.py diff --git a/1980-find-unique-binary-string/NOTES.md b/problems/1980-find-unique-binary-string/NOTES.md similarity index 100% rename from 1980-find-unique-binary-string/NOTES.md rename to problems/1980-find-unique-binary-string/NOTES.md diff --git a/problems/1980-find-unique-binary-string/README.md b/problems/1980-find-unique-binary-string/README.md new file mode 100644 index 000000000..8cdd0a25e --- /dev/null +++ b/problems/1980-find-unique-binary-string/README.md @@ -0,0 +1,35 @@ +

1980. Find Unique Binary String

Medium


Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them.

+ +

 

+

Example 1:

+ +
Input: nums = ["01","10"]
+Output: "11"
+Explanation: "11" does not appear in nums. "00" would also be correct.
+
+ +

Example 2:

+ +
Input: nums = ["00","01"]
+Output: "11"
+Explanation: "11" does not appear in nums. "10" would also be correct.
+
+ +

Example 3:

+ +
Input: nums = ["111","011","001"]
+Output: "101"
+Explanation: "101" does not appear in nums. "000", "010", "100", and "110" would also be correct.
+
+ +

 

+

Constraints:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 16
  • +
  • nums[i].length == n
  • +
  • nums[i] is either '0' or '1'.
  • +
  • All the strings of nums are unique.
  • +
+
\ No newline at end of file diff --git a/1992-find-all-groups-of-farmland/1992-find-all-groups-of-farmland.py b/problems/1992-find-all-groups-of-farmland/1992-find-all-groups-of-farmland.py similarity index 100% rename from 1992-find-all-groups-of-farmland/1992-find-all-groups-of-farmland.py rename to problems/1992-find-all-groups-of-farmland/1992-find-all-groups-of-farmland.py diff --git a/1992-find-all-groups-of-farmland/NOTES.md b/problems/1992-find-all-groups-of-farmland/NOTES.md similarity index 100% rename from 1992-find-all-groups-of-farmland/NOTES.md rename to problems/1992-find-all-groups-of-farmland/NOTES.md diff --git a/problems/1992-find-all-groups-of-farmland/README.md b/problems/1992-find-all-groups-of-farmland/README.md new file mode 100644 index 000000000..783ad4023 --- /dev/null +++ b/problems/1992-find-all-groups-of-farmland/README.md @@ -0,0 +1,45 @@ +

1992. Find All Groups of Farmland

Medium


You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland.

+ +

To keep the land organized, there are designated rectangular areas of hectares that consist entirely of farmland. These rectangular areas are called groups. No two groups are adjacent, meaning farmland in one group is not four-directionally adjacent to another farmland in a different group.

+ +

land can be represented by a coordinate system where the top left corner of land is (0, 0) and the bottom right corner of land is (m-1, n-1). Find the coordinates of the top left and bottom right corner of each group of farmland. A group of farmland with a top left corner at (r1, c1) and a bottom right corner at (r2, c2) is represented by the 4-length array [r1, c1, r2, c2].

+ +

Return a 2D array containing the 4-length arrays described above for each group of farmland in land. If there are no groups of farmland, return an empty array. You may return the answer in any order.

+ +

 

+

Example 1:

+ +
Input: land = [[1,0,0],[0,1,1],[0,1,1]]
+Output: [[0,0,0,0],[1,1,2,2]]
+Explanation:
+The first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].
+The second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].
+
+ +

Example 2:

+ +
Input: land = [[1,1],[1,1]]
+Output: [[0,0,1,1]]
+Explanation:
+The first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].
+
+ +

Example 3:

+ +
Input: land = [[0]]
+Output: []
+Explanation:
+There are no groups of farmland.
+
+ +

 

+

Constraints:

+ +
    +
  • m == land.length
  • +
  • n == land[i].length
  • +
  • 1 <= m, n <= 300
  • +
  • land consists of only 0's and 1's.
  • +
  • Groups of farmland are rectangular in shape.
  • +
+
\ No newline at end of file diff --git a/2000-reverse-prefix-of-word/2000-reverse-prefix-of-word.py b/problems/2000-reverse-prefix-of-word/2000-reverse-prefix-of-word.py similarity index 100% rename from 2000-reverse-prefix-of-word/2000-reverse-prefix-of-word.py rename to problems/2000-reverse-prefix-of-word/2000-reverse-prefix-of-word.py diff --git a/2000-reverse-prefix-of-word/NOTES.md b/problems/2000-reverse-prefix-of-word/NOTES.md similarity index 100% rename from 2000-reverse-prefix-of-word/NOTES.md rename to problems/2000-reverse-prefix-of-word/NOTES.md diff --git a/problems/2000-reverse-prefix-of-word/README.md b/problems/2000-reverse-prefix-of-word/README.md new file mode 100644 index 000000000..e5627c83f --- /dev/null +++ b/problems/2000-reverse-prefix-of-word/README.md @@ -0,0 +1,42 @@ +

2000. Reverse Prefix of Word

Easy


Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.

+ +
    +
  • For example, if word = "abcdefd" and ch = "d", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be "dcbaefd".
  • +
+ +

Return the resulting string.

+ +

 

+

Example 1:

+ +
Input: word = "abcdefd", ch = "d"
+Output: "dcbaefd"
+Explanation: The first occurrence of "d" is at index 3. 
+Reverse the part of word from 0 to 3 (inclusive), the resulting string is "dcbaefd".
+
+ +

Example 2:

+ +
Input: word = "xyxzxe", ch = "z"
+Output: "zxyxxe"
+Explanation: The first and only occurrence of "z" is at index 3.
+Reverse the part of word from 0 to 3 (inclusive), the resulting string is "zxyxxe".
+
+ +

Example 3:

+ +
Input: word = "abcd", ch = "z"
+Output: "abcd"
+Explanation: "z" does not exist in word.
+You should not do any reverse operation, the resulting string is "abcd".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= word.length <= 250
  • +
  • word consists of lowercase English letters.
  • +
  • ch is a lowercase English letter.
  • +
+
\ No newline at end of file diff --git a/2009-minimum-number-of-operations-to-make-array-continuous/2009-minimum-number-of-operations-to-make-array-continuous.py b/problems/2009-minimum-number-of-operations-to-make-array-continuous/2009-minimum-number-of-operations-to-make-array-continuous.py similarity index 100% rename from 2009-minimum-number-of-operations-to-make-array-continuous/2009-minimum-number-of-operations-to-make-array-continuous.py rename to problems/2009-minimum-number-of-operations-to-make-array-continuous/2009-minimum-number-of-operations-to-make-array-continuous.py diff --git a/2009-minimum-number-of-operations-to-make-array-continuous/NOTES.md b/problems/2009-minimum-number-of-operations-to-make-array-continuous/NOTES.md similarity index 100% rename from 2009-minimum-number-of-operations-to-make-array-continuous/NOTES.md rename to problems/2009-minimum-number-of-operations-to-make-array-continuous/NOTES.md diff --git a/problems/2009-minimum-number-of-operations-to-make-array-continuous/README.md b/problems/2009-minimum-number-of-operations-to-make-array-continuous/README.md new file mode 100644 index 000000000..ae26c0fca --- /dev/null +++ b/problems/2009-minimum-number-of-operations-to-make-array-continuous/README.md @@ -0,0 +1,48 @@ +

2009. Minimum Number of Operations to Make Array Continuous

Hard


You are given an integer array nums. In one operation, you can replace any element in nums with any integer.

+ +

nums is considered continuous if both of the following conditions are fulfilled:

+ +
    +
  • All elements in nums are unique.
  • +
  • The difference between the maximum element and the minimum element in nums equals nums.length - 1.
  • +
+ +

For example, nums = [4, 2, 5, 3] is continuous, but nums = [1, 2, 3, 5, 6] is not continuous.

+ +

Return the minimum number of operations to make nums continuous.

+ +

 

+

Example 1:

+ +
Input: nums = [4,2,5,3]
+Output: 0
+Explanation: nums is already continuous.
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,5,6]
+Output: 1
+Explanation: One possible solution is to change the last element to 4.
+The resulting array is [1,2,3,5,4], which is continuous.
+
+ +

Example 3:

+ +
Input: nums = [1,10,100,1000]
+Output: 3
+Explanation: One possible solution is to:
+- Change the second element to 2.
+- Change the third element to 3.
+- Change the fourth element to 4.
+The resulting array is [1,2,3,4], which is continuous.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/2037-minimum-number-of-moves-to-seat-everyone/2037-minimum-number-of-moves-to-seat-everyone.py b/problems/2037-minimum-number-of-moves-to-seat-everyone/2037-minimum-number-of-moves-to-seat-everyone.py similarity index 100% rename from 2037-minimum-number-of-moves-to-seat-everyone/2037-minimum-number-of-moves-to-seat-everyone.py rename to problems/2037-minimum-number-of-moves-to-seat-everyone/2037-minimum-number-of-moves-to-seat-everyone.py diff --git a/2037-minimum-number-of-moves-to-seat-everyone/NOTES.md b/problems/2037-minimum-number-of-moves-to-seat-everyone/NOTES.md similarity index 100% rename from 2037-minimum-number-of-moves-to-seat-everyone/NOTES.md rename to problems/2037-minimum-number-of-moves-to-seat-everyone/NOTES.md diff --git a/problems/2037-minimum-number-of-moves-to-seat-everyone/README.md b/problems/2037-minimum-number-of-moves-to-seat-everyone/README.md new file mode 100644 index 000000000..04a8e685e --- /dev/null +++ b/problems/2037-minimum-number-of-moves-to-seat-everyone/README.md @@ -0,0 +1,58 @@ +

2037. Minimum Number of Moves to Seat Everyone

Easy


There are n seats and n students in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of the jth student.

+ +

You may perform the following move any number of times:

+ +
    +
  • Increase or decrease the position of the ith student by 1 (i.e., moving the ith student from position x to x + 1 or x - 1)
  • +
+ +

Return the minimum number of moves required to move each student to a seat such that no two students are in the same seat.

+ +

Note that there may be multiple seats or students in the same position at the beginning.

+ +

 

+

Example 1:

+ +
Input: seats = [3,1,5], students = [2,7,4]
+Output: 4
+Explanation: The students are moved as follows:
+- The first student is moved from from position 2 to position 1 using 1 move.
+- The second student is moved from from position 7 to position 5 using 2 moves.
+- The third student is moved from from position 4 to position 3 using 1 move.
+In total, 1 + 2 + 1 = 4 moves were used.
+
+ +

Example 2:

+ +
Input: seats = [4,1,5,9], students = [1,3,2,6]
+Output: 7
+Explanation: The students are moved as follows:
+- The first student is not moved.
+- The second student is moved from from position 3 to position 4 using 1 move.
+- The third student is moved from from position 2 to position 5 using 3 moves.
+- The fourth student is moved from from position 6 to position 9 using 3 moves.
+In total, 0 + 1 + 3 + 3 = 7 moves were used.
+
+ +

Example 3:

+ +
Input: seats = [2,2,6,6], students = [1,3,2,6]
+Output: 4
+Explanation: Note that there are two seats at position 2 and two seats at position 6.
+The students are moved as follows:
+- The first student is moved from from position 1 to position 2 using 1 move.
+- The second student is moved from from position 3 to position 6 using 3 moves.
+- The third student is not moved.
+- The fourth student is not moved.
+In total, 1 + 3 + 0 + 0 = 4 moves were used.
+
+ +

 

+

Constraints:

+ +
    +
  • n == seats.length == students.length
  • +
  • 1 <= n <= 100
  • +
  • 1 <= seats[i], students[j] <= 100
  • +
+
\ No newline at end of file diff --git a/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.py b/problems/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.py similarity index 100% rename from 2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.py rename to problems/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.py diff --git a/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/NOTES.md b/problems/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/NOTES.md similarity index 100% rename from 2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/NOTES.md rename to problems/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/NOTES.md diff --git a/problems/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/README.md b/problems/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/README.md new file mode 100644 index 000000000..a5034a96f --- /dev/null +++ b/problems/2038-remove-colored-pieces-if-both-neighbors-are-the-same-color/README.md @@ -0,0 +1,63 @@ +

2038. Remove Colored Pieces if Both Neighbors are the Same Color

Medium


There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece.

+ +

Alice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.

+ +
    +
  • Alice is only allowed to remove a piece colored 'A' if both its neighbors are also colored 'A'. She is not allowed to remove pieces that are colored 'B'.
  • +
  • Bob is only allowed to remove a piece colored 'B' if both its neighbors are also colored 'B'. He is not allowed to remove pieces that are colored 'A'.
  • +
  • Alice and Bob cannot remove pieces from the edge of the line.
  • +
  • If a player cannot make a move on their turn, that player loses and the other player wins.
  • +
+ +

Assuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.

+ +

 

+

Example 1:

+ +
Input: colors = "AAABABB"
+Output: true
+Explanation:
+AAABABB -> AABABB
+Alice moves first.
+She removes the second 'A' from the left since that is the only 'A' whose neighbors are both 'A'.
+
+Now it's Bob's turn.
+Bob cannot make a move on his turn since there are no 'B's whose neighbors are both 'B'.
+Thus, Alice wins, so return true.
+
+ +

Example 2:

+ +
Input: colors = "AA"
+Output: false
+Explanation:
+Alice has her turn first.
+There are only two 'A's and both are on the edge of the line, so she cannot move on her turn.
+Thus, Bob wins, so return false.
+
+ +

Example 3:

+ +
Input: colors = "ABBBBBBBAAA"
+Output: false
+Explanation:
+ABBBBBBBAAA -> ABBBBBBBAA
+Alice moves first.
+Her only option is to remove the second to last 'A' from the right.
+
+ABBBBBBBAA -> ABBBBBBAA
+Next is Bob's turn.
+He has many options for which 'B' piece to remove. He can pick any.
+
+On Alice's second turn, she has no more pieces that she can remove.
+Thus, Bob wins, so return false.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= colors.length <= 105
  • +
  • colors consists of only the letters 'A' and 'B'
  • +
+
\ No newline at end of file diff --git a/2045-second-minimum-time-to-reach-destination/2045-second-minimum-time-to-reach-destination.py b/problems/2045-second-minimum-time-to-reach-destination/2045-second-minimum-time-to-reach-destination.py similarity index 100% rename from 2045-second-minimum-time-to-reach-destination/2045-second-minimum-time-to-reach-destination.py rename to problems/2045-second-minimum-time-to-reach-destination/2045-second-minimum-time-to-reach-destination.py diff --git a/2045-second-minimum-time-to-reach-destination/NOTES.md b/problems/2045-second-minimum-time-to-reach-destination/NOTES.md similarity index 100% rename from 2045-second-minimum-time-to-reach-destination/NOTES.md rename to problems/2045-second-minimum-time-to-reach-destination/NOTES.md diff --git a/problems/2045-second-minimum-time-to-reach-destination/README.md b/problems/2045-second-minimum-time-to-reach-destination/README.md new file mode 100644 index 000000000..cc4613670 --- /dev/null +++ b/problems/2045-second-minimum-time-to-reach-destination/README.md @@ -0,0 +1,64 @@ +

2045. Second Minimum Time to Reach Destination

Hard


A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself. The time taken to traverse any edge is time minutes.

+ +

Each vertex has a traffic signal which changes its color from green to red and vice versa every change minutes. All signals change at the same time. You can enter a vertex at any time, but can leave a vertex only when the signal is green. You cannot wait at a vertex if the signal is green.

+ +

The second minimum value is defined as the smallest value strictly larger than the minimum value.

+ +
    +
  • For example the second minimum value of [2, 3, 4] is 3, and the second minimum value of [2, 2, 4] is 4.
  • +
+ +

Given n, edges, time, and change, return the second minimum time it will take to go from vertex 1 to vertex n.

+ +

Notes:

+ +
    +
  • You can go through any vertex any number of times, including 1 and n.
  • +
  • You can assume that when the journey starts, all signals have just turned green.
  • +
+ +

 

+

Example 1:

+         +
Input: n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5
+Output: 13
+Explanation:
+The figure on the left shows the given graph.
+The blue path in the figure on the right is the minimum time path.
+The time taken is:
+- Start at 1, time elapsed=0
+- 1 -> 4: 3 minutes, time elapsed=3
+- 4 -> 5: 3 minutes, time elapsed=6
+Hence the minimum time needed is 6 minutes.
+
+The red path shows the path to get the second minimum time.
+- Start at 1, time elapsed=0
+- 1 -> 3: 3 minutes, time elapsed=3
+- 3 -> 4: 3 minutes, time elapsed=6
+- Wait at 4 for 4 minutes, time elapsed=10
+- 4 -> 5: 3 minutes, time elapsed=13
+Hence the second minimum time is 13 minutes.      
+
+ +

Example 2:

+ +
Input: n = 2, edges = [[1,2]], time = 3, change = 2
+Output: 11
+Explanation:
+The minimum time path is 1 -> 2 with time = 3 minutes.
+The second minimum time path is 1 -> 2 -> 1 -> 2 with time = 11 minutes.
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 104
  • +
  • n - 1 <= edges.length <= min(2 * 104, n * (n - 1) / 2)
  • +
  • edges[i].length == 2
  • +
  • 1 <= ui, vi <= n
  • +
  • ui != vi
  • +
  • There are no duplicate edges.
  • +
  • Each vertex can be reached directly or indirectly from every other vertex.
  • +
  • 1 <= time, change <= 103
  • +
+
\ No newline at end of file diff --git a/2050-parallel-courses-iii/2050-parallel-courses-iii.py b/problems/2050-parallel-courses-iii/2050-parallel-courses-iii.py similarity index 100% rename from 2050-parallel-courses-iii/2050-parallel-courses-iii.py rename to problems/2050-parallel-courses-iii/2050-parallel-courses-iii.py diff --git a/2050-parallel-courses-iii/NOTES.md b/problems/2050-parallel-courses-iii/NOTES.md similarity index 100% rename from 2050-parallel-courses-iii/NOTES.md rename to problems/2050-parallel-courses-iii/NOTES.md diff --git a/problems/2050-parallel-courses-iii/README.md b/problems/2050-parallel-courses-iii/README.md new file mode 100644 index 000000000..064edd198 --- /dev/null +++ b/problems/2050-parallel-courses-iii/README.md @@ -0,0 +1,53 @@ +

2050. Parallel Courses III

Hard


You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes that course prevCoursej has to be completed before course nextCoursej (prerequisite relationship). Furthermore, you are given a 0-indexed integer array time where time[i] denotes how many months it takes to complete the (i+1)th course.

+ +

You must find the minimum number of months needed to complete all the courses following these rules:

+ +
    +
  • You may start taking a course at any time if the prerequisites are met.
  • +
  • Any number of courses can be taken at the same time.
  • +
+ +

Return the minimum number of months needed to complete all the courses.

+ +

Note: The test cases are generated such that it is possible to complete every course (i.e., the graph is a directed acyclic graph).

+ +

 

+

Example 1:

+ + +
Input: n = 3, relations = [[1,3],[2,3]], time = [3,2,5]
+Output: 8
+Explanation: The figure above represents the given graph and the time required to complete each course. 
+We start course 1 and course 2 simultaneously at month 0.
+Course 1 takes 3 months and course 2 takes 2 months to complete respectively.
+Thus, the earliest time we can start course 3 is at month 3, and the total time required is 3 + 5 = 8 months.
+
+ +

Example 2:

+ + +
Input: n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]
+Output: 12
+Explanation: The figure above represents the given graph and the time required to complete each course.
+You can start courses 1, 2, and 3 at month 0.
+You can complete them after 1, 2, and 3 months respectively.
+Course 4 can be taken only after course 3 is completed, i.e., after 3 months. It is completed after 3 + 4 = 7 months.
+Course 5 can be taken only after courses 1, 2, 3, and 4 have been completed, i.e., after max(1,2,3,7) = 7 months.
+Thus, the minimum time needed to complete all the courses is 7 + 5 = 12 months.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 5 * 104
  • +
  • 0 <= relations.length <= min(n * (n - 1) / 2, 5 * 104)
  • +
  • relations[j].length == 2
  • +
  • 1 <= prevCoursej, nextCoursej <= n
  • +
  • prevCoursej != nextCoursej
  • +
  • All the pairs [prevCoursej, nextCoursej] are unique.
  • +
  • time.length == n
  • +
  • 1 <= time[i] <= 104
  • +
  • The given graph is a directed acyclic graph.
  • +
+
\ No newline at end of file diff --git a/2053-kth-distinct-string-in-an-array/2053-kth-distinct-string-in-an-array.py b/problems/2053-kth-distinct-string-in-an-array/2053-kth-distinct-string-in-an-array.py similarity index 100% rename from 2053-kth-distinct-string-in-an-array/2053-kth-distinct-string-in-an-array.py rename to problems/2053-kth-distinct-string-in-an-array/2053-kth-distinct-string-in-an-array.py diff --git a/2053-kth-distinct-string-in-an-array/NOTES.md b/problems/2053-kth-distinct-string-in-an-array/NOTES.md similarity index 100% rename from 2053-kth-distinct-string-in-an-array/NOTES.md rename to problems/2053-kth-distinct-string-in-an-array/NOTES.md diff --git a/problems/2053-kth-distinct-string-in-an-array/README.md b/problems/2053-kth-distinct-string-in-an-array/README.md new file mode 100644 index 000000000..30e7edf53 --- /dev/null +++ b/problems/2053-kth-distinct-string-in-an-array/README.md @@ -0,0 +1,43 @@ +

2053. Kth Distinct String in an Array

Easy


A distinct string is a string that is present only once in an array.

+ +

Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return an empty string "".

+ +

Note that the strings are considered in the order in which they appear in the array.

+ +

 

+

Example 1:

+ +
Input: arr = ["d","b","c","b","c","a"], k = 2
+Output: "a"
+Explanation:
+The only distinct strings in arr are "d" and "a".
+"d" appears 1st, so it is the 1st distinct string.
+"a" appears 2nd, so it is the 2nd distinct string.
+Since k == 2, "a" is returned. 
+
+ +

Example 2:

+ +
Input: arr = ["aaa","aa","a"], k = 1
+Output: "aaa"
+Explanation:
+All strings in arr are distinct, so the 1st string "aaa" is returned.
+
+ +

Example 3:

+ +
Input: arr = ["a","b","a"], k = 3
+Output: ""
+Explanation:
+The only distinct string is "b". Since there are fewer than 3 distinct strings, we return an empty string "".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= arr.length <= 1000
  • +
  • 1 <= arr[i].length <= 5
  • +
  • arr[i] consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.py b/problems/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.py similarity index 100% rename from 2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.py rename to problems/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.py diff --git a/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/NOTES.md b/problems/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/NOTES.md similarity index 100% rename from 2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/NOTES.md rename to problems/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/NOTES.md diff --git a/problems/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/README.md b/problems/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/README.md new file mode 100644 index 000000000..530c9a237 --- /dev/null +++ b/problems/2058-find-the-minimum-and-maximum-number-of-nodes-between-critical-points/README.md @@ -0,0 +1,50 @@ +

2058. Find the Minimum and Maximum Number of Nodes Between Critical Points

Medium


A critical point in a linked list is defined as either a local maxima or a local minima.

+ +

A node is a local maxima if the current node has a value strictly greater than the previous node and the next node.

+ +

A node is a local minima if the current node has a value strictly smaller than the previous node and the next node.

+ +

Note that a node can only be a local maxima/minima if there exists both a previous node and a next node.

+ +

Given a linked list head, return an array of length 2 containing [minDistance, maxDistance] where minDistance is the minimum distance between any two distinct critical points and maxDistance is the maximum distance between any two distinct critical points. If there are fewer than two critical points, return [-1, -1].

+ +

 

+

Example 1:

+ +
Input: head = [3,1]
+Output: [-1,-1]
+Explanation: There are no critical points in [3,1].
+
+ +

Example 2:

+ +
Input: head = [5,3,1,2,5,1,2]
+Output: [1,3]
+Explanation: There are three critical points:
+- [5,3,1,2,5,1,2]: The third node is a local minima because 1 is less than 3 and 2.
+- [5,3,1,2,5,1,2]: The fifth node is a local maxima because 5 is greater than 2 and 1.
+- [5,3,1,2,5,1,2]: The sixth node is a local minima because 1 is less than 5 and 2.
+The minimum distance is between the fifth and the sixth node. minDistance = 6 - 5 = 1.
+The maximum distance is between the third and the sixth node. maxDistance = 6 - 3 = 3.
+
+ +

Example 3:

+ +
Input: head = [1,3,2,2,3,2,2,2,7]
+Output: [3,3]
+Explanation: There are two critical points:
+- [1,3,2,2,3,2,2,2,7]: The second node is a local maxima because 3 is greater than 1 and 2.
+- [1,3,2,2,3,2,2,2,7]: The fifth node is a local maxima because 3 is greater than 2 and 2.
+Both the minimum and maximum distances are between the second and the fifth node.
+Thus, minDistance and maxDistance is 5 - 2 = 3.
+Note that the last node is not considered a local maxima because it does not have a next node.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [2, 105].
  • +
  • 1 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/2061-number-of-spaces-cleaning-robot-cleaned/2061-number-of-spaces-cleaning-robot-cleaned.py b/problems/2061-number-of-spaces-cleaning-robot-cleaned/2061-number-of-spaces-cleaning-robot-cleaned.py similarity index 100% rename from 2061-number-of-spaces-cleaning-robot-cleaned/2061-number-of-spaces-cleaning-robot-cleaned.py rename to problems/2061-number-of-spaces-cleaning-robot-cleaned/2061-number-of-spaces-cleaning-robot-cleaned.py diff --git a/2061-number-of-spaces-cleaning-robot-cleaned/NOTES.md b/problems/2061-number-of-spaces-cleaning-robot-cleaned/NOTES.md similarity index 100% rename from 2061-number-of-spaces-cleaning-robot-cleaned/NOTES.md rename to problems/2061-number-of-spaces-cleaning-robot-cleaned/NOTES.md diff --git a/problems/2061-number-of-spaces-cleaning-robot-cleaned/README.md b/problems/2061-number-of-spaces-cleaning-robot-cleaned/README.md new file mode 100644 index 000000000..c5355eed2 --- /dev/null +++ b/problems/2061-number-of-spaces-cleaning-robot-cleaned/README.md @@ -0,0 +1,71 @@ +

2061. Number of Spaces Cleaning Robot Cleaned

Medium


A room is represented by a 0-indexed 2D binary matrix room where a 0 represents an empty space and a 1 represents a space with an object. The top left corner of the room will be empty in all test cases.

+ +

A cleaning robot starts at the top left corner of the room and is facing right. The robot will continue heading straight until it reaches the edge of the room or it hits an object, after which it will turn 90 degrees clockwise and repeat this process. The starting space and all spaces that the robot visits are cleaned by it.

+ +

Return the number of clean spaces in the room if the robot runs indefinetely.

+ +

 

+

Example 1:

+ +

 

+ +
+

Input: room = [[0,0,0],[1,1,0],[0,0,0]]

+ +

Output: 7

+ +

Explanation:

+ +
    +
  1. ​​​​​​​The robot cleans the spaces at (0, 0), (0, 1), and (0, 2).
  2. +
  3. The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces down.
  4. +
  5. The robot cleans the spaces at (1, 2), and (2, 2).
  6. +
  7. The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces left.
  8. +
  9. The robot cleans the spaces at (2, 1), and (2, 0).
  10. +
  11. The robot has cleaned all 7 empty spaces, so return 7.
  12. +
+
+ +

Example 2:

+ +

 

+ +
+

Input: room = [[0,1,0],[1,0,0],[0,0,0]]

+ +

Output: 1

+ +

Explanation:

+ +
    +
  1. The robot cleans the space at (0, 0).
  2. +
  3. The robot hits an object, so it turns 90 degrees clockwise and now faces down.
  4. +
  5. The robot hits an object, so it turns 90 degrees clockwise and now faces left.
  6. +
  7. The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces up.
  8. +
  9. The robot is at the edge of the room, so it turns 90 degrees clockwise and now faces right.
  10. +
  11. The robot is back at its starting position.
  12. +
  13. The robot has cleaned 1 space, so return 1.
  14. +
+
+ +

Example 3:

+ +
+

Input: room = [[0,0,0],[0,0,0],[0,0,0]]

+ +

Output: 8​​​​​​​

+ +

 

+
+ +

 

+

Constraints:

+ +
    +
  • m == room.length
  • +
  • n == room[r].length
  • +
  • 1 <= m, n <= 300
  • +
  • room[r][c] is either 0 or 1.
  • +
  • room[0][0] == 0
  • +
+
\ No newline at end of file diff --git a/2073-time-needed-to-buy-tickets/2073-time-needed-to-buy-tickets.py b/problems/2073-time-needed-to-buy-tickets/2073-time-needed-to-buy-tickets.py similarity index 100% rename from 2073-time-needed-to-buy-tickets/2073-time-needed-to-buy-tickets.py rename to problems/2073-time-needed-to-buy-tickets/2073-time-needed-to-buy-tickets.py diff --git a/2073-time-needed-to-buy-tickets/NOTES.md b/problems/2073-time-needed-to-buy-tickets/NOTES.md similarity index 100% rename from 2073-time-needed-to-buy-tickets/NOTES.md rename to problems/2073-time-needed-to-buy-tickets/NOTES.md diff --git a/problems/2073-time-needed-to-buy-tickets/README.md b/problems/2073-time-needed-to-buy-tickets/README.md new file mode 100644 index 000000000..5c998ffc9 --- /dev/null +++ b/problems/2073-time-needed-to-buy-tickets/README.md @@ -0,0 +1,39 @@ +

2073. Time Needed to Buy Tickets

Easy


There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line.

+ +

You are given a 0-indexed integer array tickets of length n where the number of tickets that the ith person would like to buy is tickets[i].

+ +

Each person takes exactly 1 second to buy a ticket. A person can only buy 1 ticket at a time and has to go back to the end of the line (which happens instantaneously) in order to buy more tickets. If a person does not have any tickets left to buy, the person will leave the line.

+ +

Return the time taken for the person at position k (0-indexed) to finish buying tickets.

+ +

 

+

Example 1:

+ +
Input: tickets = [2,3,2], k = 2
+Output: 6
+Explanation: 
+- In the first pass, everyone in the line buys a ticket and the line becomes [1, 2, 1].
+- In the second pass, everyone in the line buys a ticket and the line becomes [0, 1, 0].
+The person at position 2 has successfully bought 2 tickets and it took 3 + 3 = 6 seconds.
+
+ +

Example 2:

+ +
Input: tickets = [5,1,1,1], k = 0
+Output: 8
+Explanation:
+- In the first pass, everyone in the line buys a ticket and the line becomes [4, 0, 0, 0].
+- In the next 4 passes, only the person in position 0 is buying tickets.
+The person at position 0 has successfully bought 5 tickets and it took 4 + 1 + 1 + 1 + 1 = 8 seconds.
+
+ +

 

+

Constraints:

+ +
    +
  • n == tickets.length
  • +
  • 1 <= n <= 100
  • +
  • 1 <= tickets[i] <= 100
  • +
  • 0 <= k < n
  • +
+
\ No newline at end of file diff --git a/2083-substrings-that-begin-and-end-with-the-same-letter/2083-substrings-that-begin-and-end-with-the-same-letter.py b/problems/2083-substrings-that-begin-and-end-with-the-same-letter/2083-substrings-that-begin-and-end-with-the-same-letter.py similarity index 100% rename from 2083-substrings-that-begin-and-end-with-the-same-letter/2083-substrings-that-begin-and-end-with-the-same-letter.py rename to problems/2083-substrings-that-begin-and-end-with-the-same-letter/2083-substrings-that-begin-and-end-with-the-same-letter.py diff --git a/problems/2083-substrings-that-begin-and-end-with-the-same-letter/README.md b/problems/2083-substrings-that-begin-and-end-with-the-same-letter/README.md new file mode 100644 index 000000000..247e83074 --- /dev/null +++ b/problems/2083-substrings-that-begin-and-end-with-the-same-letter/README.md @@ -0,0 +1,41 @@ +

2083. Substrings That Begin and End With the Same Letter

Medium


You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character.

+ +

A substring is a contiguous non-empty sequence of characters within a string.

+ +

 

+

Example 1:

+ +
Input: s = "abcba"
+Output: 7
+Explanation:
+The substrings of length 1 that start and end with the same letter are: "a", "b", "c", "b", and "a".
+The substring of length 3 that starts and ends with the same letter is: "bcb".
+The substring of length 5 that starts and ends with the same letter is: "abcba".
+
+ +

Example 2:

+ +
Input: s = "abacad"
+Output: 9
+Explanation:
+The substrings of length 1 that start and end with the same letter are: "a", "b", "a", "c", "a", and "d".
+The substrings of length 3 that start and end with the same letter are: "aba" and "aca".
+The substring of length 5 that starts and ends with the same letter is: "abaca".
+
+ +

Example 3:

+ +
Input: s = "a"
+Output: 1
+Explanation:
+The substring of length 1 that starts and ends with the same letter is: "a".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s consists only of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2092-find-all-people-with-secret/2092-find-all-people-with-secret.py b/problems/2092-find-all-people-with-secret/2092-find-all-people-with-secret.py similarity index 100% rename from 2092-find-all-people-with-secret/2092-find-all-people-with-secret.py rename to problems/2092-find-all-people-with-secret/2092-find-all-people-with-secret.py diff --git a/2092-find-all-people-with-secret/NOTES.md b/problems/2092-find-all-people-with-secret/NOTES.md similarity index 100% rename from 2092-find-all-people-with-secret/NOTES.md rename to problems/2092-find-all-people-with-secret/NOTES.md diff --git a/problems/2092-find-all-people-with-secret/README.md b/problems/2092-find-all-people-with-secret/README.md new file mode 100644 index 000000000..3a4f6ecb8 --- /dev/null +++ b/problems/2092-find-all-people-with-secret/README.md @@ -0,0 +1,57 @@ +

2092. Find All People With Secret

Hard


You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei. A person may attend multiple meetings at the same time. Finally, you are given an integer firstPerson.

+ +

Person 0 has a secret and initially shares the secret with a person firstPerson at time 0. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person xi has the secret at timei, then they will share the secret with person yi, and vice versa.

+ +

The secrets are shared instantaneously. That is, a person may receive the secret and share it with people in other meetings within the same time frame.

+ +

Return a list of all the people that have the secret after all the meetings have taken place. You may return the answer in any order.

+ +

 

+

Example 1:

+ +
Input: n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1
+Output: [0,1,2,3,5]
+Explanation:
+At time 0, person 0 shares the secret with person 1.
+At time 5, person 1 shares the secret with person 2.
+At time 8, person 2 shares the secret with person 3.
+At time 10, person 1 shares the secret with person 5.​​​​
+Thus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.
+
+ +

Example 2:

+ +
Input: n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3
+Output: [0,1,3]
+Explanation:
+At time 0, person 0 shares the secret with person 3.
+At time 2, neither person 1 nor person 2 know the secret.
+At time 3, person 3 shares the secret with person 0 and person 1.
+Thus, people 0, 1, and 3 know the secret after all the meetings.
+
+ +

Example 3:

+ +
Input: n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1
+Output: [0,1,2,3,4]
+Explanation:
+At time 0, person 0 shares the secret with person 1.
+At time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.
+Note that person 2 can share the secret at the same time as receiving it.
+At time 2, person 3 shares the secret with person 4.
+Thus, people 0, 1, 2, 3, and 4 know the secret after all the meetings.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 105
  • +
  • 1 <= meetings.length <= 105
  • +
  • meetings[i].length == 3
  • +
  • 0 <= xi, yi <= n - 1
  • +
  • xi != yi
  • +
  • 1 <= timei <= 105
  • +
  • 1 <= firstPerson <= n - 1
  • +
+
\ No newline at end of file diff --git a/2093-minimum-cost-to-reach-city-with-discounts/2093-minimum-cost-to-reach-city-with-discounts.py b/problems/2093-minimum-cost-to-reach-city-with-discounts/2093-minimum-cost-to-reach-city-with-discounts.py similarity index 100% rename from 2093-minimum-cost-to-reach-city-with-discounts/2093-minimum-cost-to-reach-city-with-discounts.py rename to problems/2093-minimum-cost-to-reach-city-with-discounts/2093-minimum-cost-to-reach-city-with-discounts.py diff --git a/2093-minimum-cost-to-reach-city-with-discounts/NOTES.md b/problems/2093-minimum-cost-to-reach-city-with-discounts/NOTES.md similarity index 100% rename from 2093-minimum-cost-to-reach-city-with-discounts/NOTES.md rename to problems/2093-minimum-cost-to-reach-city-with-discounts/NOTES.md diff --git a/2096-step-by-step-directions-from-a-binary-tree-node-to-another/2096-step-by-step-directions-from-a-binary-tree-node-to-another.py b/problems/2096-step-by-step-directions-from-a-binary-tree-node-to-another/2096-step-by-step-directions-from-a-binary-tree-node-to-another.py similarity index 100% rename from 2096-step-by-step-directions-from-a-binary-tree-node-to-another/2096-step-by-step-directions-from-a-binary-tree-node-to-another.py rename to problems/2096-step-by-step-directions-from-a-binary-tree-node-to-another/2096-step-by-step-directions-from-a-binary-tree-node-to-another.py diff --git a/2096-step-by-step-directions-from-a-binary-tree-node-to-another/NOTES.md b/problems/2096-step-by-step-directions-from-a-binary-tree-node-to-another/NOTES.md similarity index 100% rename from 2096-step-by-step-directions-from-a-binary-tree-node-to-another/NOTES.md rename to problems/2096-step-by-step-directions-from-a-binary-tree-node-to-another/NOTES.md diff --git a/2108-find-first-palindromic-string-in-the-array/2108-find-first-palindromic-string-in-the-array.py b/problems/2108-find-first-palindromic-string-in-the-array/2108-find-first-palindromic-string-in-the-array.py similarity index 100% rename from 2108-find-first-palindromic-string-in-the-array/2108-find-first-palindromic-string-in-the-array.py rename to problems/2108-find-first-palindromic-string-in-the-array/2108-find-first-palindromic-string-in-the-array.py diff --git a/2108-find-first-palindromic-string-in-the-array/NOTES.md b/problems/2108-find-first-palindromic-string-in-the-array/NOTES.md similarity index 100% rename from 2108-find-first-palindromic-string-in-the-array/NOTES.md rename to problems/2108-find-first-palindromic-string-in-the-array/NOTES.md diff --git a/problems/2108-find-first-palindromic-string-in-the-array/README.md b/problems/2108-find-first-palindromic-string-in-the-array/README.md new file mode 100644 index 000000000..cdaba2f08 --- /dev/null +++ b/problems/2108-find-first-palindromic-string-in-the-array/README.md @@ -0,0 +1,36 @@ +

2108. Find First Palindromic String in the Array

Easy


Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".

+ +

A string is palindromic if it reads the same forward and backward.

+ +

 

+

Example 1:

+ +
Input: words = ["abc","car","ada","racecar","cool"]
+Output: "ada"
+Explanation: The first string that is palindromic is "ada".
+Note that "racecar" is also palindromic, but it is not the first.
+
+ +

Example 2:

+ +
Input: words = ["notapalindrome","racecar"]
+Output: "racecar"
+Explanation: The first and only string that is palindromic is "racecar".
+
+ +

Example 3:

+ +
Input: words = ["def","ghi"]
+Output: ""
+Explanation: There are no palindromic strings, so the empty string is returned.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 100
  • +
  • 1 <= words[i].length <= 100
  • +
  • words[i] consists only of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2125-number-of-laser-beams-in-a-bank/2125-number-of-laser-beams-in-a-bank.py b/problems/2125-number-of-laser-beams-in-a-bank/2125-number-of-laser-beams-in-a-bank.py similarity index 100% rename from 2125-number-of-laser-beams-in-a-bank/2125-number-of-laser-beams-in-a-bank.py rename to problems/2125-number-of-laser-beams-in-a-bank/2125-number-of-laser-beams-in-a-bank.py diff --git a/2125-number-of-laser-beams-in-a-bank/NOTES.md b/problems/2125-number-of-laser-beams-in-a-bank/NOTES.md similarity index 100% rename from 2125-number-of-laser-beams-in-a-bank/NOTES.md rename to problems/2125-number-of-laser-beams-in-a-bank/NOTES.md diff --git a/problems/2125-number-of-laser-beams-in-a-bank/README.md b/problems/2125-number-of-laser-beams-in-a-bank/README.md new file mode 100644 index 000000000..6b3c5a3f7 --- /dev/null +++ b/problems/2125-number-of-laser-beams-in-a-bank/README.md @@ -0,0 +1,48 @@ +

2125. Number of Laser Beams in a Bank

Medium


Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the ith row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.

+ +

There is one laser beam between any two security devices if both conditions are met:

+ +
    +
  • The two devices are located on two different rows: r1 and r2, where r1 < r2.
  • +
  • For each row i where r1 < i < r2, there are no security devices in the ith row.
  • +
+ +

Laser beams are independent, i.e., one beam does not interfere nor join with another.

+ +

Return the total number of laser beams in the bank.

+ +

 

+

Example 1:

+ +
Input: bank = ["011001","000000","010100","001000"]
+Output: 8
+Explanation: Between each of the following device pairs, there is one beam. In total, there are 8 beams:
+ * bank[0][1] -- bank[2][1]
+ * bank[0][1] -- bank[2][3]
+ * bank[0][2] -- bank[2][1]
+ * bank[0][2] -- bank[2][3]
+ * bank[0][5] -- bank[2][1]
+ * bank[0][5] -- bank[2][3]
+ * bank[2][1] -- bank[3][2]
+ * bank[2][3] -- bank[3][2]
+Note that there is no beam between any device on the 0th row with any on the 3rd row.
+This is because the 2nd row contains security devices, which breaks the second condition.
+
+ +

Example 2:

+ +
Input: bank = ["000","111","000"]
+Output: 0
+Explanation: There does not exist two devices located on two different rows.
+
+ +

 

+

Constraints:

+ +
    +
  • m == bank.length
  • +
  • n == bank[i].length
  • +
  • 1 <= m, n <= 500
  • +
  • bank[i][j] is either '0' or '1'.
  • +
+
\ No newline at end of file diff --git a/2134-minimum-swaps-to-group-all-1s-together-ii/2134-minimum-swaps-to-group-all-1s-together-ii.py b/problems/2134-minimum-swaps-to-group-all-1s-together-ii/2134-minimum-swaps-to-group-all-1s-together-ii.py similarity index 100% rename from 2134-minimum-swaps-to-group-all-1s-together-ii/2134-minimum-swaps-to-group-all-1s-together-ii.py rename to problems/2134-minimum-swaps-to-group-all-1s-together-ii/2134-minimum-swaps-to-group-all-1s-together-ii.py diff --git a/2134-minimum-swaps-to-group-all-1s-together-ii/NOTES.md b/problems/2134-minimum-swaps-to-group-all-1s-together-ii/NOTES.md similarity index 100% rename from 2134-minimum-swaps-to-group-all-1s-together-ii/NOTES.md rename to problems/2134-minimum-swaps-to-group-all-1s-together-ii/NOTES.md diff --git a/problems/2134-minimum-swaps-to-group-all-1s-together-ii/README.md b/problems/2134-minimum-swaps-to-group-all-1s-together-ii/README.md new file mode 100644 index 000000000..2c4dc53e4 --- /dev/null +++ b/problems/2134-minimum-swaps-to-group-all-1s-together-ii/README.md @@ -0,0 +1,46 @@ +

2134. Minimum Swaps to Group All 1's Together II

Medium


A swap is defined as taking two distinct positions in an array and swapping the values in them.

+ +

A circular array is defined as an array where we consider the first element and the last element to be adjacent.

+ +

Given a binary circular array nums, return the minimum number of swaps required to group all 1's present in the array together at any location.

+ +

 

+

Example 1:

+ +
Input: nums = [0,1,0,1,1,0,0]
+Output: 1
+Explanation: Here are a few of the ways to group all the 1's together:
+[0,0,1,1,1,0,0] using 1 swap.
+[0,1,1,1,0,0,0] using 1 swap.
+[1,1,0,0,0,0,1] using 2 swaps (using the circular property of the array).
+There is no way to group all 1's together with 0 swaps.
+Thus, the minimum number of swaps required is 1.
+
+ +

Example 2:

+ +
Input: nums = [0,1,1,1,0,0,1,1,0]
+Output: 2
+Explanation: Here are a few of the ways to group all the 1's together:
+[1,1,1,0,0,0,0,1,1] using 2 swaps (using the circular property of the array).
+[1,1,1,1,1,0,0,0,0] using 2 swaps.
+There is no way to group all 1's together with 0 or 1 swaps.
+Thus, the minimum number of swaps required is 2.
+
+ +

Example 3:

+ +
Input: nums = [1,1,0,0,1]
+Output: 0
+Explanation: All the 1's are already grouped together due to the circular property of the array.
+Thus, the minimum number of swaps required is 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • nums[i] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/2141-maximum-running-time-of-n-computers/2141-maximum-running-time-of-n-computers.py b/problems/2141-maximum-running-time-of-n-computers/2141-maximum-running-time-of-n-computers.py similarity index 100% rename from 2141-maximum-running-time-of-n-computers/2141-maximum-running-time-of-n-computers.py rename to problems/2141-maximum-running-time-of-n-computers/2141-maximum-running-time-of-n-computers.py diff --git a/2141-maximum-running-time-of-n-computers/NOTES.md b/problems/2141-maximum-running-time-of-n-computers/NOTES.md similarity index 100% rename from 2141-maximum-running-time-of-n-computers/NOTES.md rename to problems/2141-maximum-running-time-of-n-computers/NOTES.md diff --git a/problems/2141-maximum-running-time-of-n-computers/README.md b/problems/2141-maximum-running-time-of-n-computers/README.md new file mode 100644 index 000000000..e358fe254 --- /dev/null +++ b/problems/2141-maximum-running-time-of-n-computers/README.md @@ -0,0 +1,41 @@ +

2141. Maximum Running Time of N Computers

Hard


You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries.

+ +

Initially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time.

+ +

Note that the batteries cannot be recharged.

+ +

Return the maximum number of minutes you can run all the n computers simultaneously.

+ +

 

+

Example 1:

+ +
Input: n = 2, batteries = [3,3,3]
+Output: 4
+Explanation: 
+Initially, insert battery 0 into the first computer and battery 1 into the second computer.
+After two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute.
+At the end of the third minute, battery 0 is drained, and you need to remove it from the first computer and insert battery 1 instead.
+By the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running.
+We can run the two computers simultaneously for at most 4 minutes, so we return 4.
+
+
+ +

Example 2:

+ +
Input: n = 2, batteries = [1,1,1,1]
+Output: 2
+Explanation: 
+Initially, insert battery 0 into the first computer and battery 2 into the second computer. 
+After one minute, battery 0 and battery 2 are drained so you need to remove them and insert battery 1 into the first computer and battery 3 into the second computer. 
+After another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running.
+We can run the two computers simultaneously for at most 2 minutes, so we return 2.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= batteries.length <= 105
  • +
  • 1 <= batteries[i] <= 109
  • +
+
\ No newline at end of file diff --git a/2147-number-of-ways-to-divide-a-long-corridor/2147-number-of-ways-to-divide-a-long-corridor.py b/problems/2147-number-of-ways-to-divide-a-long-corridor/2147-number-of-ways-to-divide-a-long-corridor.py similarity index 100% rename from 2147-number-of-ways-to-divide-a-long-corridor/2147-number-of-ways-to-divide-a-long-corridor.py rename to problems/2147-number-of-ways-to-divide-a-long-corridor/2147-number-of-ways-to-divide-a-long-corridor.py diff --git a/2147-number-of-ways-to-divide-a-long-corridor/NOTES.md b/problems/2147-number-of-ways-to-divide-a-long-corridor/NOTES.md similarity index 100% rename from 2147-number-of-ways-to-divide-a-long-corridor/NOTES.md rename to problems/2147-number-of-ways-to-divide-a-long-corridor/NOTES.md diff --git a/problems/2147-number-of-ways-to-divide-a-long-corridor/README.md b/problems/2147-number-of-ways-to-divide-a-long-corridor/README.md new file mode 100644 index 000000000..ee62407b6 --- /dev/null +++ b/problems/2147-number-of-ways-to-divide-a-long-corridor/README.md @@ -0,0 +1,42 @@ +

2147. Number of Ways to Divide a Long Corridor

Hard


Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant.

+ +

One room divider has already been installed to the left of index 0, and another to the right of index n - 1. Additional room dividers can be installed. For each position between indices i - 1 and i (1 <= i <= n - 1), at most one divider can be installed.

+ +

Divide the corridor into non-overlapping sections, where each section has exactly two seats with any number of plants. There may be multiple ways to perform the division. Two ways are different if there is a position with a room divider installed in the first way but not in the second way.

+ +

Return the number of ways to divide the corridor. Since the answer may be very large, return it modulo 109 + 7. If there is no way, return 0.

+ +

 

+

Example 1:

+ +
Input: corridor = "SSPPSPS"
+Output: 3
+Explanation: There are 3 different ways to divide the corridor.
+The black bars in the above image indicate the two room dividers already installed.
+Note that in each of the ways, each section has exactly two seats.
+
+ +

Example 2:

+ +
Input: corridor = "PPSPSP"
+Output: 1
+Explanation: There is only 1 way to divide the corridor, by not installing any additional dividers.
+Installing any would create some section that does not have exactly two seats.
+
+ +

Example 3:

+ +
Input: corridor = "S"
+Output: 0
+Explanation: There is no way to divide the corridor because there will always be a section that does not have exactly two seats.
+
+ +

 

+

Constraints:

+ +
    +
  • n == corridor.length
  • +
  • 1 <= n <= 105
  • +
  • corridor[i] is either 'S' or 'P'.
  • +
+
\ No newline at end of file diff --git a/2149-rearrange-array-elements-by-sign/2149-rearrange-array-elements-by-sign.py b/problems/2149-rearrange-array-elements-by-sign/2149-rearrange-array-elements-by-sign.py similarity index 100% rename from 2149-rearrange-array-elements-by-sign/2149-rearrange-array-elements-by-sign.py rename to problems/2149-rearrange-array-elements-by-sign/2149-rearrange-array-elements-by-sign.py diff --git a/2149-rearrange-array-elements-by-sign/NOTES.md b/problems/2149-rearrange-array-elements-by-sign/NOTES.md similarity index 100% rename from 2149-rearrange-array-elements-by-sign/NOTES.md rename to problems/2149-rearrange-array-elements-by-sign/NOTES.md diff --git a/problems/2149-rearrange-array-elements-by-sign/README.md b/problems/2149-rearrange-array-elements-by-sign/README.md new file mode 100644 index 000000000..06869c95b --- /dev/null +++ b/problems/2149-rearrange-array-elements-by-sign/README.md @@ -0,0 +1,42 @@ +

2149. Rearrange Array Elements by Sign

Medium


You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers.

+ +

You should rearrange the elements of nums such that the modified array follows the given conditions:

+ +
    +
  1. Every consecutive pair of integers have opposite signs.
  2. +
  3. For all integers with the same sign, the order in which they were present in nums is preserved.
  4. +
  5. The rearranged array begins with a positive integer.
  6. +
+ +

Return the modified array after rearranging the elements to satisfy the aforementioned conditions.

+ +

 

+

Example 1:

+ +
Input: nums = [3,1,-2,-5,2,-4]
+Output: [3,-2,1,-5,2,-4]
+Explanation:
+The positive integers in nums are [3,1,2]. The negative integers are [-2,-5,-4].
+The only possible way to rearrange them such that they satisfy all conditions is [3,-2,1,-5,2,-4].
+Other ways such as [1,-2,2,-5,3,-4], [3,1,2,-2,-5,-4], [-2,3,-5,1,-4,2] are incorrect because they do not satisfy one or more conditions.  
+
+ +

Example 2:

+ +
Input: nums = [-1,1]
+Output: [1,-1]
+Explanation:
+1 is the only positive integer and -1 the only negative integer in nums.
+So nums is rearranged to [1,-1].
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 2 * 105
  • +
  • nums.length is even
  • +
  • 1 <= |nums[i]| <= 105
  • +
  • nums consists of equal number of positive and negative integers.
  • +
+
\ No newline at end of file diff --git a/2181-merge-nodes-in-between-zeros/2181-merge-nodes-in-between-zeros.py b/problems/2181-merge-nodes-in-between-zeros/2181-merge-nodes-in-between-zeros.py similarity index 100% rename from 2181-merge-nodes-in-between-zeros/2181-merge-nodes-in-between-zeros.py rename to problems/2181-merge-nodes-in-between-zeros/2181-merge-nodes-in-between-zeros.py diff --git a/problems/2181-merge-nodes-in-between-zeros/README.md b/problems/2181-merge-nodes-in-between-zeros/README.md new file mode 100644 index 000000000..b70d21cf8 --- /dev/null +++ b/problems/2181-merge-nodes-in-between-zeros/README.md @@ -0,0 +1,38 @@ +

2181. Merge Nodes in Between Zeros

Medium


You are given the head of a linked list, which contains a series of integers separated by 0's. The beginning and end of the linked list will have Node.val == 0.

+ +

For every two consecutive 0's, merge all the nodes lying in between them into a single node whose value is the sum of all the merged nodes. The modified list should not contain any 0's.

+ +

Return the head of the modified linked list.

+ +

 

+

Example 1:

+ +
Input: head = [0,3,1,0,4,5,2,0]
+Output: [4,11]
+Explanation: 
+The above figure represents the given linked list. The modified list contains
+- The sum of the nodes marked in green: 3 + 1 = 4.
+- The sum of the nodes marked in red: 4 + 5 + 2 = 11.
+
+ +

Example 2:

+ +
Input: head = [0,1,0,3,0,2,2,0]
+Output: [1,3,4]
+Explanation: 
+The above figure represents the given linked list. The modified list contains
+- The sum of the nodes marked in green: 1 = 1.
+- The sum of the nodes marked in red: 3 = 3.
+- The sum of the nodes marked in yellow: 2 + 2 = 4.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [3, 2 * 105].
  • +
  • 0 <= Node.val <= 1000
  • +
  • There are no two consecutive nodes with Node.val == 0.
  • +
  • The beginning and end of the linked list have Node.val == 0.
  • +
+
\ No newline at end of file diff --git a/2191-sort-the-jumbled-numbers/2191-sort-the-jumbled-numbers.py b/problems/2191-sort-the-jumbled-numbers/2191-sort-the-jumbled-numbers.py similarity index 100% rename from 2191-sort-the-jumbled-numbers/2191-sort-the-jumbled-numbers.py rename to problems/2191-sort-the-jumbled-numbers/2191-sort-the-jumbled-numbers.py diff --git a/problems/2191-sort-the-jumbled-numbers/README.md b/problems/2191-sort-the-jumbled-numbers/README.md new file mode 100644 index 000000000..c230b1a84 --- /dev/null +++ b/problems/2191-sort-the-jumbled-numbers/README.md @@ -0,0 +1,47 @@ +

2191. Sort the Jumbled Numbers

Medium


You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.

+ +

The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9.

+ +

You are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.

+ +

Notes:

+ +
    +
  • Elements with the same mapped values should appear in the same relative order as in the input.
  • +
  • The elements of nums should only be sorted based on their mapped values and not be replaced by them.
  • +
+ +

 

+

Example 1:

+ +
Input: mapping = [8,9,4,0,2,1,3,5,7,6], nums = [991,338,38]
+Output: [338,38,991]
+Explanation: 
+Map the number 991 as follows:
+1. mapping[9] = 6, so all occurrences of the digit 9 will become 6.
+2. mapping[1] = 9, so all occurrences of the digit 1 will become 9.
+Therefore, the mapped value of 991 is 669.
+338 maps to 007, or 7 after removing the leading zeros.
+38 maps to 07, which is also 7 after removing leading zeros.
+Since 338 and 38 share the same mapped value, they should remain in the same relative order, so 338 comes before 38.
+Thus, the sorted array is [338,38,991].
+
+ +

Example 2:

+ +
Input: mapping = [0,1,2,3,4,5,6,7,8,9], nums = [789,456,123]
+Output: [123,456,789]
+Explanation: 789 maps to 789, 456 maps to 456, and 123 maps to 123. Thus, the sorted array is [123,456,789].
+
+ +

 

+

Constraints:

+ +
    +
  • mapping.length == 10
  • +
  • 0 <= mapping[i] <= 9
  • +
  • All the values of mapping[i] are unique.
  • +
  • 1 <= nums.length <= 3 * 104
  • +
  • 0 <= nums[i] < 109
  • +
+
\ No newline at end of file diff --git a/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph.py b/problems/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph.py similarity index 100% rename from 2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph.py rename to problems/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph.py diff --git a/problems/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/README.md b/problems/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/README.md new file mode 100644 index 000000000..8831f9958 --- /dev/null +++ b/problems/2192-all-ancestors-of-a-node-in-a-directed-acyclic-graph/README.md @@ -0,0 +1,49 @@ +

2192. All Ancestors of a Node in a Directed Acyclic Graph

Medium


You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).

+ +

You are also given a 2D integer array edges, where edges[i] = [fromi, toi] denotes that there is a unidirectional edge from fromi to toi in the graph.

+ +

Return a list answer, where answer[i] is the list of ancestors of the ith node, sorted in ascending order.

+ +

A node u is an ancestor of another node v if u can reach v via a set of edges.

+ +

 

+

Example 1:

+ +
Input: n = 8, edgeList = [[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]]
+Output: [[],[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]
+Explanation:
+The above diagram represents the input graph.
+- Nodes 0, 1, and 2 do not have any ancestors.
+- Node 3 has two ancestors 0 and 1.
+- Node 4 has two ancestors 0 and 2.
+- Node 5 has three ancestors 0, 1, and 3.
+- Node 6 has five ancestors 0, 1, 2, 3, and 4.
+- Node 7 has four ancestors 0, 1, 2, and 3.
+
+ +

Example 2:

+ +
Input: n = 5, edgeList = [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
+Output: [[],[0],[0,1],[0,1,2],[0,1,2,3]]
+Explanation:
+The above diagram represents the input graph.
+- Node 0 does not have any ancestor.
+- Node 1 has one ancestor 0.
+- Node 2 has two ancestors 0 and 1.
+- Node 3 has three ancestors 0, 1, and 2.
+- Node 4 has four ancestors 0, 1, 2, and 3.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1000
  • +
  • 0 <= edges.length <= min(2000, n * (n - 1) / 2)
  • +
  • edges[i].length == 2
  • +
  • 0 <= fromi, toi <= n - 1
  • +
  • fromi != toi
  • +
  • There are no duplicate edges.
  • +
  • The graph is directed and acyclic.
  • +
+
\ No newline at end of file diff --git a/2196-create-binary-tree-from-descriptions/2196-create-binary-tree-from-descriptions.py b/problems/2196-create-binary-tree-from-descriptions/2196-create-binary-tree-from-descriptions.py similarity index 100% rename from 2196-create-binary-tree-from-descriptions/2196-create-binary-tree-from-descriptions.py rename to problems/2196-create-binary-tree-from-descriptions/2196-create-binary-tree-from-descriptions.py diff --git a/problems/2196-create-binary-tree-from-descriptions/README.md b/problems/2196-create-binary-tree-from-descriptions/README.md new file mode 100644 index 000000000..3d44829bf --- /dev/null +++ b/problems/2196-create-binary-tree-from-descriptions/README.md @@ -0,0 +1,39 @@ +

2196. Create Binary Tree From Descriptions

Medium


You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore,

+ +
    +
  • If isLefti == 1, then childi is the left child of parenti.
  • +
  • If isLefti == 0, then childi is the right child of parenti.
  • +
+ +

Construct the binary tree described by descriptions and return its root.

+ +

The test cases will be generated such that the binary tree is valid.

+ +

 

+

Example 1:

+ +
Input: descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]]
+Output: [50,20,80,15,17,19]
+Explanation: The root node is the node with value 50 since it has no parent.
+The resulting binary tree is shown in the diagram.
+
+ +

Example 2:

+ +
Input: descriptions = [[1,2,1],[2,3,0],[3,4,1]]
+Output: [1,2,null,null,3,4]
+Explanation: The root node is the node with value 1 since it has no parent.
+The resulting binary tree is shown in the diagram.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= descriptions.length <= 104
  • +
  • descriptions[i].length == 3
  • +
  • 1 <= parenti, childi <= 105
  • +
  • 0 <= isLefti <= 1
  • +
  • The binary tree described by descriptions is valid.
  • +
+
\ No newline at end of file diff --git a/2225-find-players-with-zero-or-one-losses/2225-find-players-with-zero-or-one-losses.py b/problems/2225-find-players-with-zero-or-one-losses/2225-find-players-with-zero-or-one-losses.py similarity index 100% rename from 2225-find-players-with-zero-or-one-losses/2225-find-players-with-zero-or-one-losses.py rename to problems/2225-find-players-with-zero-or-one-losses/2225-find-players-with-zero-or-one-losses.py diff --git a/2225-find-players-with-zero-or-one-losses/NOTES.md b/problems/2225-find-players-with-zero-or-one-losses/NOTES.md similarity index 100% rename from 2225-find-players-with-zero-or-one-losses/NOTES.md rename to problems/2225-find-players-with-zero-or-one-losses/NOTES.md diff --git a/problems/2225-find-players-with-zero-or-one-losses/README.md b/problems/2225-find-players-with-zero-or-one-losses/README.md new file mode 100644 index 000000000..7b31cde1e --- /dev/null +++ b/problems/2225-find-players-with-zero-or-one-losses/README.md @@ -0,0 +1,51 @@ +

2225. Find Players With Zero or One Losses

Medium


You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.

+ +

Return a list answer of size 2 where:

+ +
    +
  • answer[0] is a list of all players that have not lost any matches.
  • +
  • answer[1] is a list of all players that have lost exactly one match.
  • +
+ +

The values in the two lists should be returned in increasing order.

+ +

Note:

+ +
    +
  • You should only consider the players that have played at least one match.
  • +
  • The testcases will be generated such that no two matches will have the same outcome.
  • +
+ +

 

+

Example 1:

+ +
Input: matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
+Output: [[1,2,10],[4,5,7,8]]
+Explanation:
+Players 1, 2, and 10 have not lost any matches.
+Players 4, 5, 7, and 8 each have lost one match.
+Players 3, 6, and 9 each have lost two matches.
+Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].
+
+ +

Example 2:

+ +
Input: matches = [[2,3],[1,3],[5,4],[6,4]]
+Output: [[1,2,5,6],[]]
+Explanation:
+Players 1, 2, 5, and 6 have not lost any matches.
+Players 3 and 4 each have lost two matches.
+Thus, answer[0] = [1,2,5,6] and answer[1] = [].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= matches.length <= 105
  • +
  • matches[i].length == 2
  • +
  • 1 <= winneri, loseri <= 105
  • +
  • winneri != loseri
  • +
  • All matches[i] are unique.
  • +
+
\ No newline at end of file diff --git a/2251-number-of-flowers-in-full-bloom/2251-number-of-flowers-in-full-bloom.py b/problems/2251-number-of-flowers-in-full-bloom/2251-number-of-flowers-in-full-bloom.py similarity index 100% rename from 2251-number-of-flowers-in-full-bloom/2251-number-of-flowers-in-full-bloom.py rename to problems/2251-number-of-flowers-in-full-bloom/2251-number-of-flowers-in-full-bloom.py diff --git a/2251-number-of-flowers-in-full-bloom/NOTES.md b/problems/2251-number-of-flowers-in-full-bloom/NOTES.md similarity index 100% rename from 2251-number-of-flowers-in-full-bloom/NOTES.md rename to problems/2251-number-of-flowers-in-full-bloom/NOTES.md diff --git a/problems/2251-number-of-flowers-in-full-bloom/README.md b/problems/2251-number-of-flowers-in-full-bloom/README.md new file mode 100644 index 000000000..ad9361121 --- /dev/null +++ b/problems/2251-number-of-flowers-in-full-bloom/README.md @@ -0,0 +1,32 @@ +

2251. Number of Flowers in Full Bloom

Hard


You are given a 0-indexed 2D integer array flowers, where flowers[i] = [starti, endi] means the ith flower will be in full bloom from starti to endi (inclusive). You are also given a 0-indexed integer array people of size n, where people[i] is the time that the ith person will arrive to see the flowers.

+ +

Return an integer array answer of size n, where answer[i] is the number of flowers that are in full bloom when the ith person arrives.

+ +

 

+

Example 1:

+ +
Input: flowers = [[1,6],[3,7],[9,12],[4,13]], people = [2,3,7,11]
+Output: [1,2,2,2]
+Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
+For each person, we return the number of flowers in full bloom during their arrival.
+
+ +

Example 2:

+ +
Input: flowers = [[1,10],[3,3]], people = [3,3,2]
+Output: [2,2,1]
+Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
+For each person, we return the number of flowers in full bloom during their arrival.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= flowers.length <= 5 * 104
  • +
  • flowers[i].length == 2
  • +
  • 1 <= starti <= endi <= 109
  • +
  • 1 <= people.length <= 5 * 104
  • +
  • 1 <= people[i] <= 109
  • +
+
\ No newline at end of file diff --git a/2264-largest-3-same-digit-number-in-string/2264-largest-3-same-digit-number-in-string.py b/problems/2264-largest-3-same-digit-number-in-string/2264-largest-3-same-digit-number-in-string.py similarity index 100% rename from 2264-largest-3-same-digit-number-in-string/2264-largest-3-same-digit-number-in-string.py rename to problems/2264-largest-3-same-digit-number-in-string/2264-largest-3-same-digit-number-in-string.py diff --git a/2264-largest-3-same-digit-number-in-string/NOTES.md b/problems/2264-largest-3-same-digit-number-in-string/NOTES.md similarity index 100% rename from 2264-largest-3-same-digit-number-in-string/NOTES.md rename to problems/2264-largest-3-same-digit-number-in-string/NOTES.md diff --git a/problems/2264-largest-3-same-digit-number-in-string/README.md b/problems/2264-largest-3-same-digit-number-in-string/README.md new file mode 100644 index 000000000..6dfcc6a6c --- /dev/null +++ b/problems/2264-largest-3-same-digit-number-in-string/README.md @@ -0,0 +1,47 @@ +

2264. Largest 3-Same-Digit Number in String

Easy


You are given a string num representing a large integer. An integer is good if it meets the following conditions:

+ +
    +
  • It is a substring of num with length 3.
  • +
  • It consists of only one unique digit.
  • +
+ +

Return the maximum good integer as a string or an empty string "" if no such integer exists.

+ +

Note:

+ +
    +
  • A substring is a contiguous sequence of characters within a string.
  • +
  • There may be leading zeroes in num or a good integer.
  • +
+ +

 

+

Example 1:

+ +
Input: num = "6777133339"
+Output: "777"
+Explanation: There are two distinct good integers: "777" and "333".
+"777" is the largest, so we return "777".
+
+ +

Example 2:

+ +
Input: num = "2300019"
+Output: "000"
+Explanation: "000" is the only good integer.
+
+ +

Example 3:

+ +
Input: num = "42352338"
+Output: ""
+Explanation: No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= num.length <= 1000
  • +
  • num only consists of digits.
  • +
+
\ No newline at end of file diff --git a/2265-count-nodes-equal-to-average-of-subtree/2265-count-nodes-equal-to-average-of-subtree.py b/problems/2265-count-nodes-equal-to-average-of-subtree/2265-count-nodes-equal-to-average-of-subtree.py similarity index 100% rename from 2265-count-nodes-equal-to-average-of-subtree/2265-count-nodes-equal-to-average-of-subtree.py rename to problems/2265-count-nodes-equal-to-average-of-subtree/2265-count-nodes-equal-to-average-of-subtree.py diff --git a/problems/2265-count-nodes-equal-to-average-of-subtree/README.md b/problems/2265-count-nodes-equal-to-average-of-subtree/README.md new file mode 100644 index 000000000..d9972242f --- /dev/null +++ b/problems/2265-count-nodes-equal-to-average-of-subtree/README.md @@ -0,0 +1,37 @@ +

2265. Count Nodes Equal to Average of Subtree

Medium


Given the root of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree.

+ +

Note:

+ +
    +
  • The average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.
  • +
  • A subtree of root is a tree consisting of root and all of its descendants.
  • +
+ +

 

+

Example 1:

+ +
Input: root = [4,8,5,0,1,null,6]
+Output: 5
+Explanation: 
+For the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.
+For the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.
+For the node with value 0: The average of its subtree is 0 / 1 = 0.
+For the node with value 1: The average of its subtree is 1 / 1 = 1.
+For the node with value 6: The average of its subtree is 6 / 1 = 6.
+
+ +

Example 2:

+ +
Input: root = [1]
+Output: 1
+Explanation: For the node with value 1: The average of its subtree is 1 / 1 = 1.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 1000].
  • +
  • 0 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/2285-maximum-total-importance-of-roads/2285-maximum-total-importance-of-roads.py b/problems/2285-maximum-total-importance-of-roads/2285-maximum-total-importance-of-roads.py similarity index 100% rename from 2285-maximum-total-importance-of-roads/2285-maximum-total-importance-of-roads.py rename to problems/2285-maximum-total-importance-of-roads/2285-maximum-total-importance-of-roads.py diff --git a/2285-maximum-total-importance-of-roads/NOTES.md b/problems/2285-maximum-total-importance-of-roads/NOTES.md similarity index 100% rename from 2285-maximum-total-importance-of-roads/NOTES.md rename to problems/2285-maximum-total-importance-of-roads/NOTES.md diff --git a/2331-evaluate-boolean-binary-tree/2331-evaluate-boolean-binary-tree.py b/problems/2331-evaluate-boolean-binary-tree/2331-evaluate-boolean-binary-tree.py similarity index 100% rename from 2331-evaluate-boolean-binary-tree/2331-evaluate-boolean-binary-tree.py rename to problems/2331-evaluate-boolean-binary-tree/2331-evaluate-boolean-binary-tree.py diff --git a/problems/2331-evaluate-boolean-binary-tree/README.md b/problems/2331-evaluate-boolean-binary-tree/README.md new file mode 100644 index 000000000..d563a4b93 --- /dev/null +++ b/problems/2331-evaluate-boolean-binary-tree/README.md @@ -0,0 +1,48 @@ +

2331. Evaluate Boolean Binary Tree

Easy


You are given the root of a full binary tree with the following properties:

+ +
    +
  • Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True.
  • +
  • Non-leaf nodes have either the value 2 or 3, where 2 represents the boolean OR and 3 represents the boolean AND.
  • +
+ +

The evaluation of a node is as follows:

+ +
    +
  • If the node is a leaf node, the evaluation is the value of the node, i.e. True or False.
  • +
  • Otherwise, evaluate the node's two children and apply the boolean operation of its value with the children's evaluations.
  • +
+ +

Return the boolean result of evaluating the root node.

+ +

A full binary tree is a binary tree where each node has either 0 or 2 children.

+ +

A leaf node is a node that has zero children.

+ +

 

+

Example 1:

+ +
Input: root = [2,1,3,null,null,0,1]
+Output: true
+Explanation: The above diagram illustrates the evaluation process.
+The AND node evaluates to False AND True = False.
+The OR node evaluates to True OR False = True.
+The root node evaluates to True, so we return true.
+ +

Example 2:

+ +
Input: root = [0]
+Output: false
+Explanation: The root node is a leaf node and it evaluates to false, so we return false.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 1000].
  • +
  • 0 <= Node.val <= 3
  • +
  • Every node has either 0 or 2 children.
  • +
  • Leaf nodes have a value of 0 or 1.
  • +
  • Non-leaf nodes have a value of 2 or 3.
  • +
+
\ No newline at end of file diff --git a/2353-design-a-food-rating-system/2353-design-a-food-rating-system.py b/problems/2353-design-a-food-rating-system/2353-design-a-food-rating-system.py similarity index 100% rename from 2353-design-a-food-rating-system/2353-design-a-food-rating-system.py rename to problems/2353-design-a-food-rating-system/2353-design-a-food-rating-system.py diff --git a/2353-design-a-food-rating-system/NOTES.md b/problems/2353-design-a-food-rating-system/NOTES.md similarity index 100% rename from 2353-design-a-food-rating-system/NOTES.md rename to problems/2353-design-a-food-rating-system/NOTES.md diff --git a/problems/2353-design-a-food-rating-system/README.md b/problems/2353-design-a-food-rating-system/README.md new file mode 100644 index 000000000..085588a8b --- /dev/null +++ b/problems/2353-design-a-food-rating-system/README.md @@ -0,0 +1,63 @@ +

2353. Design a Food Rating System

Medium


Design a food rating system that can do the following:

+ +
    +
  • Modify the rating of a food item listed in the system.
  • +
  • Return the highest-rated food item for a type of cuisine in the system.
  • +
+ +

Implement the FoodRatings class:

+ +
    +
  • FoodRatings(String[] foods, String[] cuisines, int[] ratings) Initializes the system. The food items are described by foods, cuisines and ratings, all of which have a length of n. + +
      +
    • foods[i] is the name of the ith food,
    • +
    • cuisines[i] is the type of cuisine of the ith food, and
    • +
    • ratings[i] is the initial rating of the ith food.
    • +
    +
  • +
  • void changeRating(String food, int newRating) Changes the rating of the food item with the name food.
  • +
  • String highestRated(String cuisine) Returns the name of the food item that has the highest rating for the given type of cuisine. If there is a tie, return the item with the lexicographically smaller name.
  • +
+ +

Note that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.

+ +

 

+

Example 1:

+ +
Input
+["FoodRatings", "highestRated", "highestRated", "changeRating", "highestRated", "changeRating", "highestRated"]
+[[["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]], ["korean"], ["japanese"], ["sushi", 16], ["japanese"], ["ramen", 16], ["japanese"]]
+Output
+[null, "kimchi", "ramen", null, "sushi", null, "ramen"]
+
+Explanation
+FoodRatings foodRatings = new FoodRatings(["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]);
+foodRatings.highestRated("korean"); // return "kimchi"
+                                    // "kimchi" is the highest rated korean food with a rating of 9.
+foodRatings.highestRated("japanese"); // return "ramen"
+                                      // "ramen" is the highest rated japanese food with a rating of 14.
+foodRatings.changeRating("sushi", 16); // "sushi" now has a rating of 16.
+foodRatings.highestRated("japanese"); // return "sushi"
+                                      // "sushi" is the highest rated japanese food with a rating of 16.
+foodRatings.changeRating("ramen", 16); // "ramen" now has a rating of 16.
+foodRatings.highestRated("japanese"); // return "ramen"
+                                      // Both "sushi" and "ramen" have a rating of 16.
+                                      // However, "ramen" is lexicographically smaller than "sushi".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 2 * 104
  • +
  • n == foods.length == cuisines.length == ratings.length
  • +
  • 1 <= foods[i].length, cuisines[i].length <= 10
  • +
  • foods[i], cuisines[i] consist of lowercase English letters.
  • +
  • 1 <= ratings[i] <= 108
  • +
  • All the strings in foods are distinct.
  • +
  • food will be the name of a food item in the system across all calls to changeRating.
  • +
  • cuisine will be a type of cuisine of at least one food item in the system across all calls to highestRated.
  • +
  • At most 2 * 104 calls in total will be made to changeRating and highestRated.
  • +
+
\ No newline at end of file diff --git a/2355-maximum-number-of-books-you-can-take/2355-maximum-number-of-books-you-can-take.py b/problems/2355-maximum-number-of-books-you-can-take/2355-maximum-number-of-books-you-can-take.py similarity index 100% rename from 2355-maximum-number-of-books-you-can-take/2355-maximum-number-of-books-you-can-take.py rename to problems/2355-maximum-number-of-books-you-can-take/2355-maximum-number-of-books-you-can-take.py diff --git a/2355-maximum-number-of-books-you-can-take/NOTES.md b/problems/2355-maximum-number-of-books-you-can-take/NOTES.md similarity index 100% rename from 2355-maximum-number-of-books-you-can-take/NOTES.md rename to problems/2355-maximum-number-of-books-you-can-take/NOTES.md diff --git a/problems/2355-maximum-number-of-books-you-can-take/README.md b/problems/2355-maximum-number-of-books-you-can-take/README.md new file mode 100644 index 000000000..91b9f2e9a --- /dev/null +++ b/problems/2355-maximum-number-of-books-you-can-take/README.md @@ -0,0 +1,53 @@ +

2355. Maximum Number of Books You Can Take

Hard


You are given a 0-indexed integer array books of length n where books[i] denotes the number of books on the ith shelf of a bookshelf.

+ +

You are going to take books from a contiguous section of the bookshelf spanning from l to r where 0 <= l <= r < n. For each index i in the range l <= i < r, you must take strictly fewer books from shelf i than shelf i + 1.

+ +

Return the maximum number of books you can take from the bookshelf.

+ +

 

+

Example 1:

+ +
Input: books = [8,5,2,7,9]
+Output: 19
+Explanation:
+- Take 1 book from shelf 1.
+- Take 2 books from shelf 2.
+- Take 7 books from shelf 3.
+- Take 9 books from shelf 4.
+You have taken 19 books, so return 19.
+It can be proven that 19 is the maximum number of books you can take.
+
+ +

Example 2:

+ +
Input: books = [7,0,3,4,5]
+Output: 12
+Explanation:
+- Take 3 books from shelf 2.
+- Take 4 books from shelf 3.
+- Take 5 books from shelf 4.
+You have taken 12 books so return 12.
+It can be proven that 12 is the maximum number of books you can take.
+
+ +

Example 3:

+ +
Input: books = [8,2,3,7,3,4,0,1,4,3]
+Output: 13
+Explanation:
+- Take 1 book from shelf 0.
+- Take 2 books from shelf 1.
+- Take 3 books from shelf 2.
+- Take 7 books from shelf 3.
+You have taken 13 books so return 13.
+It can be proven that 13 is the maximum number of books you can take.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= books.length <= 105
  • +
  • 0 <= books[i] <= 105
  • +
+
\ No newline at end of file diff --git a/2361-minimum-costs-using-the-train-line/2361-minimum-costs-using-the-train-line.py b/problems/2361-minimum-costs-using-the-train-line/2361-minimum-costs-using-the-train-line.py similarity index 100% rename from 2361-minimum-costs-using-the-train-line/2361-minimum-costs-using-the-train-line.py rename to problems/2361-minimum-costs-using-the-train-line/2361-minimum-costs-using-the-train-line.py diff --git a/2361-minimum-costs-using-the-train-line/NOTES.md b/problems/2361-minimum-costs-using-the-train-line/NOTES.md similarity index 100% rename from 2361-minimum-costs-using-the-train-line/NOTES.md rename to problems/2361-minimum-costs-using-the-train-line/NOTES.md diff --git a/problems/2361-minimum-costs-using-the-train-line/README.md b/problems/2361-minimum-costs-using-the-train-line/README.md new file mode 100644 index 000000000..be82d6997 --- /dev/null +++ b/problems/2361-minimum-costs-using-the-train-line/README.md @@ -0,0 +1,53 @@ +

2361. Minimum Costs Using the Train Line

Hard


A train line going through a city has two routes, the regular route and the express route. Both routes go through the same n + 1 stops labeled from 0 to n. Initially, you start on the regular route at stop 0.

+ +

You are given two 1-indexed integer arrays regular and express, both of length n. regular[i] describes the cost it takes to go from stop i - 1 to stop i using the regular route, and express[i] describes the cost it takes to go from stop i - 1 to stop i using the express route.

+ +

You are also given an integer expressCost which represents the cost to transfer from the regular route to the express route.

+ +

Note that:

+ +
    +
  • There is no cost to transfer from the express route back to the regular route.
  • +
  • You pay expressCost every time you transfer from the regular route to the express route.
  • +
  • There is no extra cost to stay on the express route.
  • +
+ +

Return a 1-indexed array costs of length n, where costs[i] is the minimum cost to reach stop i from stop 0.

+ +

Note that a stop can be counted as reached from either route.

+ +

 

+

Example 1:

+ +
Input: regular = [1,6,9,5], express = [5,2,3,10], expressCost = 8
+Output: [1,7,14,19]
+Explanation: The diagram above shows how to reach stop 4 from stop 0 with minimum cost.
+- Take the regular route from stop 0 to stop 1, costing 1.
+- Take the express route from stop 1 to stop 2, costing 8 + 2 = 10.
+- Take the express route from stop 2 to stop 3, costing 3.
+- Take the regular route from stop 3 to stop 4, costing 5.
+The total cost is 1 + 10 + 3 + 5 = 19.
+Note that a different route could be taken to reach the other stops with minimum cost.
+
+ +

Example 2:

+ +
Input: regular = [11,5,13], express = [7,10,6], expressCost = 3
+Output: [10,15,24]
+Explanation: The diagram above shows how to reach stop 3 from stop 0 with minimum cost.
+- Take the express route from stop 0 to stop 1, costing 3 + 7 = 10.
+- Take the regular route from stop 1 to stop 2, costing 5.
+- Take the express route from stop 2 to stop 3, costing 3 + 6 = 9.
+The total cost is 10 + 5 + 9 = 24.
+Note that the expressCost is paid again to transfer back to the express route.
+
+ +

 

+

Constraints:

+ +
    +
  • n == regular.length == express.length
  • +
  • 1 <= n <= 105
  • +
  • 1 <= regular[i], express[i], expressCost <= 105
  • +
+
\ No newline at end of file diff --git a/2366-minimum-replacements-to-sort-the-array/2366-minimum-replacements-to-sort-the-array.py b/problems/2366-minimum-replacements-to-sort-the-array/2366-minimum-replacements-to-sort-the-array.py similarity index 100% rename from 2366-minimum-replacements-to-sort-the-array/2366-minimum-replacements-to-sort-the-array.py rename to problems/2366-minimum-replacements-to-sort-the-array/2366-minimum-replacements-to-sort-the-array.py diff --git a/problems/2366-minimum-replacements-to-sort-the-array/README.md b/problems/2366-minimum-replacements-to-sort-the-array/README.md new file mode 100644 index 000000000..19164773b --- /dev/null +++ b/problems/2366-minimum-replacements-to-sort-the-array/README.md @@ -0,0 +1,35 @@ +

2366. Minimum Replacements to Sort the Array

Hard


You are given a 0-indexed integer array nums. In one operation you can replace any element of the array with any two elements that sum to it.

+ +
    +
  • For example, consider nums = [5,6,7]. In one operation, we can replace nums[1] with 2 and 4 and convert nums to [5,2,4,7].
  • +
+ +

Return the minimum number of operations to make an array that is sorted in non-decreasing order.

+ +

 

+

Example 1:

+ +
Input: nums = [3,9,3]
+Output: 2
+Explanation: Here are the steps to sort the array in non-decreasing order:
+- From [3,9,3], replace the 9 with 3 and 6 so the array becomes [3,3,6,3]
+- From [3,3,6,3], replace the 6 with 3 and 3 so the array becomes [3,3,3,3,3]
+There are 2 steps to sort the array in non-decreasing order. Therefore, we return 2.
+
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,4,5]
+Output: 0
+Explanation: The array is already in non-decreasing order. Therefore, we return 0. 
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/2369-check-if-there-is-a-valid-partition-for-the-array/2369-check-if-there-is-a-valid-partition-for-the-array.py b/problems/2369-check-if-there-is-a-valid-partition-for-the-array/2369-check-if-there-is-a-valid-partition-for-the-array.py similarity index 100% rename from 2369-check-if-there-is-a-valid-partition-for-the-array/2369-check-if-there-is-a-valid-partition-for-the-array.py rename to problems/2369-check-if-there-is-a-valid-partition-for-the-array/2369-check-if-there-is-a-valid-partition-for-the-array.py diff --git a/problems/2369-check-if-there-is-a-valid-partition-for-the-array/README.md b/problems/2369-check-if-there-is-a-valid-partition-for-the-array/README.md new file mode 100644 index 000000000..9f45a5c98 --- /dev/null +++ b/problems/2369-check-if-there-is-a-valid-partition-for-the-array/README.md @@ -0,0 +1,36 @@ +

2369. Check if There is a Valid Partition For The Array

Medium


You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays.

+ +

We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions:

+ +
    +
  1. The subarray consists of exactly 2 equal elements. For example, the subarray [2,2] is good.
  2. +
  3. The subarray consists of exactly 3 equal elements. For example, the subarray [4,4,4] is good.
  4. +
  5. The subarray consists of exactly 3 consecutive increasing elements, that is, the difference between adjacent elements is 1. For example, the subarray [3,4,5] is good, but the subarray [1,3,5] is not.
  6. +
+ +

Return true if the array has at least one valid partition. Otherwise, return false.

+ +

 

+

Example 1:

+ +
Input: nums = [4,4,4,5,6]
+Output: true
+Explanation: The array can be partitioned into the subarrays [4,4] and [4,5,6].
+This partition is valid, so we return true.
+
+ +

Example 2:

+ +
Input: nums = [1,1,1,2]
+Output: false
+Explanation: There is no valid partition for this array.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 106
  • +
+
\ No newline at end of file diff --git a/2370-longest-ideal-subsequence/2370-longest-ideal-subsequence.py b/problems/2370-longest-ideal-subsequence/2370-longest-ideal-subsequence.py similarity index 100% rename from 2370-longest-ideal-subsequence/2370-longest-ideal-subsequence.py rename to problems/2370-longest-ideal-subsequence/2370-longest-ideal-subsequence.py diff --git a/2370-longest-ideal-subsequence/NOTES.md b/problems/2370-longest-ideal-subsequence/NOTES.md similarity index 100% rename from 2370-longest-ideal-subsequence/NOTES.md rename to problems/2370-longest-ideal-subsequence/NOTES.md diff --git a/problems/2370-longest-ideal-subsequence/README.md b/problems/2370-longest-ideal-subsequence/README.md new file mode 100644 index 000000000..17c7257e5 --- /dev/null +++ b/problems/2370-longest-ideal-subsequence/README.md @@ -0,0 +1,37 @@ +

2370. Longest Ideal Subsequence

Medium


You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:

+ +
    +
  • t is a subsequence of the string s.
  • +
  • The absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.
  • +
+ +

Return the length of the longest ideal string.

+ +

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

+ +

Note that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of 'a' and 'z' is 25, not 1.

+ +

 

+

Example 1:

+ +
Input: s = "acfgbd", k = 2
+Output: 4
+Explanation: The longest ideal string is "acbd". The length of this string is 4, so 4 is returned.
+Note that "acfgbd" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.
+ +

Example 2:

+ +
Input: s = "abcd", k = 3
+Output: 4
+Explanation: The longest ideal string is "abcd". The length of this string is 4, so 4 is returned.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • 0 <= k <= 25
  • +
  • s consists of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2373-largest-local-values-in-a-matrix/2373-largest-local-values-in-a-matrix.py b/problems/2373-largest-local-values-in-a-matrix/2373-largest-local-values-in-a-matrix.py similarity index 100% rename from 2373-largest-local-values-in-a-matrix/2373-largest-local-values-in-a-matrix.py rename to problems/2373-largest-local-values-in-a-matrix/2373-largest-local-values-in-a-matrix.py diff --git a/2373-largest-local-values-in-a-matrix/NOTES.md b/problems/2373-largest-local-values-in-a-matrix/NOTES.md similarity index 100% rename from 2373-largest-local-values-in-a-matrix/NOTES.md rename to problems/2373-largest-local-values-in-a-matrix/NOTES.md diff --git a/problems/2373-largest-local-values-in-a-matrix/README.md b/problems/2373-largest-local-values-in-a-matrix/README.md new file mode 100644 index 000000000..b70175aef --- /dev/null +++ b/problems/2373-largest-local-values-in-a-matrix/README.md @@ -0,0 +1,36 @@ +

2373. Largest Local Values in a Matrix

Easy


You are given an n x n integer matrix grid.

+ +

Generate an integer matrix maxLocal of size (n - 2) x (n - 2) such that:

+ +
    +
  • maxLocal[i][j] is equal to the largest value of the 3 x 3 matrix in grid centered around row i + 1 and column j + 1.
  • +
+ +

In other words, we want to find the largest value in every contiguous 3 x 3 matrix in grid.

+ +

Return the generated matrix.

+ +

 

+

Example 1:

+ +
Input: grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
+Output: [[9,9],[8,6]]
+Explanation: The diagram above shows the original matrix and the generated matrix.
+Notice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.
+ +

Example 2:

+ +
Input: grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]
+Output: [[2,2,2],[2,2,2],[2,2,2]]
+Explanation: Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid.
+
+ +

 

+

Constraints:

+ +
    +
  • n == grid.length == grid[i].length
  • +
  • 3 <= n <= 100
  • +
  • 1 <= grid[i][j] <= 100
  • +
+
\ No newline at end of file diff --git a/2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.py b/problems/2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.py similarity index 100% rename from 2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.py rename to problems/2385-amount-of-time-for-binary-tree-to-be-infected/2385-amount-of-time-for-binary-tree-to-be-infected.py diff --git a/2385-amount-of-time-for-binary-tree-to-be-infected/NOTES.md b/problems/2385-amount-of-time-for-binary-tree-to-be-infected/NOTES.md similarity index 100% rename from 2385-amount-of-time-for-binary-tree-to-be-infected/NOTES.md rename to problems/2385-amount-of-time-for-binary-tree-to-be-infected/NOTES.md diff --git a/problems/2385-amount-of-time-for-binary-tree-to-be-infected/README.md b/problems/2385-amount-of-time-for-binary-tree-to-be-infected/README.md new file mode 100644 index 000000000..4c9f31b3c --- /dev/null +++ b/problems/2385-amount-of-time-for-binary-tree-to-be-infected/README.md @@ -0,0 +1,42 @@ +

2385. Amount of Time for Binary Tree to Be Infected

Medium


You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start.

+ +

Each minute, a node becomes infected if:

+ +
    +
  • The node is currently uninfected.
  • +
  • The node is adjacent to an infected node.
  • +
+ +

Return the number of minutes needed for the entire tree to be infected.

+ +

 

+

Example 1:

+ +
Input: root = [1,5,3,null,4,10,6,9,2], start = 3
+Output: 4
+Explanation: The following nodes are infected during:
+- Minute 0: Node 3
+- Minute 1: Nodes 1, 10 and 6
+- Minute 2: Node 5
+- Minute 3: Node 4
+- Minute 4: Nodes 9 and 2
+It takes 4 minutes for the whole tree to be infected so we return 4.
+
+ +

Example 2:

+ +
Input: root = [1], start = 1
+Output: 0
+Explanation: At minute 0, the only node in the tree is infected so we return 0.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the tree is in the range [1, 105].
  • +
  • 1 <= Node.val <= 105
  • +
  • Each node has a unique value.
  • +
  • A node with a value of start exists in the tree.
  • +
+
\ No newline at end of file diff --git a/2391-minimum-amount-of-time-to-collect-garbage/2391-minimum-amount-of-time-to-collect-garbage.py b/problems/2391-minimum-amount-of-time-to-collect-garbage/2391-minimum-amount-of-time-to-collect-garbage.py similarity index 100% rename from 2391-minimum-amount-of-time-to-collect-garbage/2391-minimum-amount-of-time-to-collect-garbage.py rename to problems/2391-minimum-amount-of-time-to-collect-garbage/2391-minimum-amount-of-time-to-collect-garbage.py diff --git a/2391-minimum-amount-of-time-to-collect-garbage/NOTES.md b/problems/2391-minimum-amount-of-time-to-collect-garbage/NOTES.md similarity index 100% rename from 2391-minimum-amount-of-time-to-collect-garbage/NOTES.md rename to problems/2391-minimum-amount-of-time-to-collect-garbage/NOTES.md diff --git a/problems/2391-minimum-amount-of-time-to-collect-garbage/README.md b/problems/2391-minimum-amount-of-time-to-collect-garbage/README.md new file mode 100644 index 000000000..8a44ad8cc --- /dev/null +++ b/problems/2391-minimum-amount-of-time-to-collect-garbage/README.md @@ -0,0 +1,56 @@ +

2391. Minimum Amount of Time to Collect Garbage

Medium


You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking up one unit of any type of garbage takes 1 minute.

+ +

You are also given a 0-indexed integer array travel where travel[i] is the number of minutes needed to go from house i to house i + 1.

+ +

There are three garbage trucks in the city, each responsible for picking up one type of garbage. Each garbage truck starts at house 0 and must visit each house in order; however, they do not need to visit every house.

+ +

Only one garbage truck may be used at any given moment. While one truck is driving or picking up garbage, the other two trucks cannot do anything.

+ +

Return the minimum number of minutes needed to pick up all the garbage.

+ +

 

+

Example 1:

+ +
Input: garbage = ["G","P","GP","GG"], travel = [2,4,3]
+Output: 21
+Explanation:
+The paper garbage truck:
+1. Travels from house 0 to house 1
+2. Collects the paper garbage at house 1
+3. Travels from house 1 to house 2
+4. Collects the paper garbage at house 2
+Altogether, it takes 8 minutes to pick up all the paper garbage.
+The glass garbage truck:
+1. Collects the glass garbage at house 0
+2. Travels from house 0 to house 1
+3. Travels from house 1 to house 2
+4. Collects the glass garbage at house 2
+5. Travels from house 2 to house 3
+6. Collects the glass garbage at house 3
+Altogether, it takes 13 minutes to pick up all the glass garbage.
+Since there is no metal garbage, we do not need to consider the metal garbage truck.
+Therefore, it takes a total of 8 + 13 = 21 minutes to collect all the garbage.
+
+ +

Example 2:

+ +
Input: garbage = ["MMM","PGM","GP"], travel = [3,10]
+Output: 37
+Explanation:
+The metal garbage truck takes 7 minutes to pick up all the metal garbage.
+The paper garbage truck takes 15 minutes to pick up all the paper garbage.
+The glass garbage truck takes 15 minutes to pick up all the glass garbage.
+It takes a total of 7 + 15 + 15 = 37 minutes to collect all the garbage.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= garbage.length <= 105
  • +
  • garbage[i] consists of only the letters 'M', 'P', and 'G'.
  • +
  • 1 <= garbage[i].length <= 10
  • +
  • travel.length == garbage.length - 1
  • +
  • 1 <= travel[i] <= 100
  • +
+
\ No newline at end of file diff --git a/2392-build-a-matrix-with-conditions/2392-build-a-matrix-with-conditions.py b/problems/2392-build-a-matrix-with-conditions/2392-build-a-matrix-with-conditions.py similarity index 100% rename from 2392-build-a-matrix-with-conditions/2392-build-a-matrix-with-conditions.py rename to problems/2392-build-a-matrix-with-conditions/2392-build-a-matrix-with-conditions.py diff --git a/problems/2392-build-a-matrix-with-conditions/README.md b/problems/2392-build-a-matrix-with-conditions/README.md new file mode 100644 index 000000000..83a8ca6c2 --- /dev/null +++ b/problems/2392-build-a-matrix-with-conditions/README.md @@ -0,0 +1,55 @@ +

2392. Build a Matrix With Conditions

Hard


You are given a positive integer k. You are also given:

+ +
    +
  • a 2D integer array rowConditions of size n where rowConditions[i] = [abovei, belowi], and
  • +
  • a 2D integer array colConditions of size m where colConditions[i] = [lefti, righti].
  • +
+ +

The two arrays contain integers from 1 to k.

+ +

You have to build a k x k matrix that contains each of the numbers from 1 to k exactly once. The remaining cells should have the value 0.

+ +

The matrix should also satisfy the following conditions:

+ +
    +
  • The number abovei should appear in a row that is strictly above the row at which the number belowi appears for all i from 0 to n - 1.
  • +
  • The number lefti should appear in a column that is strictly left of the column at which the number righti appears for all i from 0 to m - 1.
  • +
+ +

Return any matrix that satisfies the conditions. If no answer exists, return an empty matrix.

+ +

 

+

Example 1:

+ +
Input: k = 3, rowConditions = [[1,2],[3,2]], colConditions = [[2,1],[3,2]]
+Output: [[3,0,0],[0,0,1],[0,2,0]]
+Explanation: The diagram above shows a valid example of a matrix that satisfies all the conditions.
+The row conditions are the following:
+- Number 1 is in row 1, and number 2 is in row 2, so 1 is above 2 in the matrix.
+- Number 3 is in row 0, and number 2 is in row 2, so 3 is above 2 in the matrix.
+The column conditions are the following:
+- Number 2 is in column 1, and number 1 is in column 2, so 2 is left of 1 in the matrix.
+- Number 3 is in column 0, and number 2 is in column 1, so 3 is left of 2 in the matrix.
+Note that there may be multiple correct answers.
+
+ +

Example 2:

+ +
Input: k = 3, rowConditions = [[1,2],[2,3],[3,1],[2,3]], colConditions = [[2,1]]
+Output: []
+Explanation: From the first two conditions, 3 has to be below 1 but the third conditions needs 3 to be above 1 to be satisfied.
+No matrix can satisfy all the conditions, so we return the empty matrix.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= k <= 400
  • +
  • 1 <= rowConditions.length, colConditions.length <= 104
  • +
  • rowConditions[i].length == colConditions[i].length == 2
  • +
  • 1 <= abovei, belowi, lefti, righti <= k
  • +
  • abovei != belowi
  • +
  • lefti != righti
  • +
+
\ No newline at end of file diff --git a/2393-count-strictly-increasing-subarrays/2393-count-strictly-increasing-subarrays.py b/problems/2393-count-strictly-increasing-subarrays/2393-count-strictly-increasing-subarrays.py similarity index 100% rename from 2393-count-strictly-increasing-subarrays/2393-count-strictly-increasing-subarrays.py rename to problems/2393-count-strictly-increasing-subarrays/2393-count-strictly-increasing-subarrays.py diff --git a/2393-count-strictly-increasing-subarrays/NOTES.md b/problems/2393-count-strictly-increasing-subarrays/NOTES.md similarity index 100% rename from 2393-count-strictly-increasing-subarrays/NOTES.md rename to problems/2393-count-strictly-increasing-subarrays/NOTES.md diff --git a/problems/2393-count-strictly-increasing-subarrays/README.md b/problems/2393-count-strictly-increasing-subarrays/README.md new file mode 100644 index 000000000..b3cc7aff2 --- /dev/null +++ b/problems/2393-count-strictly-increasing-subarrays/README.md @@ -0,0 +1,33 @@ +

2393. Count Strictly Increasing Subarrays

Medium


You are given an array nums consisting of positive integers.

+ +

Return the number of subarrays of nums that are in strictly increasing order.

+ +

A subarray is a contiguous part of an array.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3,5,4,4,6]
+Output: 10
+Explanation: The strictly increasing subarrays are the following:
+- Subarrays of length 1: [1], [3], [5], [4], [4], [6].
+- Subarrays of length 2: [1,3], [3,5], [4,6].
+- Subarrays of length 3: [1,3,5].
+The total number of subarrays is 6 + 3 + 1 = 10.
+
+ +

Example 2:

+ +
Input: nums = [1,2,3,4,5]
+Output: 15
+Explanation: Every subarray is strictly increasing. There are 15 possible subarrays that we can take.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 106
  • +
+
\ No newline at end of file diff --git a/2402-meeting-rooms-iii/2402-meeting-rooms-iii.py b/problems/2402-meeting-rooms-iii/2402-meeting-rooms-iii.py similarity index 100% rename from 2402-meeting-rooms-iii/2402-meeting-rooms-iii.py rename to problems/2402-meeting-rooms-iii/2402-meeting-rooms-iii.py diff --git a/2402-meeting-rooms-iii/NOTES.md b/problems/2402-meeting-rooms-iii/NOTES.md similarity index 100% rename from 2402-meeting-rooms-iii/NOTES.md rename to problems/2402-meeting-rooms-iii/NOTES.md diff --git a/problems/2402-meeting-rooms-iii/README.md b/problems/2402-meeting-rooms-iii/README.md new file mode 100644 index 000000000..fffc9ee80 --- /dev/null +++ b/problems/2402-meeting-rooms-iii/README.md @@ -0,0 +1,57 @@ +

2402. Meeting Rooms III

Hard


You are given an integer n. There are n rooms numbered from 0 to n - 1.

+ +

You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.

+ +

Meetings are allocated to rooms in the following manner:

+ +
    +
  1. Each meeting will take place in the unused room with the lowest number.
  2. +
  3. If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.
  4. +
  5. When a room becomes unused, meetings that have an earlier original start time should be given the room.
  6. +
+ +

Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.

+ +

A half-closed interval [a, b) is the interval between a and b including a and not including b.

+ +

 

+

Example 1:

+ +
Input: n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
+Output: 0
+Explanation:
+- At time 0, both rooms are not being used. The first meeting starts in room 0.
+- At time 1, only room 1 is not being used. The second meeting starts in room 1.
+- At time 2, both rooms are being used. The third meeting is delayed.
+- At time 3, both rooms are being used. The fourth meeting is delayed.
+- At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).
+- At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).
+Both rooms 0 and 1 held 2 meetings, so we return 0. 
+
+ +

Example 2:

+ +
Input: n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]
+Output: 1
+Explanation:
+- At time 1, all three rooms are not being used. The first meeting starts in room 0.
+- At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.
+- At time 3, only room 2 is not being used. The third meeting starts in room 2.
+- At time 4, all three rooms are being used. The fourth meeting is delayed.
+- At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).
+- At time 6, all three rooms are being used. The fifth meeting is delayed.
+- At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).
+Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1. 
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 100
  • +
  • 1 <= meetings.length <= 105
  • +
  • meetings[i].length == 2
  • +
  • 0 <= starti < endi <= 5 * 105
  • +
  • All the values of starti are unique.
  • +
+
\ No newline at end of file diff --git a/2418-sort-the-people/2418-sort-the-people.py b/problems/2418-sort-the-people/2418-sort-the-people.py similarity index 100% rename from 2418-sort-the-people/2418-sort-the-people.py rename to problems/2418-sort-the-people/2418-sort-the-people.py diff --git a/2418-sort-the-people/NOTES.md b/problems/2418-sort-the-people/NOTES.md similarity index 100% rename from 2418-sort-the-people/NOTES.md rename to problems/2418-sort-the-people/NOTES.md diff --git a/problems/2418-sort-the-people/README.md b/problems/2418-sort-the-people/README.md new file mode 100644 index 000000000..2f291942a --- /dev/null +++ b/problems/2418-sort-the-people/README.md @@ -0,0 +1,33 @@ +

2418. Sort the People

Easy


You are given an array of strings names, and an array heights that consists of distinct positive integers. Both arrays are of length n.

+ +

For each index i, names[i] and heights[i] denote the name and height of the ith person.

+ +

Return names sorted in descending order by the people's heights.

+ +

 

+

Example 1:

+ +
Input: names = ["Mary","John","Emma"], heights = [180,165,170]
+Output: ["Mary","Emma","John"]
+Explanation: Mary is the tallest, followed by Emma and John.
+
+ +

Example 2:

+ +
Input: names = ["Alice","Bob","Bob"], heights = [155,185,150]
+Output: ["Bob","Alice","Bob"]
+Explanation: The first Bob is the tallest, followed by Alice and the second Bob.
+
+ +

 

+

Constraints:

+ +
    +
  • n == names.length == heights.length
  • +
  • 1 <= n <= 103
  • +
  • 1 <= names[i].length <= 20
  • +
  • 1 <= heights[i] <= 105
  • +
  • names[i] consists of lower and upper case English letters.
  • +
  • All the values of heights are distinct.
  • +
+
\ No newline at end of file diff --git a/2433-find-the-original-array-of-prefix-xor/2433-find-the-original-array-of-prefix-xor.py b/problems/2433-find-the-original-array-of-prefix-xor/2433-find-the-original-array-of-prefix-xor.py similarity index 100% rename from 2433-find-the-original-array-of-prefix-xor/2433-find-the-original-array-of-prefix-xor.py rename to problems/2433-find-the-original-array-of-prefix-xor/2433-find-the-original-array-of-prefix-xor.py diff --git a/2433-find-the-original-array-of-prefix-xor/NOTES.md b/problems/2433-find-the-original-array-of-prefix-xor/NOTES.md similarity index 100% rename from 2433-find-the-original-array-of-prefix-xor/NOTES.md rename to problems/2433-find-the-original-array-of-prefix-xor/NOTES.md diff --git a/problems/2433-find-the-original-array-of-prefix-xor/README.md b/problems/2433-find-the-original-array-of-prefix-xor/README.md new file mode 100644 index 000000000..380a3f994 --- /dev/null +++ b/problems/2433-find-the-original-array-of-prefix-xor/README.md @@ -0,0 +1,38 @@ +

2433. Find The Original Array of Prefix Xor

Medium


You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:

+ +
    +
  • pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].
  • +
+ +

Note that ^ denotes the bitwise-xor operation.

+ +

It can be proven that the answer is unique.

+ +

 

+

Example 1:

+ +
Input: pref = [5,2,0,3,1]
+Output: [5,7,2,3,2]
+Explanation: From the array [5,7,2,3,2] we have the following:
+- pref[0] = 5.
+- pref[1] = 5 ^ 7 = 2.
+- pref[2] = 5 ^ 7 ^ 2 = 0.
+- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
+- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
+
+ +

Example 2:

+ +
Input: pref = [13]
+Output: [13]
+Explanation: We have pref[0] = arr[0] = 13.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= pref.length <= 105
  • +
  • 0 <= pref[i] <= 106
  • +
+
\ No newline at end of file diff --git a/2441-largest-positive-integer-that-exists-with-its-negative/2441-largest-positive-integer-that-exists-with-its-negative.py b/problems/2441-largest-positive-integer-that-exists-with-its-negative/2441-largest-positive-integer-that-exists-with-its-negative.py similarity index 100% rename from 2441-largest-positive-integer-that-exists-with-its-negative/2441-largest-positive-integer-that-exists-with-its-negative.py rename to problems/2441-largest-positive-integer-that-exists-with-its-negative/2441-largest-positive-integer-that-exists-with-its-negative.py diff --git a/2441-largest-positive-integer-that-exists-with-its-negative/NOTES.md b/problems/2441-largest-positive-integer-that-exists-with-its-negative/NOTES.md similarity index 100% rename from 2441-largest-positive-integer-that-exists-with-its-negative/NOTES.md rename to problems/2441-largest-positive-integer-that-exists-with-its-negative/NOTES.md diff --git a/problems/2441-largest-positive-integer-that-exists-with-its-negative/README.md b/problems/2441-largest-positive-integer-that-exists-with-its-negative/README.md new file mode 100644 index 000000000..6a8246721 --- /dev/null +++ b/problems/2441-largest-positive-integer-that-exists-with-its-negative/README.md @@ -0,0 +1,35 @@ +

2441. Largest Positive Integer That Exists With Its Negative

Easy


Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.

+ +

Return the positive integer k. If there is no such integer, return -1.

+ +

 

+

Example 1:

+ +
Input: nums = [-1,2,-3,3]
+Output: 3
+Explanation: 3 is the only valid k we can find in the array.
+
+ +

Example 2:

+ +
Input: nums = [-1,10,6,7,-7,1]
+Output: 7
+Explanation: Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.
+
+ +

Example 3:

+ +
Input: nums = [-10,8,6,7,-2,-3]
+Output: -1
+Explanation: There is no a single valid k, we return -1.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • -1000 <= nums[i] <= 1000
  • +
  • nums[i] != 0
  • +
+
\ No newline at end of file diff --git a/2444-count-subarrays-with-fixed-bounds/2444-count-subarrays-with-fixed-bounds.py b/problems/2444-count-subarrays-with-fixed-bounds/2444-count-subarrays-with-fixed-bounds.py similarity index 100% rename from 2444-count-subarrays-with-fixed-bounds/2444-count-subarrays-with-fixed-bounds.py rename to problems/2444-count-subarrays-with-fixed-bounds/2444-count-subarrays-with-fixed-bounds.py diff --git a/2444-count-subarrays-with-fixed-bounds/NOTES.md b/problems/2444-count-subarrays-with-fixed-bounds/NOTES.md similarity index 100% rename from 2444-count-subarrays-with-fixed-bounds/NOTES.md rename to problems/2444-count-subarrays-with-fixed-bounds/NOTES.md diff --git a/problems/2444-count-subarrays-with-fixed-bounds/README.md b/problems/2444-count-subarrays-with-fixed-bounds/README.md new file mode 100644 index 000000000..ab1ef8854 --- /dev/null +++ b/problems/2444-count-subarrays-with-fixed-bounds/README.md @@ -0,0 +1,36 @@ +

2444. Count Subarrays With Fixed Bounds

Hard


You are given an integer array nums and two integers minK and maxK.

+ +

A fixed-bound subarray of nums is a subarray that satisfies the following conditions:

+ +
    +
  • The minimum value in the subarray is equal to minK.
  • +
  • The maximum value in the subarray is equal to maxK.
  • +
+ +

Return the number of fixed-bound subarrays.

+ +

A subarray is a contiguous part of an array.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3,5,2,7,5], minK = 1, maxK = 5
+Output: 2
+Explanation: The fixed-bound subarrays are [1,3,5] and [1,3,5,2].
+
+ +

Example 2:

+ +
Input: nums = [1,1,1,1], minK = 1, maxK = 1
+Output: 10
+Explanation: Every subarray of nums is a fixed-bound subarray. There are 10 possible subarrays.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 105
  • +
  • 1 <= nums[i], minK, maxK <= 106
  • +
+
\ No newline at end of file diff --git a/2473-minimum-cost-to-buy-apples/2473-minimum-cost-to-buy-apples.py b/problems/2473-minimum-cost-to-buy-apples/2473-minimum-cost-to-buy-apples.py similarity index 100% rename from 2473-minimum-cost-to-buy-apples/2473-minimum-cost-to-buy-apples.py rename to problems/2473-minimum-cost-to-buy-apples/2473-minimum-cost-to-buy-apples.py diff --git a/problems/2473-minimum-cost-to-buy-apples/README.md b/problems/2473-minimum-cost-to-buy-apples/README.md new file mode 100644 index 000000000..f4d875f51 --- /dev/null +++ b/problems/2473-minimum-cost-to-buy-apples/README.md @@ -0,0 +1,42 @@ +

2473. Minimum Cost to Buy Apples

Medium


You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads, where roads[i] = [ai, bi, costi] indicates that there is a bidirectional road between cities ai and bi with a cost of traveling equal to costi.

+ +

You can buy apples in any city you want, but some cities have different costs to buy apples. You are given the 1-based array appleCost where appleCost[i] is the cost of buying one apple from city i.

+ +

You start at some city, traverse through various roads, and eventually buy exactly one apple from any city. After you buy that apple, you have to return back to the city you started at, but now the cost of all the roads will be multiplied by a given factor k.

+ +

Given the integer k, return a 1-based array answer of size n where answer[i] is the minimum total cost to buy an apple if you start at city i.

+ +

 

+

Example 1:

+ +
Input: n = 4, roads = [[1,2,4],[2,3,2],[2,4,5],[3,4,1],[1,3,4]], appleCost = [56,42,102,301], k = 2
+Output: [54,42,48,51]
+Explanation: The minimum cost for each starting city is the following:
+- Starting at city 1: You take the path 1 -> 2, buy an apple at city 2, and finally take the path 2 -> 1. The total cost is 4 + 42 + 4 * 2 = 54.
+- Starting at city 2: You directly buy an apple at city 2. The total cost is 42.
+- Starting at city 3: You take the path 3 -> 2, buy an apple at city 2, and finally take the path 2 -> 3. The total cost is 2 + 42 + 2 * 2 = 48.
+- Starting at city 4: You take the path 4 -> 3 -> 2 then you buy at city 2, and finally take the path 2 -> 3 -> 4. The total cost is 1 + 2 + 42 + 1 * 2 + 2 * 2 = 51.
+
+ +

Example 2:

+ +
Input: n = 3, roads = [[1,2,5],[2,3,1],[3,1,2]], appleCost = [2,3,1], k = 3
+Output: [2,3,1]
+Explanation: It is always optimal to buy the apple in the starting city.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 1000
  • +
  • 1 <= roads.length <= 1000
  • +
  • 1 <= ai, bi <= n
  • +
  • ai != bi
  • +
  • 1 <= costi <= 105
  • +
  • appleCost.length == n
  • +
  • 1 <= appleCost[i] <= 105
  • +
  • 1 <= k <= 100
  • +
  • There are no repeated edges.
  • +
+
\ No newline at end of file diff --git a/2482-difference-between-ones-and-zeros-in-row-and-column/2482-difference-between-ones-and-zeros-in-row-and-column.py b/problems/2482-difference-between-ones-and-zeros-in-row-and-column/2482-difference-between-ones-and-zeros-in-row-and-column.py similarity index 100% rename from 2482-difference-between-ones-and-zeros-in-row-and-column/2482-difference-between-ones-and-zeros-in-row-and-column.py rename to problems/2482-difference-between-ones-and-zeros-in-row-and-column/2482-difference-between-ones-and-zeros-in-row-and-column.py diff --git a/2482-difference-between-ones-and-zeros-in-row-and-column/NOTES.md b/problems/2482-difference-between-ones-and-zeros-in-row-and-column/NOTES.md similarity index 100% rename from 2482-difference-between-ones-and-zeros-in-row-and-column/NOTES.md rename to problems/2482-difference-between-ones-and-zeros-in-row-and-column/NOTES.md diff --git a/problems/2482-difference-between-ones-and-zeros-in-row-and-column/README.md b/problems/2482-difference-between-ones-and-zeros-in-row-and-column/README.md new file mode 100644 index 000000000..3353ff560 --- /dev/null +++ b/problems/2482-difference-between-ones-and-zeros-in-row-and-column/README.md @@ -0,0 +1,55 @@ +

2482. Difference Between Ones and Zeros in Row and Column

Medium


You are given a 0-indexed m x n binary matrix grid.

+ +

A 0-indexed m x n difference matrix diff is created with the following procedure:

+ +
    +
  • Let the number of ones in the ith row be onesRowi.
  • +
  • Let the number of ones in the jth column be onesColj.
  • +
  • Let the number of zeros in the ith row be zerosRowi.
  • +
  • Let the number of zeros in the jth column be zerosColj.
  • +
  • diff[i][j] = onesRowi + onesColj - zerosRowi - zerosColj
  • +
+ +

Return the difference matrix diff.

+ +

 

+

Example 1:

+ +
Input: grid = [[0,1,1],[1,0,1],[0,0,1]]
+Output: [[0,0,4],[0,0,4],[-2,-2,2]]
+Explanation:
+- diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 2 + 1 - 1 - 2 = 0 
+- diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 2 + 1 - 1 - 2 = 0 
+- diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 2 + 3 - 1 - 0 = 4 
+- diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 2 + 1 - 1 - 2 = 0 
+- diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 2 + 1 - 1 - 2 = 0 
+- diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 2 + 3 - 1 - 0 = 4 
+- diff[2][0] = onesRow2 + onesCol0 - zerosRow2 - zerosCol0 = 1 + 1 - 2 - 2 = -2
+- diff[2][1] = onesRow2 + onesCol1 - zerosRow2 - zerosCol1 = 1 + 1 - 2 - 2 = -2
+- diff[2][2] = onesRow2 + onesCol2 - zerosRow2 - zerosCol2 = 1 + 3 - 2 - 0 = 2
+
+ +

Example 2:

+ +
Input: grid = [[1,1,1],[1,1,1]]
+Output: [[5,5,5],[5,5,5]]
+Explanation:
+- diff[0][0] = onesRow0 + onesCol0 - zerosRow0 - zerosCol0 = 3 + 2 - 0 - 0 = 5
+- diff[0][1] = onesRow0 + onesCol1 - zerosRow0 - zerosCol1 = 3 + 2 - 0 - 0 = 5
+- diff[0][2] = onesRow0 + onesCol2 - zerosRow0 - zerosCol2 = 3 + 2 - 0 - 0 = 5
+- diff[1][0] = onesRow1 + onesCol0 - zerosRow1 - zerosCol0 = 3 + 2 - 0 - 0 = 5
+- diff[1][1] = onesRow1 + onesCol1 - zerosRow1 - zerosCol1 = 3 + 2 - 0 - 0 = 5
+- diff[1][2] = onesRow1 + onesCol2 - zerosRow1 - zerosCol2 = 3 + 2 - 0 - 0 = 5
+
+ +

 

+

Constraints:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 105
  • +
  • 1 <= m * n <= 105
  • +
  • grid[i][j] is either 0 or 1.
  • +
+
\ No newline at end of file diff --git a/2483-minimum-penalty-for-a-shop/2483-minimum-penalty-for-a-shop.py b/problems/2483-minimum-penalty-for-a-shop/2483-minimum-penalty-for-a-shop.py similarity index 100% rename from 2483-minimum-penalty-for-a-shop/2483-minimum-penalty-for-a-shop.py rename to problems/2483-minimum-penalty-for-a-shop/2483-minimum-penalty-for-a-shop.py diff --git a/2483-minimum-penalty-for-a-shop/NOTES.md b/problems/2483-minimum-penalty-for-a-shop/NOTES.md similarity index 100% rename from 2483-minimum-penalty-for-a-shop/NOTES.md rename to problems/2483-minimum-penalty-for-a-shop/NOTES.md diff --git a/problems/2483-minimum-penalty-for-a-shop/README.md b/problems/2483-minimum-penalty-for-a-shop/README.md new file mode 100644 index 000000000..eb9e9cc71 --- /dev/null +++ b/problems/2483-minimum-penalty-for-a-shop/README.md @@ -0,0 +1,53 @@ +

2483. Minimum Penalty for a Shop

Medium


You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y':

+ +
    +
  • if the ith character is 'Y', it means that customers come at the ith hour
  • +
  • whereas 'N' indicates that no customers come at the ith hour.
  • +
+ +

If the shop closes at the jth hour (0 <= j <= n), the penalty is calculated as follows:

+ +
    +
  • For every hour when the shop is open and no customers come, the penalty increases by 1.
  • +
  • For every hour when the shop is closed and customers come, the penalty increases by 1.
  • +
+ +

Return the earliest hour at which the shop must be closed to incur a minimum penalty.

+ +

Note that if a shop closes at the jth hour, it means the shop is closed at the hour j.

+ +

 

+

Example 1:

+ +
Input: customers = "YYNY"
+Output: 2
+Explanation: 
+- Closing the shop at the 0th hour incurs in 1+1+0+1 = 3 penalty.
+- Closing the shop at the 1st hour incurs in 0+1+0+1 = 2 penalty.
+- Closing the shop at the 2nd hour incurs in 0+0+0+1 = 1 penalty.
+- Closing the shop at the 3rd hour incurs in 0+0+1+1 = 2 penalty.
+- Closing the shop at the 4th hour incurs in 0+0+1+0 = 1 penalty.
+Closing the shop at 2nd or 4th hour gives a minimum penalty. Since 2 is earlier, the optimal closing time is 2.
+
+ +

Example 2:

+ +
Input: customers = "NNNNN"
+Output: 0
+Explanation: It is best to close the shop at the 0th hour as no customers arrive.
+ +

Example 3:

+ +
Input: customers = "YYYY"
+Output: 4
+Explanation: It is best to close the shop at the 4th hour as customers arrive at each hour.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= customers.length <= 105
  • +
  • customers consists only of characters 'Y' and 'N'.
  • +
+
\ No newline at end of file diff --git a/2485-find-the-pivot-integer/2485-find-the-pivot-integer.py b/problems/2485-find-the-pivot-integer/2485-find-the-pivot-integer.py similarity index 100% rename from 2485-find-the-pivot-integer/2485-find-the-pivot-integer.py rename to problems/2485-find-the-pivot-integer/2485-find-the-pivot-integer.py diff --git a/2485-find-the-pivot-integer/NOTES.md b/problems/2485-find-the-pivot-integer/NOTES.md similarity index 100% rename from 2485-find-the-pivot-integer/NOTES.md rename to problems/2485-find-the-pivot-integer/NOTES.md diff --git a/problems/2485-find-the-pivot-integer/README.md b/problems/2485-find-the-pivot-integer/README.md new file mode 100644 index 000000000..12c9294c5 --- /dev/null +++ b/problems/2485-find-the-pivot-integer/README.md @@ -0,0 +1,37 @@ +

2485. Find the Pivot Integer

Easy


Given a positive integer n, find the pivot integer x such that:

+ +
    +
  • The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively.
  • +
+ +

Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input.

+ +

 

+

Example 1:

+ +
Input: n = 8
+Output: 6
+Explanation: 6 is the pivot integer since: 1 + 2 + 3 + 4 + 5 + 6 = 6 + 7 + 8 = 21.
+
+ +

Example 2:

+ +
Input: n = 1
+Output: 1
+Explanation: 1 is the pivot integer since: 1 = 1.
+
+ +

Example 3:

+ +
Input: n = 4
+Output: -1
+Explanation: It can be proved that no such integer exist.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 1000
  • +
+
\ No newline at end of file diff --git a/2486-append-characters-to-string-to-make-subsequence/2486-append-characters-to-string-to-make-subsequence.py b/problems/2486-append-characters-to-string-to-make-subsequence/2486-append-characters-to-string-to-make-subsequence.py similarity index 100% rename from 2486-append-characters-to-string-to-make-subsequence/2486-append-characters-to-string-to-make-subsequence.py rename to problems/2486-append-characters-to-string-to-make-subsequence/2486-append-characters-to-string-to-make-subsequence.py diff --git a/problems/2486-append-characters-to-string-to-make-subsequence/README.md b/problems/2486-append-characters-to-string-to-make-subsequence/README.md new file mode 100644 index 000000000..3029053ca --- /dev/null +++ b/problems/2486-append-characters-to-string-to-make-subsequence/README.md @@ -0,0 +1,40 @@ +

2486. Append Characters to String to Make Subsequence

Medium


You are given two strings s and t consisting of only lowercase English letters.

+ +

Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.

+ +

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

+ +

 

+

Example 1:

+ +
Input: s = "coaching", t = "coding"
+Output: 4
+Explanation: Append the characters "ding" to the end of s so that s = "coachingding".
+Now, t is a subsequence of s ("coachingding").
+It can be shown that appending any 3 characters to the end of s will never make t a subsequence.
+
+ +

Example 2:

+ +
Input: s = "abcde", t = "a"
+Output: 0
+Explanation: t is already a subsequence of s ("abcde").
+
+ +

Example 3:

+ +
Input: s = "z", t = "abcde"
+Output: 5
+Explanation: Append the characters "abcde" to the end of s so that s = "zabcde".
+Now, t is a subsequence of s ("zabcde").
+It can be shown that appending any 4 characters to the end of s will never make t a subsequence.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length, t.length <= 105
  • +
  • s and t consist only of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2487-remove-nodes-from-linked-list/2487-remove-nodes-from-linked-list.py b/problems/2487-remove-nodes-from-linked-list/2487-remove-nodes-from-linked-list.py similarity index 100% rename from 2487-remove-nodes-from-linked-list/2487-remove-nodes-from-linked-list.py rename to problems/2487-remove-nodes-from-linked-list/2487-remove-nodes-from-linked-list.py diff --git a/2487-remove-nodes-from-linked-list/NOTES.md b/problems/2487-remove-nodes-from-linked-list/NOTES.md similarity index 100% rename from 2487-remove-nodes-from-linked-list/NOTES.md rename to problems/2487-remove-nodes-from-linked-list/NOTES.md diff --git a/2505-bitwise-or-of-all-subsequence-sums/2505-bitwise-or-of-all-subsequence-sums.py b/problems/2505-bitwise-or-of-all-subsequence-sums/2505-bitwise-or-of-all-subsequence-sums.py similarity index 100% rename from 2505-bitwise-or-of-all-subsequence-sums/2505-bitwise-or-of-all-subsequence-sums.py rename to problems/2505-bitwise-or-of-all-subsequence-sums/2505-bitwise-or-of-all-subsequence-sums.py diff --git a/2505-bitwise-or-of-all-subsequence-sums/NOTES.md b/problems/2505-bitwise-or-of-all-subsequence-sums/NOTES.md similarity index 100% rename from 2505-bitwise-or-of-all-subsequence-sums/NOTES.md rename to problems/2505-bitwise-or-of-all-subsequence-sums/NOTES.md diff --git a/problems/2505-bitwise-or-of-all-subsequence-sums/README.md b/problems/2505-bitwise-or-of-all-subsequence-sums/README.md new file mode 100644 index 000000000..715372ed9 --- /dev/null +++ b/problems/2505-bitwise-or-of-all-subsequence-sums/README.md @@ -0,0 +1,28 @@ +

2505. Bitwise OR of All Subsequence Sums

Medium


Given an integer array nums, return the value of the bitwise OR of the sum of all possible subsequences in the array.

+ +

A subsequence is a sequence that can be derived from another sequence by removing zero or more elements without changing the order of the remaining elements.

+ +

 

+

Example 1:

+ +
Input: nums = [2,1,0,3]
+Output: 7
+Explanation: All possible subsequence sums that we can have are: 0, 1, 2, 3, 4, 5, 6.
+And we have 0 OR 1 OR 2 OR 3 OR 4 OR 5 OR 6 = 7, so we return 7.
+
+ +

Example 2:

+ +
Input: nums = [0,0,0]
+Output: 0
+Explanation: 0 is the only possible subsequence sum we can have, so we return 0.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/2540-minimum-common-value/2540-minimum-common-value.py b/problems/2540-minimum-common-value/2540-minimum-common-value.py similarity index 100% rename from 2540-minimum-common-value/2540-minimum-common-value.py rename to problems/2540-minimum-common-value/2540-minimum-common-value.py diff --git a/2540-minimum-common-value/NOTES.md b/problems/2540-minimum-common-value/NOTES.md similarity index 100% rename from 2540-minimum-common-value/NOTES.md rename to problems/2540-minimum-common-value/NOTES.md diff --git a/2582-pass-the-pillow/2582-pass-the-pillow.py b/problems/2582-pass-the-pillow/2582-pass-the-pillow.py similarity index 100% rename from 2582-pass-the-pillow/2582-pass-the-pillow.py rename to problems/2582-pass-the-pillow/2582-pass-the-pillow.py diff --git a/2582-pass-the-pillow/NOTES.md b/problems/2582-pass-the-pillow/NOTES.md similarity index 100% rename from 2582-pass-the-pillow/NOTES.md rename to problems/2582-pass-the-pillow/NOTES.md diff --git a/problems/2582-pass-the-pillow/README.md b/problems/2582-pass-the-pillow/README.md new file mode 100644 index 000000000..fcea94162 --- /dev/null +++ b/problems/2582-pass-the-pillow/README.md @@ -0,0 +1,32 @@ +

2582. Pass the Pillow

Easy


There are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction.

+ +
    +
  • For example, once the pillow reaches the nth person they pass it to the n - 1th person, then to the n - 2th person and so on.
  • +
+ +

Given the two positive integers n and time, return the index of the person holding the pillow after time seconds.

+

 

+

Example 1:

+ +
Input: n = 4, time = 5
+Output: 2
+Explanation: People pass the pillow in the following way: 1 -> 2 -> 3 -> 4 -> 3 -> 2.
+After five seconds, the 2nd person is holding the pillow.
+
+ +

Example 2:

+ +
Input: n = 3, time = 2
+Output: 3
+Explanation: People pass the pillow in the following way: 1 -> 2 -> 3.
+After two seconds, the 3rd person is holding the pillow.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n <= 1000
  • +
  • 1 <= time <= 1000
  • +
+
\ No newline at end of file diff --git a/2597-the-number-of-beautiful-subsets/2597-the-number-of-beautiful-subsets.py b/problems/2597-the-number-of-beautiful-subsets/2597-the-number-of-beautiful-subsets.py similarity index 100% rename from 2597-the-number-of-beautiful-subsets/2597-the-number-of-beautiful-subsets.py rename to problems/2597-the-number-of-beautiful-subsets/2597-the-number-of-beautiful-subsets.py diff --git a/2597-the-number-of-beautiful-subsets/NOTES.md b/problems/2597-the-number-of-beautiful-subsets/NOTES.md similarity index 100% rename from 2597-the-number-of-beautiful-subsets/NOTES.md rename to problems/2597-the-number-of-beautiful-subsets/NOTES.md diff --git a/problems/2597-the-number-of-beautiful-subsets/README.md b/problems/2597-the-number-of-beautiful-subsets/README.md new file mode 100644 index 000000000..1c16e7bef --- /dev/null +++ b/problems/2597-the-number-of-beautiful-subsets/README.md @@ -0,0 +1,33 @@ +

2597. The Number of Beautiful Subsets

Medium


You are given an array nums of positive integers and a positive integer k.

+ +

A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.

+ +

Return the number of non-empty beautiful subsets of the array nums.

+ +

A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.

+ +

 

+

Example 1:

+ +
Input: nums = [2,4,6], k = 2
+Output: 4
+Explanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].
+It can be proved that there are only 4 beautiful subsets in the array [2,4,6].
+
+ +

Example 2:

+ +
Input: nums = [1], k = 1
+Output: 1
+Explanation: The beautiful subset of the array nums is [1].
+It can be proved that there is only 1 beautiful subset in the array [1].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 20
  • +
  • 1 <= nums[i], k <= 1000
  • +
+
\ No newline at end of file diff --git a/2610-convert-an-array-into-a-2d-array-with-conditions/2610-convert-an-array-into-a-2d-array-with-conditions.py b/problems/2610-convert-an-array-into-a-2d-array-with-conditions/2610-convert-an-array-into-a-2d-array-with-conditions.py similarity index 100% rename from 2610-convert-an-array-into-a-2d-array-with-conditions/2610-convert-an-array-into-a-2d-array-with-conditions.py rename to problems/2610-convert-an-array-into-a-2d-array-with-conditions/2610-convert-an-array-into-a-2d-array-with-conditions.py diff --git a/problems/2610-convert-an-array-into-a-2d-array-with-conditions/README.md b/problems/2610-convert-an-array-into-a-2d-array-with-conditions/README.md new file mode 100644 index 000000000..58b3233b2 --- /dev/null +++ b/problems/2610-convert-an-array-into-a-2d-array-with-conditions/README.md @@ -0,0 +1,39 @@ +

2610. Convert an Array Into a 2D Array With Conditions

Medium


You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:

+ +
    +
  • The 2D array should contain only the elements of the array nums.
  • +
  • Each row in the 2D array contains distinct integers.
  • +
  • The number of rows in the 2D array should be minimal.
  • +
+ +

Return the resulting array. If there are multiple answers, return any of them.

+ +

Note that the 2D array can have a different number of elements on each row.

+ +

 

+

Example 1:

+ +
Input: nums = [1,3,4,1,2,3,1]
+Output: [[1,3,4,2],[1,3],[1]]
+Explanation: We can create a 2D array that contains the following rows:
+- 1,3,4,2
+- 1,3
+- 1
+All elements of nums were used, and each row of the 2D array contains distinct integers, so it is a valid answer.
+It can be shown that we cannot have less than 3 rows in a valid array.
+ +

Example 2:

+ +
Input: nums = [1,2,3,4]
+Output: [[4,3,2,1]]
+Explanation: All elements of the array are distinct, so we can keep all of them in the first row of the 2D array.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 200
  • +
  • 1 <= nums[i] <= nums.length
  • +
+
\ No newline at end of file diff --git a/2616-minimize-the-maximum-difference-of-pairs/2616-minimize-the-maximum-difference-of-pairs.py b/problems/2616-minimize-the-maximum-difference-of-pairs/2616-minimize-the-maximum-difference-of-pairs.py similarity index 100% rename from 2616-minimize-the-maximum-difference-of-pairs/2616-minimize-the-maximum-difference-of-pairs.py rename to problems/2616-minimize-the-maximum-difference-of-pairs/2616-minimize-the-maximum-difference-of-pairs.py diff --git a/2616-minimize-the-maximum-difference-of-pairs/NOTES.md b/problems/2616-minimize-the-maximum-difference-of-pairs/NOTES.md similarity index 100% rename from 2616-minimize-the-maximum-difference-of-pairs/NOTES.md rename to problems/2616-minimize-the-maximum-difference-of-pairs/NOTES.md diff --git a/problems/2616-minimize-the-maximum-difference-of-pairs/README.md b/problems/2616-minimize-the-maximum-difference-of-pairs/README.md new file mode 100644 index 000000000..3b3b09438 --- /dev/null +++ b/problems/2616-minimize-the-maximum-difference-of-pairs/README.md @@ -0,0 +1,31 @@ +

2616. Minimize the Maximum Difference of Pairs

Medium


You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.

+ +

Note that for a pair of elements at the index i and j, the difference of this pair is |nums[i] - nums[j]|, where |x| represents the absolute value of x.

+ +

Return the minimum maximum difference among all p pairs. We define the maximum of an empty set to be zero.

+ +

 

+

Example 1:

+ +
Input: nums = [10,1,2,7,1,3], p = 2
+Output: 1
+Explanation: The first pair is formed from the indices 1 and 4, and the second pair is formed from the indices 2 and 5. 
+The maximum difference is max(|nums[1] - nums[4]|, |nums[2] - nums[5]|) = max(0, 1) = 1. Therefore, we return 1.
+
+ +

Example 2:

+ +
Input: nums = [4,2,1,2], p = 1
+Output: 0
+Explanation: Let the indices 1 and 3 form a pair. The difference of that pair is |2 - 2| = 0, which is the minimum we can attain.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 0 <= nums[i] <= 109
  • +
  • 0 <= p <= (nums.length)/2
  • +
+
\ No newline at end of file diff --git a/2618-check-if-object-instance-of-class/2618-check-if-object-instance-of-class.ts b/problems/2618-check-if-object-instance-of-class/2618-check-if-object-instance-of-class.ts similarity index 100% rename from 2618-check-if-object-instance-of-class/2618-check-if-object-instance-of-class.ts rename to problems/2618-check-if-object-instance-of-class/2618-check-if-object-instance-of-class.ts diff --git a/2618-check-if-object-instance-of-class/NOTES.md b/problems/2618-check-if-object-instance-of-class/NOTES.md similarity index 100% rename from 2618-check-if-object-instance-of-class/NOTES.md rename to problems/2618-check-if-object-instance-of-class/NOTES.md diff --git a/problems/2618-check-if-object-instance-of-class/README.md b/problems/2618-check-if-object-instance-of-class/README.md new file mode 100644 index 000000000..8ce81bd42 --- /dev/null +++ b/problems/2618-check-if-object-instance-of-class/README.md @@ -0,0 +1,37 @@ +

2618. Check if Object Instance of Class

Medium


Write a function that checks if a given value is an instance of a given class or superclass. For this problem, an object is considered an instance of a given class if that object has access to that class's methods.

+ +

There are no constraints on the data types that can be passed to the function. For example, the value or the class could be undefined.

+ +

 

+

Example 1:

+ +
Input: func = () => checkIfInstanceOf(new Date(), Date)
+Output: true
+Explanation: The object returned by the Date constructor is, by definition, an instance of Date.
+
+ +

Example 2:

+ +
Input: func = () => { class Animal {}; class Dog extends Animal {}; return checkIfInstanceOf(new Dog(), Animal); }
+Output: true
+Explanation:
+class Animal {};
+class Dog extends Animal {};
+checkIfInstanceOf(new Dog(), Animal); // true
+
+Dog is a subclass of Animal. Therefore, a Dog object is an instance of both Dog and Animal.
+ +

Example 3:

+ +
Input: func = () => checkIfInstanceOf(Date, Date)
+Output: false
+Explanation: A date constructor cannot logically be an instance of itself.
+
+ +

Example 4:

+ +
Input: func = () => checkIfInstanceOf(5, Number)
+Output: true
+Explanation: 5 is a Number. Note that the "instanceof" keyword would return false. However, it is still considered an instance of Number because it accesses the Number methods. For example "toFixed()".
+
+
\ No newline at end of file diff --git a/2619-array-prototype-last/2619-array-prototype-last.js b/problems/2619-array-prototype-last/2619-array-prototype-last.js similarity index 100% rename from 2619-array-prototype-last/2619-array-prototype-last.js rename to problems/2619-array-prototype-last/2619-array-prototype-last.js diff --git a/2619-array-prototype-last/2619-array-prototype-last.ts b/problems/2619-array-prototype-last/2619-array-prototype-last.ts similarity index 100% rename from 2619-array-prototype-last/2619-array-prototype-last.ts rename to problems/2619-array-prototype-last/2619-array-prototype-last.ts diff --git a/2619-array-prototype-last/NOTES.md b/problems/2619-array-prototype-last/NOTES.md similarity index 100% rename from 2619-array-prototype-last/NOTES.md rename to problems/2619-array-prototype-last/NOTES.md diff --git a/problems/2619-array-prototype-last/README.md b/problems/2619-array-prototype-last/README.md new file mode 100644 index 000000000..8030ed590 --- /dev/null +++ b/problems/2619-array-prototype-last/README.md @@ -0,0 +1,26 @@ +

2619. Array Prototype Last

Easy


Write code that enhances all arrays such that you can call the array.last() method on any array and it will return the last element. If there are no elements in the array, it should return -1.

+ +

You may assume the array is the output of JSON.parse.

+ +

 

+

Example 1:

+ +
Input: nums = [null, {}, 3]
+Output: 3
+Explanation: Calling nums.last() should return the last element: 3.
+
+ +

Example 2:

+ +
Input: nums = []
+Output: -1
+Explanation: Because there are no elements, return -1.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= arr.length <= 1000
  • +
+
\ No newline at end of file diff --git a/2620-counter/2620-counter.js b/problems/2620-counter/2620-counter.js similarity index 100% rename from 2620-counter/2620-counter.js rename to problems/2620-counter/2620-counter.js diff --git a/2620-counter/2620-counter.ts b/problems/2620-counter/2620-counter.ts similarity index 100% rename from 2620-counter/2620-counter.ts rename to problems/2620-counter/2620-counter.ts diff --git a/2620-counter/NOTES.md b/problems/2620-counter/NOTES.md similarity index 100% rename from 2620-counter/NOTES.md rename to problems/2620-counter/NOTES.md diff --git a/problems/2620-counter/README.md b/problems/2620-counter/README.md new file mode 100644 index 000000000..26ee6dd6a --- /dev/null +++ b/problems/2620-counter/README.md @@ -0,0 +1,32 @@ +

2620. Counter

Easy


Given an integer n, return a counter function. This counter function initially returns n and then returns 1 more than the previous value every subsequent time it is called (n, n + 1, n + 2, etc).

+ +

 

+

Example 1:

+ +
Input: 
+n = 10 
+["call","call","call"]
+Output: [10,11,12]
+Explanation: 
+counter() = 10 // The first time counter() is called, it returns n.
+counter() = 11 // Returns 1 more than the previous time.
+counter() = 12 // Returns 1 more than the previous time.
+
+ +

Example 2:

+ +
Input: 
+n = -2
+["call","call","call","call","call"]
+Output: [-2,-1,0,1,2]
+Explanation: counter() initially returns -2. Then increases after each sebsequent call.
+
+ +

 

+

Constraints:

+ +
    +
  • -1000 <= n <= 1000
  • +
  • At most 1000 calls to counter() will be made
  • +
+
\ No newline at end of file diff --git a/2621-sleep/2621-sleep.js b/problems/2621-sleep/2621-sleep.js similarity index 100% rename from 2621-sleep/2621-sleep.js rename to problems/2621-sleep/2621-sleep.js diff --git a/2621-sleep/2621-sleep.ts b/problems/2621-sleep/2621-sleep.ts similarity index 100% rename from 2621-sleep/2621-sleep.ts rename to problems/2621-sleep/2621-sleep.ts diff --git a/2621-sleep/NOTES.md b/problems/2621-sleep/NOTES.md similarity index 100% rename from 2621-sleep/NOTES.md rename to problems/2621-sleep/NOTES.md diff --git a/problems/2621-sleep/README.md b/problems/2621-sleep/README.md new file mode 100644 index 000000000..512b3620d --- /dev/null +++ b/problems/2621-sleep/README.md @@ -0,0 +1,28 @@ +

2621. Sleep

Easy


Given a positive integer millis, write an asynchronous function that sleeps for millis milliseconds. It can resolve any value.

+ +

 

+

Example 1:

+ +
Input: millis = 100
+Output: 100
+Explanation: It should return a promise that resolves after 100ms.
+let t = Date.now();
+sleep(100).then(() => {
+  console.log(Date.now() - t); // 100
+});
+
+ +

Example 2:

+ +
Input: millis = 200
+Output: 200
+Explanation: It should return a promise that resolves after 200ms.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= millis <= 1000
  • +
+
\ No newline at end of file diff --git a/2622-cache-with-time-limit/2622-cache-with-time-limit.js b/problems/2622-cache-with-time-limit/2622-cache-with-time-limit.js similarity index 100% rename from 2622-cache-with-time-limit/2622-cache-with-time-limit.js rename to problems/2622-cache-with-time-limit/2622-cache-with-time-limit.js diff --git a/2622-cache-with-time-limit/2622-cache-with-time-limit.ts b/problems/2622-cache-with-time-limit/2622-cache-with-time-limit.ts similarity index 100% rename from 2622-cache-with-time-limit/2622-cache-with-time-limit.ts rename to problems/2622-cache-with-time-limit/2622-cache-with-time-limit.ts diff --git a/2622-cache-with-time-limit/NOTES.md b/problems/2622-cache-with-time-limit/NOTES.md similarity index 100% rename from 2622-cache-with-time-limit/NOTES.md rename to problems/2622-cache-with-time-limit/NOTES.md diff --git a/problems/2622-cache-with-time-limit/README.md b/problems/2622-cache-with-time-limit/README.md new file mode 100644 index 000000000..5d3054a15 --- /dev/null +++ b/problems/2622-cache-with-time-limit/README.md @@ -0,0 +1,55 @@ +

2622. Cache With Time Limit

Medium


Write a class that allows getting and setting key-value pairs, however a time until expiration is associated with each key.

+ +

The class has three public methods:

+ +

set(key, value, duration): accepts an integer key, an integer value, and a duration in milliseconds. Once the duration has elapsed, the key should be inaccessible. The method should return true if the same un-expired key already exists and false otherwise. Both the value and duration should be overwritten if the key already exists.

+ +

get(key): if an un-expired key exists, it should return the associated value. Otherwise it should return -1.

+ +

count(): returns the count of un-expired keys.

+ +

 

+

Example 1:

+ +
Input: 
+["TimeLimitedCache", "set", "get", "count", "get"]
+[[], [1, 42, 100], [1], [], [1]]
+[0, 0, 50, 50, 150]
+Output: [null, false, 42, 1, -1]
+Explanation:
+At t=0, the cache is constructed.
+At t=0, a key-value pair (1: 42) is added with a time limit of 100ms. The value doesn't exist so false is returned.
+At t=50, key=1 is requested and the value of 42 is returned.
+At t=50, count() is called and there is one active key in the cache.
+At t=100, key=1 expires.
+At t=150, get(1) is called but -1 is returned because the cache is empty.
+
+ +

Example 2:

+ +
Input: 
+["TimeLimitedCache", "set", "set", "get", "get", "get", "count"]
+[[], [1, 42, 50], [1, 50, 100], [1], [1], [1], []]
+[0, 0, 40, 50, 120, 200, 250]
+Output: [null, false, true, 50, 50, -1, 0]
+Explanation:
+At t=0, the cache is constructed.
+At t=0, a key-value pair (1: 42) is added with a time limit of 50ms. The value doesn't exist so false is returned.
+At t=40, a key-value pair (1: 50) is added with a time limit of 100ms. A non-expired value already existed so true is returned and the old value was overwritten.
+At t=50, get(1) is called which returned 50.
+At t=120, get(1) is called which returned 50.
+At t=140, key=1 expires.
+At t=200, get(1) is called but the cache is empty so -1 is returned.
+At t=250, count() returns 0 because the cache is empty.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= key <= 109
  • +
  • 0 <= value <= 109
  • +
  • 0 <= duration <= 1000
  • +
  • total method calls will not exceed 100
  • +
+
\ No newline at end of file diff --git a/2623-memoize/2623-memoize.js b/problems/2623-memoize/2623-memoize.js similarity index 100% rename from 2623-memoize/2623-memoize.js rename to problems/2623-memoize/2623-memoize.js diff --git a/2623-memoize/2623-memoize.ts b/problems/2623-memoize/2623-memoize.ts similarity index 100% rename from 2623-memoize/2623-memoize.ts rename to problems/2623-memoize/2623-memoize.ts diff --git a/2623-memoize/NOTES.md b/problems/2623-memoize/NOTES.md similarity index 100% rename from 2623-memoize/NOTES.md rename to problems/2623-memoize/NOTES.md diff --git a/problems/2623-memoize/README.md b/problems/2623-memoize/README.md new file mode 100644 index 000000000..2f1ce95f5 --- /dev/null +++ b/problems/2623-memoize/README.md @@ -0,0 +1,78 @@ +

2623. Memoize

Medium


Given a function fn, return a memoized version of that function.

+ +

memoized function is a function that will never be called twice with the same inputs. Instead it will return a cached value.

+ +

You can assume there are possible input functions: sum, fiband factorial.

+ +
    +
  • sum accepts two integers a and b and returns a + b.
  • +
  • fib accepts a single integer n and returns 1 if n <= 1 or fib(n - 1) + fib(n - 2) otherwise.
  • +
  • factorial accepts a single integer n and returns 1 if n <= 1 or factorial(n - 1) * n otherwise.
  • +
+ +

 

+

Example 1:

+ +
Input
+"sum"
+["call","call","getCallCount","call","getCallCount"]
+[[2,2],[2,2],[],[1,2],[]]
+Output
+[4,4,1,3,2]
+
+Explanation
+const sum = (a, b) => a + b;
+const memoizedSum = memoize(sum);
+memoizedSum(2, 2); // Returns 4. sum() was called as (2, 2) was not seen before.
+memoizedSum(2, 2); // Returns 4. However sum() was not called because the same inputs were seen before.
+// Total call count: 1
+memoizedSum(1, 2); // Returns 3. sum() was called as (1, 2) was not seen before.
+// Total call count: 2
+
+ +

Example 2:

+ +
Input
+"factorial"
+["call","call","call","getCallCount","call","getCallCount"]
+[[2],[3],[2],[],[3],[]]
+Output
+[2,6,2,2,6,2]
+
+Explanation
+const factorial = (n) => (n <= 1) ? 1 : (n * factorial(n - 1));
+const memoFactorial = memoize(factorial);
+memoFactorial(2); // Returns 2.
+memoFactorial(3); // Returns 6.
+memoFactorial(2); // Returns 2. However factorial was not called because 2 was seen before.
+// Total call count: 2
+memoFactorial(3); // Returns 6. However factorial was not called because 3 was seen before.
+// Total call count: 2
+
+ +

Example 3:

+ +
Input
+"fib"
+["call","getCallCount"]
+[[5],[]]
+Output
+[8,1]
+
+Explanation
+fib(5) = 8
+// Total call count: 1
+
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= a, b <= 105
  • +
  • 1 <= n <= 10
  • +
  • at most 105 function calls
  • +
  • at most 105 attempts to access callCount
  • +
  • input function is sum, fib, or factorial
  • +
+
\ No newline at end of file diff --git a/2624-snail-traversal/2624-snail-traversal.ts b/problems/2624-snail-traversal/2624-snail-traversal.ts similarity index 100% rename from 2624-snail-traversal/2624-snail-traversal.ts rename to problems/2624-snail-traversal/2624-snail-traversal.ts diff --git a/2624-snail-traversal/NOTES.md b/problems/2624-snail-traversal/NOTES.md similarity index 100% rename from 2624-snail-traversal/NOTES.md rename to problems/2624-snail-traversal/NOTES.md diff --git a/problems/2624-snail-traversal/README.md b/problems/2624-snail-traversal/README.md new file mode 100644 index 000000000..7844e53a8 --- /dev/null +++ b/problems/2624-snail-traversal/README.md @@ -0,0 +1,56 @@ +

2624. Snail Traversal

Medium


Write code that enhances all arrays such that you can call the snail(rowsCount, colsCount) method that transforms the 1D array into a 2D array organised in the pattern known as snail traversal order. Invalid input values should output an empty array. If rowsCount * colsCount !== nums.length, the input is considered invalid.

+ +

Snail traversal order starts at the top left cell with the first value of the current array. It then moves through the entire first column from top to bottom, followed by moving to the next column on the right and traversing it from bottom to top. This pattern continues, alternating the direction of traversal with each column, until the entire current array is covered. For example, when given the input array [19, 10, 3, 7, 9, 8, 5, 2, 1, 17, 16, 14, 12, 18, 6, 13, 11, 20, 4, 15] with rowsCount = 5 and colsCount = 4, the desired output matrix is shown below. Note that iterating the matrix following the arrows corresponds to the order of numbers in the original array.

+ +

 

+ +

Traversal Diagram

+ +

 

+

Example 1:

+ +
Input: 
+nums = [19, 10, 3, 7, 9, 8, 5, 2, 1, 17, 16, 14, 12, 18, 6, 13, 11, 20, 4, 15]
+rowsCount = 5
+colsCount = 4
+Output: 
+[
+ [19,17,16,15],
+ [10,1,14,4],
+ [3,2,12,20],
+ [7,5,18,11],
+ [9,8,6,13]
+]
+
+ +

Example 2:

+ +
Input: 
+nums = [1,2,3,4]
+rowsCount = 1
+colsCount = 4
+Output: [[1, 2, 3, 4]]
+
+ +

Example 3:

+ +
Input: 
+nums = [1,3]
+rowsCount = 2
+colsCount = 2
+Output: []
+Explanation: 2 multiplied by 2 is 4, and the original array [1,3] has a length of 2; therefore, the input is invalid.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 250
  • +
  • 1 <= nums[i] <= 1000
  • +
  • 1 <= rowsCount <= 250
  • +
  • 1 <= colsCount <= 250
  • +
+ +

 

+
\ No newline at end of file diff --git a/2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.js b/problems/2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.js similarity index 100% rename from 2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.js rename to problems/2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.js diff --git a/2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.ts b/problems/2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.ts similarity index 100% rename from 2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.ts rename to problems/2625-flatten-deeply-nested-array/2625-flatten-deeply-nested-array.ts diff --git a/2625-flatten-deeply-nested-array/NOTES.md b/problems/2625-flatten-deeply-nested-array/NOTES.md similarity index 100% rename from 2625-flatten-deeply-nested-array/NOTES.md rename to problems/2625-flatten-deeply-nested-array/NOTES.md diff --git a/problems/2625-flatten-deeply-nested-array/README.md b/problems/2625-flatten-deeply-nested-array/README.md new file mode 100644 index 000000000..ca03a77fb --- /dev/null +++ b/problems/2625-flatten-deeply-nested-array/README.md @@ -0,0 +1,53 @@ +

2625. Flatten Deeply Nested Array

Medium


Given a multi-dimensional array arr and a depth n, return a flattened version of that array.

+ +

A multi-dimensional array is a recursive data structure that contains integers or other multi-dimensional arrays.

+ +

flattened array is a version of that array with some or all of the sub-arrays removed and replaced with the actual elements in that sub-array. This flattening operation should only be done if the current depth of nesting is less than n. The depth of the elements in the first array are considered to be 0.

+ +

Please solve it without the built-in Array.flat method.

+ +

 

+

Example 1:

+ +
Input
+arr = [1, 2, 3, [4, 5, 6], [7, 8, [9, 10, 11], 12], [13, 14, 15]]
+n = 0
+Output
+[1, 2, 3, [4, 5, 6], [7, 8, [9, 10, 11], 12], [13, 14, 15]]
+
+Explanation
+Passing a depth of n=0 will always result in the original array. This is because the smallest possible depth of a subarray (0) is not less than n=0. Thus, no subarray should be flattened. 
+ +

Example 2:

+ +
Input
+arr = [1, 2, 3, [4, 5, 6], [7, 8, [9, 10, 11], 12], [13, 14, 15]]
+n = 1
+Output
+[1, 2, 3, 4, 5, 6, 7, 8, [9, 10, 11], 12, 13, 14, 15]
+
+Explanation
+The subarrays starting with 4, 7, and 13 are all flattened. This is because their depth of 0 is less than 1. However [9, 10, 11] remains unflattened because its depth is 1.
+ +

Example 3:

+ +
Input
+arr = [[1, 2, 3], [4, 5, 6], [7, 8, [9, 10, 11], 12], [13, 14, 15]]
+n = 2
+Output
+[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
+
+Explanation
+The maximum depth of any subarray is 1. Thus, all of them are flattened.
+ +

 

+

Constraints:

+ +
    +
  • 0 <= count of numbers in arr <= 105
  • +
  • 0 <= count of subarrays in arr <= 105
  • +
  • maxDepth <= 1000
  • +
  • -1000 <= each number <= 1000
  • +
  • 0 <= n <= 1000
  • +
+
\ No newline at end of file diff --git a/2626-array-reduce-transformation/2626-array-reduce-transformation.js b/problems/2626-array-reduce-transformation/2626-array-reduce-transformation.js similarity index 100% rename from 2626-array-reduce-transformation/2626-array-reduce-transformation.js rename to problems/2626-array-reduce-transformation/2626-array-reduce-transformation.js diff --git a/2626-array-reduce-transformation/2626-array-reduce-transformation.ts b/problems/2626-array-reduce-transformation/2626-array-reduce-transformation.ts similarity index 100% rename from 2626-array-reduce-transformation/2626-array-reduce-transformation.ts rename to problems/2626-array-reduce-transformation/2626-array-reduce-transformation.ts diff --git a/2626-array-reduce-transformation/NOTES.md b/problems/2626-array-reduce-transformation/NOTES.md similarity index 100% rename from 2626-array-reduce-transformation/NOTES.md rename to problems/2626-array-reduce-transformation/NOTES.md diff --git a/problems/2626-array-reduce-transformation/README.md b/problems/2626-array-reduce-transformation/README.md new file mode 100644 index 000000000..098b2840d --- /dev/null +++ b/problems/2626-array-reduce-transformation/README.md @@ -0,0 +1,60 @@ +

2626. Array Reduce Transformation

Easy


Given an integer array nums, a reducer function fn, and an initial value init, return a reduced array.

+ +

reduced array is created by applying the following operation: val = fn(init, nums[0]), val = fn(val, nums[1])val = fn(val, nums[2])... until every element in the array has been processed. The final value of val is returned.

+ +

If the length of the array is 0, it should return init.

+ +

Please solve it without using the built-in Array.reduce method.

+ +

 

+

Example 1:

+ +
Input: 
+nums = [1,2,3,4]
+fn = function sum(accum, curr) { return accum + curr; }
+init = 0
+Output: 10
+Explanation:
+initially, the value is init=0.
+(0) + nums[0] = 1
+(1) + nums[1] = 3
+(3) + nums[2] = 6
+(6) + nums[3] = 10
+The final answer is 10.
+
+ +

Example 2:

+ +
Input: 
+nums = [1,2,3,4]
+fn = function sum(accum, curr) { return accum + curr * curr; }
+init = 100
+Output: 130
+Explanation:
+initially, the value is init=100.
+(100) + nums[0]^2 = 101
+(101) + nums[1]^2 = 105
+(105) + nums[2]^2 = 114
+(114) + nums[3]^2 = 130
+The final answer is 130.
+
+ +

Example 3:

+ +
Input: 
+nums = []
+fn = function sum(accum, curr) { return 0; }
+init = 25
+Output: 25
+Explanation: For empty arrays, the answer is always init.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 1000
  • +
  • 0 <= nums[i] <= 1000
  • +
  • 0 <= init <= 1000
  • +
+
\ No newline at end of file diff --git a/2627-debounce/2627-debounce.js b/problems/2627-debounce/2627-debounce.js similarity index 100% rename from 2627-debounce/2627-debounce.js rename to problems/2627-debounce/2627-debounce.js diff --git a/2627-debounce/2627-debounce.ts b/problems/2627-debounce/2627-debounce.ts similarity index 100% rename from 2627-debounce/2627-debounce.ts rename to problems/2627-debounce/2627-debounce.ts diff --git a/2627-debounce/NOTES.md b/problems/2627-debounce/NOTES.md similarity index 100% rename from 2627-debounce/NOTES.md rename to problems/2627-debounce/NOTES.md diff --git a/problems/2627-debounce/README.md b/problems/2627-debounce/README.md new file mode 100644 index 000000000..5d2e4f6e9 --- /dev/null +++ b/problems/2627-debounce/README.md @@ -0,0 +1,75 @@ +

2627. Debounce

Medium


Given a function fn and a time in milliseconds t, return a debounced version of that function.

+ +

debounced function is a function whose execution is delayed by t milliseconds and whose execution is cancelled if it is called again within that window of time. The debounced function should also receive the passed parameters.

+ +

For example, let's say t = 50ms, and the function was called at 30ms60ms, and 100ms. The first 2 function calls would be cancelled, and the 3rd function call would be executed at 150ms. If instead t = 35ms, The 1st call would be cancelled, the 2nd would be executed at 95ms, and the 3rd would be executed at 135ms.

+ +

Debounce Schematic

+ +

The above diagram shows how debounce will transform events. Each rectangle represents 100ms and the debounce time is 400ms. Each color represents a different set of inputs.

+ +

Please solve it without using lodash's _.debounce() function.

+ +

 

+

Example 1:

+ +
Input: 
+t = 50
+calls = [
+  {"t": 50, inputs: [1]},
+  {"t": 75, inputs: [2]}
+]
+Output: [{"t": 125, inputs: [2]}]
+Explanation:
+let start = Date.now();
+function log(...inputs) { 
+  console.log([Date.now() - start, inputs ])
+}
+const dlog = debounce(log, 50);
+setTimeout(() => dlog(1), 50);
+setTimeout(() => dlog(2), 75);
+
+The 1st call is cancelled by the 2nd call because the 2nd call occurred before 100ms
+The 2nd call is delayed by 50ms and executed at 125ms. The inputs were (2).
+
+ +

Example 2:

+ +
Input: 
+t = 20
+calls = [
+  {"t": 50, inputs: [1]},
+  {"t": 100, inputs: [2]}
+]
+Output: [{"t": 70, inputs: [1]}, {"t": 120, inputs: [2]}]
+Explanation:
+The 1st call is delayed until 70ms. The inputs were (1).
+The 2nd call is delayed until 120ms. The inputs were (2).
+
+ +

Example 3:

+ +
Input: 
+t = 150
+calls = [
+  {"t": 50, inputs: [1, 2]},
+  {"t": 300, inputs: [3, 4]},
+  {"t": 300, inputs: [5, 6]}
+]
+Output: [{"t": 200, inputs: [1,2]}, {"t": 450, inputs: [5, 6]}]
+Explanation:
+The 1st call is delayed by 150ms and ran at 200ms. The inputs were (1, 2).
+The 2nd call is cancelled by the 3rd call
+The 3rd call is delayed by 150ms and ran at 450ms. The inputs were (5, 6).
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= t <= 1000
  • +
  • 1 <= calls.length <= 10
  • +
  • 0 <= calls[i].t <= 1000
  • +
  • 0 <= calls[i].inputs.length <= 10
  • +
+
\ No newline at end of file diff --git a/2628-json-deep-equal/2628-json-deep-equal.js b/problems/2628-json-deep-equal/2628-json-deep-equal.js similarity index 100% rename from 2628-json-deep-equal/2628-json-deep-equal.js rename to problems/2628-json-deep-equal/2628-json-deep-equal.js diff --git a/2628-json-deep-equal/2628-json-deep-equal.ts b/problems/2628-json-deep-equal/2628-json-deep-equal.ts similarity index 100% rename from 2628-json-deep-equal/2628-json-deep-equal.ts rename to problems/2628-json-deep-equal/2628-json-deep-equal.ts diff --git a/2628-json-deep-equal/NOTES.md b/problems/2628-json-deep-equal/NOTES.md similarity index 100% rename from 2628-json-deep-equal/NOTES.md rename to problems/2628-json-deep-equal/NOTES.md diff --git a/problems/2628-json-deep-equal/README.md b/problems/2628-json-deep-equal/README.md new file mode 100644 index 000000000..10f6565c7 --- /dev/null +++ b/problems/2628-json-deep-equal/README.md @@ -0,0 +1,45 @@ +

2628. JSON Deep Equal

Medium


Given two objects o1 and o2, check if they are deeply equal.

+ +

For two objects to be deeply equal, they must contain the same keys, and the associated values must also be deeply equal. Two objects are also considered deeply equal if they pass the === equality check.

+ +

You may assume both objects are the output of JSON.parse. In other words, they are valid JSON.

+ +

Please solve it without using lodash's _.isEqual() function.

+ +

 

+

Example 1:

+ +
Input: o1 = {"x":1,"y":2}, o2 = {"x":1,"y":2}
+Output: true
+Explanation: The keys and values match exactly.
+
+ +

Example 2:

+ +
Input: o1 = {"y":2,"x":1}, o2 = {"x":1,"y":2}
+Output: true
+Explanation: Although the keys are in a different order, they still match exactly.
+
+ +

Example 3:

+ +
Input: o1 = {"x":null,"L":[1,2,3]}, o2 = {"x":null,"L":["1","2","3"]}
+Output: false
+Explanation: The array of numbers is different from the array of strings.
+
+ +

Example 4:

+ +
Input: o1 = true, o2 = false
+Output: false
+Explanation: true !== false
+ +

 

+

Constraints:

+ +
    +
  • 1 <= JSON.stringify(o1).length <= 105
  • +
  • 1 <= JSON.stringify(o2).length <= 105
  • +
  • maxNestingDepth <= 1000
  • +
+
\ No newline at end of file diff --git a/2629-function-composition/2629-function-composition.js b/problems/2629-function-composition/2629-function-composition.js similarity index 100% rename from 2629-function-composition/2629-function-composition.js rename to problems/2629-function-composition/2629-function-composition.js diff --git a/2629-function-composition/2629-function-composition.ts b/problems/2629-function-composition/2629-function-composition.ts similarity index 100% rename from 2629-function-composition/2629-function-composition.ts rename to problems/2629-function-composition/2629-function-composition.ts diff --git a/2629-function-composition/NOTES.md b/problems/2629-function-composition/NOTES.md similarity index 100% rename from 2629-function-composition/NOTES.md rename to problems/2629-function-composition/NOTES.md diff --git a/problems/2629-function-composition/README.md b/problems/2629-function-composition/README.md new file mode 100644 index 000000000..08a0eab51 --- /dev/null +++ b/problems/2629-function-composition/README.md @@ -0,0 +1,48 @@ +

2629. Function Composition

Easy


Given an array of functions [f1, f2, f3, ..., fn], return a new function fn that is the function composition of the array of functions.

+ +

The function composition of [f(x), g(x), h(x)] is fn(x) = f(g(h(x))).

+ +

The function composition of an empty list of functions is the identity function f(x) = x.

+ +

You may assume each function in the array accepts one integer as input and returns one integer as output.

+ +

 

+

Example 1:

+ +
Input: functions = [x => x + 1, x => x * x, x => 2 * x], x = 4
+Output: 65
+Explanation:
+Evaluating from right to left ...
+Starting with x = 4.
+2 * (4) = 8
+(8) * (8) = 64
+(64) + 1 = 65
+
+ +

Example 2:

+ +
Input: functions = [x => 10 * x, x => 10 * x, x => 10 * x], x = 1
+Output: 1000
+Explanation:
+Evaluating from right to left ...
+10 * (1) = 10
+10 * (10) = 100
+10 * (100) = 1000
+
+ +

Example 3:

+ +
Input: functions = [], x = 42
+Output: 42
+Explanation:
+The composition of zero functions is the identity function
+ +

 

+

Constraints:

+ +
    +
  • -1000 <= x <= 1000
  • +
  • 0 <= functions.length <= 1000
  • +
  • all functions accept and return a single integer
  • +
+
\ No newline at end of file diff --git a/2630-memoize-ii/2630-memoize-ii.ts b/problems/2630-memoize-ii/2630-memoize-ii.ts similarity index 100% rename from 2630-memoize-ii/2630-memoize-ii.ts rename to problems/2630-memoize-ii/2630-memoize-ii.ts diff --git a/2630-memoize-ii/NOTES.md b/problems/2630-memoize-ii/NOTES.md similarity index 100% rename from 2630-memoize-ii/NOTES.md rename to problems/2630-memoize-ii/NOTES.md diff --git a/problems/2630-memoize-ii/README.md b/problems/2630-memoize-ii/README.md new file mode 100644 index 000000000..67b5e3950 --- /dev/null +++ b/problems/2630-memoize-ii/README.md @@ -0,0 +1,54 @@ +

2630. Memoize II

Hard


Given a function fn, return a memoized version of that function.

+ +

memoized function is a function that will never be called twice with the same inputs. Instead it will return a cached value.

+ +

fn can be any function and there are no constraints on what type of values it accepts. Inputs are considered identical if they are === to each other.

+ +

 

+

Example 1:

+ +
Input: 
+getInputs = () => [[2,2],[2,2],[1,2]]
+fn = function (a, b) { return a + b; }
+Output: [{"val":4,"calls":1},{"val":4,"calls":1},{"val":3,"calls":2}]
+Explanation:
+const inputs = getInputs();
+const memoized = memoize(fn);
+for (const arr of inputs) {
+  memoized(...arr);
+}
+
+For the inputs of (2, 2): 2 + 2 = 4, and it required a call to fn().
+For the inputs of (2, 2): 2 + 2 = 4, but those inputs were seen before so no call to fn() was required.
+For the inputs of (1, 2): 1 + 2 = 3, and it required another call to fn() for a total of 2.
+
+ +

Example 2:

+ +
Input: 
+getInputs = () => [[{},{}],[{},{}],[{},{}]] 
+fn = function (a, b) { return ({...a, ...b}); }
+Output: [{"val":{},"calls":1},{"val":{},"calls":2},{"val":{},"calls":3}]
+Explanation:
+Merging two empty objects will always result in an empty object. It may seem like there should only be 1 call to fn() because of cache-hits, however none of those objects are === to each other.
+
+ +

Example 3:

+ +
Input: 
+getInputs = () => { const o = {}; return [[o,o],[o,o],[o,o]]; }
+fn = function (a, b) { return ({...a, ...b}); }
+Output: [{"val":{},"calls":1},{"val":{},"calls":1},{"val":{},"calls":1}]
+Explanation:
+Merging two empty objects will always result in an empty object. The 2nd and 3rd third function calls result in a cache-hit. This is because every object passed in is identical.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= inputs.length <= 105
  • +
  • 0 <= inputs.flat().length <= 105
  • +
  • inputs[i][j] != NaN
  • +
+
\ No newline at end of file diff --git a/2631-group-by/2631-group-by.js b/problems/2631-group-by/2631-group-by.js similarity index 100% rename from 2631-group-by/2631-group-by.js rename to problems/2631-group-by/2631-group-by.js diff --git a/2631-group-by/2631-group-by.ts b/problems/2631-group-by/2631-group-by.ts similarity index 100% rename from 2631-group-by/2631-group-by.ts rename to problems/2631-group-by/2631-group-by.ts diff --git a/2631-group-by/NOTES.md b/problems/2631-group-by/NOTES.md similarity index 100% rename from 2631-group-by/NOTES.md rename to problems/2631-group-by/NOTES.md diff --git a/problems/2631-group-by/README.md b/problems/2631-group-by/README.md new file mode 100644 index 000000000..04f5d8748 --- /dev/null +++ b/problems/2631-group-by/README.md @@ -0,0 +1,81 @@ +

2631. Group By

Medium


Write code that enhances all arrays such that you can call the array.groupBy(fn) method on any array and it will return a grouped version of the array.

+ +

grouped array is an object where each key is the output of fn(arr[i]) and each value is an array containing all items in the original array with that key.

+ +

The provided callback fn will accept an item in the array and return a string key.

+ +

The order of each value list should be the order the items appear in the array. Any order of keys is acceptable.

+ +

Please solve it without lodash's _.groupBy function.

+ +

 

+

Example 1:

+ +
Input: 
+array = [
+  {"id":"1"},
+  {"id":"1"},
+  {"id":"2"}
+], 
+fn = function (item) { 
+  return item.id; 
+}
+Output: 
+{ 
+  "1": [{"id": "1"}, {"id": "1"}],   
+  "2": [{"id": "2"}] 
+}
+Explanation:
+Output is from array.groupBy(fn).
+The selector function gets the "id" out of each item in the array.
+There are two objects with an "id" of 1. Both of those objects are put in the first array.
+There is one object with an "id" of 2. That object is put in the second array.
+
+ +

Example 2:

+ +
Input: 
+array = [
+  [1, 2, 3],
+  [1, 3, 5],
+  [1, 5, 9]
+]
+fn = function (list) { 
+  return String(list[0]); 
+}
+Output: 
+{ 
+  "1": [[1, 2, 3], [1, 3, 5], [1, 5, 9]] 
+}
+Explanation:
+The array can be of any type. In this case, the selector function defines the key as being the first element in the array. 
+All the arrays have 1 as their first element so they are grouped together.
+{
+  "1": [[1, 2, 3], [1, 3, 5], [1, 5, 9]]
+}
+
+ +

Example 3:

+ +
Input: 
+array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+fn = function (n) { 
+  return String(n > 5);
+}
+Output:
+{
+  "true": [6, 7, 8, 9, 10],
+  "false": [1, 2, 3, 4, 5]
+}
+Explanation:
+The selector function splits the array by whether each number is greater than 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= array.length <= 105
  • +
  • fn returns a string
  • +
+
\ No newline at end of file diff --git a/2632-curry/2632-curry.js b/problems/2632-curry/2632-curry.js similarity index 100% rename from 2632-curry/2632-curry.js rename to problems/2632-curry/2632-curry.js diff --git a/2632-curry/2632-curry.ts b/problems/2632-curry/2632-curry.ts similarity index 100% rename from 2632-curry/2632-curry.ts rename to problems/2632-curry/2632-curry.ts diff --git a/2632-curry/NOTES.md b/problems/2632-curry/NOTES.md similarity index 100% rename from 2632-curry/NOTES.md rename to problems/2632-curry/NOTES.md diff --git a/problems/2632-curry/README.md b/problems/2632-curry/README.md new file mode 100644 index 000000000..92d2880f6 --- /dev/null +++ b/problems/2632-curry/README.md @@ -0,0 +1,64 @@ +

2632. Curry

Medium


Given a function fn, return a curried version of that function.

+ +

curried function is a function that accepts fewer or an equal number of parameters as the original function and returns either another curried function or the same value the original function would have returned.

+ +

In practical terms, if you called the original function like sum(1,2,3), you would call the curried version like csum(1)(2)(3)csum(1)(2,3)csum(1,2)(3), or csum(1,2,3). All these methods of calling the curried function should return the same value as the original.

+ +

 

+

Example 1:

+ +
Input: 
+fn = function sum(a, b, c) { return a + b + c; }
+inputs = [[1],[2],[3]]
+Output: 6
+Explanation:
+The code being executed is:
+const curriedSum = curry(fn);
+curriedSum(1)(2)(3) === 6;
+curriedSum(1)(2)(3) should return the same value as sum(1, 2, 3).
+
+ +

Example 2:

+ +
Input:
+fn = function sum(a, b, c) { return a + b + c; }
+inputs = [[1,2],[3]]
+Output: 6
+Explanation:
+curriedSum(1, 2)(3) should return the same value as sum(1, 2, 3).
+ +

Example 3:

+ +
Input:
+fn = function sum(a, b, c) { return a + b + c; }
+inputs = [[],[],[1,2,3]]
+Output: 6
+Explanation:
+You should be able to pass the parameters in any way, including all at once or none at all.
+curriedSum()()(1, 2, 3) should return the same value as sum(1, 2, 3).
+
+ +

Example 4:

+ +
Input:
+fn = function life() { return 42; }
+inputs = [[]]
+Output: 42
+Explanation:
+currying a function that accepts zero parameters should effectively do nothing.
+curriedLife() === 42
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= inputs.length <= 1000
  • +
  • 0 <= inputs[i][j] <= 105
  • +
  • 0 <= fn.length <= 1000
  • +
  • inputs.flat().length == fn.length
  • +
  • function parameters explicitly defined
  • +
  • If fn.length > 0 then the last array in inputs is not empty
  • +
  • If fn.length === 0 then inputs.length === 1 
  • +
+
\ No newline at end of file diff --git a/2633-convert-object-to-json-string/2633-convert-object-to-json-string.js b/problems/2633-convert-object-to-json-string/2633-convert-object-to-json-string.js similarity index 100% rename from 2633-convert-object-to-json-string/2633-convert-object-to-json-string.js rename to problems/2633-convert-object-to-json-string/2633-convert-object-to-json-string.js diff --git a/2633-convert-object-to-json-string/2633-convert-object-to-json-string.ts b/problems/2633-convert-object-to-json-string/2633-convert-object-to-json-string.ts similarity index 100% rename from 2633-convert-object-to-json-string/2633-convert-object-to-json-string.ts rename to problems/2633-convert-object-to-json-string/2633-convert-object-to-json-string.ts diff --git a/2633-convert-object-to-json-string/NOTES.md b/problems/2633-convert-object-to-json-string/NOTES.md similarity index 100% rename from 2633-convert-object-to-json-string/NOTES.md rename to problems/2633-convert-object-to-json-string/NOTES.md diff --git a/problems/2633-convert-object-to-json-string/README.md b/problems/2633-convert-object-to-json-string/README.md new file mode 100644 index 000000000..bf0c8633b --- /dev/null +++ b/problems/2633-convert-object-to-json-string/README.md @@ -0,0 +1,46 @@ +

2633. Convert Object to JSON String

Medium


Given an object, return a valid JSON string of that object. You may assume the object only includes strings, integers, arrays, objects, booleans, and null. The returned string should not include extra spaces. The order of keys should be the same as the order returned by Object.keys().

+ +

Please solve it without using the built-in JSON.stringify method.

+ +

 

+

Example 1:

+ +
Input: object = {"y":1,"x":2}
+Output: {"y":1,"x":2}
+Explanation: 
+Return the JSON representation.
+Note that the order of keys should be the same as the order returned by Object.keys().
+ +

Example 2:

+ +
Input: object = {"a":"str","b":-12,"c":true,"d":null}
+Output: {"a":"str","b":-12,"c":true,"d":null}
+Explanation:
+The primitives of JSON are strings, numbers, booleans, and null.
+
+ +

Example 3:

+ +
Input: object = {"key":{"a":1,"b":[{},null,"Hello"]}}
+Output: {"key":{"a":1,"b":[{},null,"Hello"]}}
+Explanation:
+Objects and arrays can include other objects and arrays.
+
+ +

Example 4:

+ +
Input: object = true
+Output: true
+Explanation:
+Primitive types are valid inputs.
+ +

 

+

Constraints:

+ +
    +
  • object includes strings, integers, booleans, arrays, objects, and null
  • +
  • 1 <= JSON.stringify(object).length <= 105
  • +
  • maxNestingLevel <= 1000
  • +
  • all strings will only contain alphanumeric characters
  • +
+
\ No newline at end of file diff --git a/2634-filter-elements-from-array/2634-filter-elements-from-array.js b/problems/2634-filter-elements-from-array/2634-filter-elements-from-array.js similarity index 100% rename from 2634-filter-elements-from-array/2634-filter-elements-from-array.js rename to problems/2634-filter-elements-from-array/2634-filter-elements-from-array.js diff --git a/2634-filter-elements-from-array/2634-filter-elements-from-array.ts b/problems/2634-filter-elements-from-array/2634-filter-elements-from-array.ts similarity index 100% rename from 2634-filter-elements-from-array/2634-filter-elements-from-array.ts rename to problems/2634-filter-elements-from-array/2634-filter-elements-from-array.ts diff --git a/2634-filter-elements-from-array/NOTES.md b/problems/2634-filter-elements-from-array/NOTES.md similarity index 100% rename from 2634-filter-elements-from-array/NOTES.md rename to problems/2634-filter-elements-from-array/NOTES.md diff --git a/problems/2634-filter-elements-from-array/README.md b/problems/2634-filter-elements-from-array/README.md new file mode 100644 index 000000000..694f1d0bb --- /dev/null +++ b/problems/2634-filter-elements-from-array/README.md @@ -0,0 +1,47 @@ +

2634. Filter Elements from Array

Easy


Given an integer array arr and a filtering function fn, return a filtered array filteredArr.

+ +

The fn function takes one or two arguments:

+ +
    +
  • arr[i] - number from the arr
  • +
  • i - index of arr[i]
  • +
+ +

filteredArr should only contain the elements from the arr for which the expression fn(arr[i], i) evaluates to a truthy value. A truthy value is a value where Boolean(value) returns true.

+ +

Please solve it without the built-in Array.filter method.

+ +

 

+

Example 1:

+ +
Input: arr = [0,10,20,30], fn = function greaterThan10(n) { return n > 10; }
+Output: [20,30]
+Explanation:
+const newArray = filter(arr, fn); // [20, 30]
+The function filters out values that are not greater than 10
+ +

Example 2:

+ +
Input: arr = [1,2,3], fn = function firstIndex(n, i) { return i === 0; }
+Output: [1]
+Explanation:
+fn can also accept the index of each element
+In this case, the function removes elements not at index 0
+
+ +

Example 3:

+ +
Input: arr = [-2,-1,0,1,2], fn = function plusOne(n) { return n + 1 }
+Output: [-2,0,1,2]
+Explanation:
+Falsey values such as 0 should be filtered out
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= arr.length <= 1000
  • +
  • -109 <= arr[i] <= 109
  • +
+
\ No newline at end of file diff --git a/2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.js b/problems/2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.js similarity index 100% rename from 2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.js rename to problems/2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.js diff --git a/2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.ts b/problems/2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.ts similarity index 100% rename from 2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.ts rename to problems/2635-apply-transform-over-each-element-in-array/2635-apply-transform-over-each-element-in-array.ts diff --git a/2635-apply-transform-over-each-element-in-array/NOTES.md b/problems/2635-apply-transform-over-each-element-in-array/NOTES.md similarity index 100% rename from 2635-apply-transform-over-each-element-in-array/NOTES.md rename to problems/2635-apply-transform-over-each-element-in-array/NOTES.md diff --git a/problems/2635-apply-transform-over-each-element-in-array/README.md b/problems/2635-apply-transform-over-each-element-in-array/README.md new file mode 100644 index 000000000..eea14ea64 --- /dev/null +++ b/problems/2635-apply-transform-over-each-element-in-array/README.md @@ -0,0 +1,39 @@ +

2635. Apply Transform Over Each Element in Array

Easy


Given an integer array arr and a mapping function fn, return a new array with a transformation applied to each element.

+ +

The returned array should be created such that returnedArray[i] = fn(arr[i], i).

+ +

Please solve it without the built-in Array.map method.

+ +

 

+

Example 1:

+ +
Input: arr = [1,2,3], fn = function plusone(n) { return n + 1; }
+Output: [2,3,4]
+Explanation:
+const newArray = map(arr, plusone); // [2,3,4]
+The function increases each value in the array by one. 
+
+ +

Example 2:

+ +
Input: arr = [1,2,3], fn = function plusI(n, i) { return n + i; }
+Output: [1,3,5]
+Explanation: The function increases each value by the index it resides in.
+
+ +

Example 3:

+ +
Input: arr = [10,20,30], fn = function constant() { return 42; }
+Output: [42,42,42]
+Explanation: The function always returns 42.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= arr.length <= 1000
  • +
  • -109 <= arr[i] <= 109
  • +
  • fn returns a number
  • +
+
\ No newline at end of file diff --git a/2636-promise-pool/2636-promise-pool.js b/problems/2636-promise-pool/2636-promise-pool.js similarity index 100% rename from 2636-promise-pool/2636-promise-pool.js rename to problems/2636-promise-pool/2636-promise-pool.js diff --git a/2636-promise-pool/2636-promise-pool.ts b/problems/2636-promise-pool/2636-promise-pool.ts similarity index 100% rename from 2636-promise-pool/2636-promise-pool.ts rename to problems/2636-promise-pool/2636-promise-pool.ts diff --git a/2636-promise-pool/NOTES.md b/problems/2636-promise-pool/NOTES.md similarity index 100% rename from 2636-promise-pool/NOTES.md rename to problems/2636-promise-pool/NOTES.md diff --git a/problems/2636-promise-pool/README.md b/problems/2636-promise-pool/README.md new file mode 100644 index 000000000..2d941f5ad --- /dev/null +++ b/problems/2636-promise-pool/README.md @@ -0,0 +1,74 @@ +

2636. Promise Pool

Medium


Given an array of asynchronous functions functions and a pool limit n, return an asynchronous function promisePool. It should return a promise that resolves when all the input functions resolve.

+ +

Pool limit is defined as the maximum number promises that can be pending at once. promisePool should begin execution of as many functions as possible and continue executing new functions when old promises resolve. promisePool should execute functions[i] then functions[i + 1] then functions[i + 2], etc. When the last promise resolves, promisePool should also resolve.

+ +

For example, if n = 1, promisePool will execute one function at a time in series. However, if n = 2, it first executes two functions. When either of the two functions resolve, a 3rd function should be executed (if available), and so on until there are no functions left to execute.

+ +

You can assume all functions never reject. It is acceptable for promisePool to return a promise that resolves any value.

+ +

 

+

Example 1:

+ +
Input: 
+functions = [
+  () => new Promise(res => setTimeout(res, 300)),
+  () => new Promise(res => setTimeout(res, 400)),
+  () => new Promise(res => setTimeout(res, 200))
+]
+n = 2
+Output: [[300,400,500],500]
+Explanation:
+Three functions are passed in. They sleep for 300ms, 400ms, and 200ms respectively.
+They resolve at 300ms, 400ms, and 500ms respectively. The returned promise resolves at 500ms.
+At t=0, the first 2 functions are executed. The pool size limit of 2 is reached.
+At t=300, the 1st function resolves, and the 3rd function is executed. Pool size is 2.
+At t=400, the 2nd function resolves. There is nothing left to execute. Pool size is 1.
+At t=500, the 3rd function resolves. Pool size is zero so the returned promise also resolves.
+
+ +

Example 2:

+ +
Input:
+functions = [
+  () => new Promise(res => setTimeout(res, 300)),
+  () => new Promise(res => setTimeout(res, 400)),
+  () => new Promise(res => setTimeout(res, 200))
+]
+n = 5
+Output: [[300,400,200],400]
+Explanation:
+The three input promises resolve at 300ms, 400ms, and 200ms respectively.
+The returned promise resolves at 400ms.
+At t=0, all 3 functions are executed. The pool limit of 5 is never met.
+At t=200, the 3rd function resolves. Pool size is 2.
+At t=300, the 1st function resolved. Pool size is 1.
+At t=400, the 2nd function resolves. Pool size is 0, so the returned promise also resolves.
+
+ +

Example 3:

+ +
Input:
+functions = [
+  () => new Promise(res => setTimeout(res, 300)),
+  () => new Promise(res => setTimeout(res, 400)),
+  () => new Promise(res => setTimeout(res, 200))
+]
+n = 1
+Output: [[300,700,900],900]
+Explanation:
+The three input promises resolve at 300ms, 700ms, and 900ms respectively.
+The returned promise resolves at 900ms.
+At t=0, the 1st function is executed. Pool size is 1.
+At t=300, the 1st function resolves and the 2nd function is executed. Pool size is 1.
+At t=700, the 2nd function resolves and the 3rd function is executed. Pool size is 1.
+At t=900, the 3rd function resolves. Pool size is 0 so the returned promise resolves.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= functions.length <= 10
  • +
  • 1 <= n <= 10
  • +
+
\ No newline at end of file diff --git a/2637-promise-time-limit/2637-promise-time-limit.js b/problems/2637-promise-time-limit/2637-promise-time-limit.js similarity index 100% rename from 2637-promise-time-limit/2637-promise-time-limit.js rename to problems/2637-promise-time-limit/2637-promise-time-limit.js diff --git a/2637-promise-time-limit/2637-promise-time-limit.ts b/problems/2637-promise-time-limit/2637-promise-time-limit.ts similarity index 100% rename from 2637-promise-time-limit/2637-promise-time-limit.ts rename to problems/2637-promise-time-limit/2637-promise-time-limit.ts diff --git a/2637-promise-time-limit/NOTES.md b/problems/2637-promise-time-limit/NOTES.md similarity index 100% rename from 2637-promise-time-limit/NOTES.md rename to problems/2637-promise-time-limit/NOTES.md diff --git a/problems/2637-promise-time-limit/README.md b/problems/2637-promise-time-limit/README.md new file mode 100644 index 000000000..8996be98a --- /dev/null +++ b/problems/2637-promise-time-limit/README.md @@ -0,0 +1,84 @@ +

2637. Promise Time Limit

Medium


Given an asynchronous function fn and a time t in milliseconds, return a new time limited version of the input function. fn takes arguments provided to the time limited function.

+ +

The time limited function should follow these rules:

+ +
    +
  • If the fn completes within the time limit of t milliseconds, the time limited function should resolve with the result.
  • +
  • If the execution of the fn exceeds the time limit, the time limited function should reject with the string "Time Limit Exceeded".
  • +
+ +

 

+

Example 1:

+ +
Input: 
+fn = async (n) => { 
+  await new Promise(res => setTimeout(res, 100)); 
+  return n * n; 
+}
+inputs = [5]
+t = 50
+Output: {"rejected":"Time Limit Exceeded","time":50}
+Explanation:
+const limited = timeLimit(fn, t)
+const start = performance.now()
+let result;
+try {
+   const res = await limited(...inputs)
+   result = {"resolved": res, "time": Math.floor(performance.now() - start)};
+} catch (err) {
+   result = {"rejected": err, "time": Math.floor(performance.now() - start)};
+}
+console.log(result) // Output
+
+The provided function is set to resolve after 100ms. However, the time limit is set to 50ms. It rejects at t=50ms because the time limit was reached.
+
+ +

Example 2:

+ +
Input: 
+fn = async (n) => { 
+  await new Promise(res => setTimeout(res, 100)); 
+  return n * n; 
+}
+inputs = [5]
+t = 150
+Output: {"resolved":25,"time":100}
+Explanation:
+The function resolved 5 * 5 = 25 at t=100ms. The time limit is never reached.
+
+ +

Example 3:

+ +
Input: 
+fn = async (a, b) => { 
+  await new Promise(res => setTimeout(res, 120)); 
+  return a + b; 
+}
+inputs = [5,10]
+t = 150
+Output: {"resolved":15,"time":120}
+Explanation:
+​​​​The function resolved 5 + 10 = 15 at t=120ms. The time limit is never reached.
+
+ +

Example 4:

+ +
Input: 
+fn = async () => { 
+  throw "Error";
+}
+inputs = []
+t = 1000
+Output: {"rejected":"Error","time":0}
+Explanation:
+The function immediately throws an error.
+ +

 

+

Constraints:

+ +
    +
  • 0 <= inputs.length <= 10
  • +
  • 0 <= t <= 1000
  • +
  • fn returns a promise
  • +
+
\ No newline at end of file diff --git a/2642-design-graph-with-shortest-path-calculator/2642-design-graph-with-shortest-path-calculator.py b/problems/2642-design-graph-with-shortest-path-calculator/2642-design-graph-with-shortest-path-calculator.py similarity index 100% rename from 2642-design-graph-with-shortest-path-calculator/2642-design-graph-with-shortest-path-calculator.py rename to problems/2642-design-graph-with-shortest-path-calculator/2642-design-graph-with-shortest-path-calculator.py diff --git a/2642-design-graph-with-shortest-path-calculator/NOTES.md b/problems/2642-design-graph-with-shortest-path-calculator/NOTES.md similarity index 100% rename from 2642-design-graph-with-shortest-path-calculator/NOTES.md rename to problems/2642-design-graph-with-shortest-path-calculator/NOTES.md diff --git a/problems/2642-design-graph-with-shortest-path-calculator/README.md b/problems/2642-design-graph-with-shortest-path-calculator/README.md new file mode 100644 index 000000000..151185c6a --- /dev/null +++ b/problems/2642-design-graph-with-shortest-path-calculator/README.md @@ -0,0 +1,41 @@ +

2642. Design Graph With Shortest Path Calculator

Hard


There is a directed weighted graph that consists of n nodes numbered from 0 to n - 1. The edges of the graph are initially represented by the given array edges where edges[i] = [fromi, toi, edgeCosti] meaning that there is an edge from fromi to toi with the cost edgeCosti.

+ +

Implement the Graph class:

+ +
    +
  • Graph(int n, int[][] edges) initializes the object with n nodes and the given edges.
  • +
  • addEdge(int[] edge) adds an edge to the list of edges where edge = [from, to, edgeCost]. It is guaranteed that there is no edge between the two nodes before adding this one.
  • +
  • int shortestPath(int node1, int node2) returns the minimum cost of a path from node1 to node2. If no path exists, return -1. The cost of a path is the sum of the costs of the edges in the path.
  • +
+ +

 

+

Example 1:

+ +
Input
+["Graph", "shortestPath", "shortestPath", "addEdge", "shortestPath"]
+[[4, [[0, 2, 5], [0, 1, 2], [1, 2, 1], [3, 0, 3]]], [3, 2], [0, 3], [[1, 3, 4]], [0, 3]]
+Output
+[null, 6, -1, null, 6]
+
+Explanation
+Graph g = new Graph(4, [[0, 2, 5], [0, 1, 2], [1, 2, 1], [3, 0, 3]]);
+g.shortestPath(3, 2); // return 6. The shortest path from 3 to 2 in the first diagram above is 3 -> 0 -> 1 -> 2 with a total cost of 3 + 2 + 1 = 6.
+g.shortestPath(0, 3); // return -1. There is no path from 0 to 3.
+g.addEdge([1, 3, 4]); // We add an edge from node 1 to node 3, and we get the second diagram above.
+g.shortestPath(0, 3); // return 6. The shortest path from 0 to 3 now is 0 -> 1 -> 3 with a total cost of 2 + 4 = 6.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 100
  • +
  • 0 <= edges.length <= n * (n - 1)
  • +
  • edges[i].length == edge.length == 3
  • +
  • 0 <= fromi, toi, from, to, node1, node2 <= n - 1
  • +
  • 1 <= edgeCosti, edgeCost <= 106
  • +
  • There are no repeated edges and no self-loops in the graph at any point.
  • +
  • At most 100 calls will be made for addEdge.
  • +
  • At most 100 calls will be made for shortestPath.
  • +
+
\ No newline at end of file diff --git a/2648-generate-fibonacci-sequence/2648-generate-fibonacci-sequence.ts b/problems/2648-generate-fibonacci-sequence/2648-generate-fibonacci-sequence.ts similarity index 100% rename from 2648-generate-fibonacci-sequence/2648-generate-fibonacci-sequence.ts rename to problems/2648-generate-fibonacci-sequence/2648-generate-fibonacci-sequence.ts diff --git a/2648-generate-fibonacci-sequence/NOTES.md b/problems/2648-generate-fibonacci-sequence/NOTES.md similarity index 100% rename from 2648-generate-fibonacci-sequence/NOTES.md rename to problems/2648-generate-fibonacci-sequence/NOTES.md diff --git a/problems/2648-generate-fibonacci-sequence/README.md b/problems/2648-generate-fibonacci-sequence/README.md new file mode 100644 index 000000000..b2ad9203f --- /dev/null +++ b/problems/2648-generate-fibonacci-sequence/README.md @@ -0,0 +1,34 @@ +

2648. Generate Fibonacci Sequence

Easy


Write a generator function that returns a generator object which yields the fibonacci sequence.

+ +

The fibonacci sequence is defined by the relation Xn = Xn-1 + Xn-2.

+ +

The first few numbers of the series are 0, 1, 1, 2, 3, 5, 8, 13.

+ +

 

+

Example 1:

+ +
Input: callCount = 5
+Output: [0,1,1,2,3]
+Explanation:
+const gen = fibGenerator();
+gen.next().value; // 0
+gen.next().value; // 1
+gen.next().value; // 1
+gen.next().value; // 2
+gen.next().value; // 3
+
+ +

Example 2:

+ +
Input: callCount = 0
+Output: []
+Explanation: gen.next() is never called so nothing is outputted
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= callCount <= 50
  • +
+
\ No newline at end of file diff --git a/2649-nested-array-generator/2649-nested-array-generator.ts b/problems/2649-nested-array-generator/2649-nested-array-generator.ts similarity index 100% rename from 2649-nested-array-generator/2649-nested-array-generator.ts rename to problems/2649-nested-array-generator/2649-nested-array-generator.ts diff --git a/2649-nested-array-generator/NOTES.md b/problems/2649-nested-array-generator/NOTES.md similarity index 100% rename from 2649-nested-array-generator/NOTES.md rename to problems/2649-nested-array-generator/NOTES.md diff --git a/problems/2649-nested-array-generator/README.md b/problems/2649-nested-array-generator/README.md new file mode 100644 index 000000000..73c2baee4 --- /dev/null +++ b/problems/2649-nested-array-generator/README.md @@ -0,0 +1,37 @@ +

2649. Nested Array Generator

Medium


Given a multi-dimensional array of integers, return a generator object which yields integers in the same order as inorder traversal.

+ +

multi-dimensional array is a recursive data structure that contains both integers and other multi-dimensional arrays.

+ +

inorder traversal iterates over each array from left to right, yielding any integers it encounters or applying inorder traversal to any arrays it encounters.

+ +

 

+

Example 1:

+ +
Input: arr = [[[6]],[1,3],[]]
+Output: [6,1,3]
+Explanation:
+const generator = inorderTraversal(arr);
+generator.next().value; // 6
+generator.next().value; // 1
+generator.next().value; // 3
+generator.next().done; // true
+
+ +

Example 2:

+ +
Input: arr = []
+Output: []
+Explanation: There are no integers so the generator doesn't yield anything.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= arr.flat().length <= 105
  • +
  • 0 <= arr.flat()[i] <= 105
  • +
  • maxNestingDepth <= 105
  • +
+ +

 

+Can you solve this without creating a new flattened version of the array?
\ No newline at end of file diff --git a/2650-design-cancellable-function/2650-design-cancellable-function.ts b/problems/2650-design-cancellable-function/2650-design-cancellable-function.ts similarity index 100% rename from 2650-design-cancellable-function/2650-design-cancellable-function.ts rename to problems/2650-design-cancellable-function/2650-design-cancellable-function.ts diff --git a/2650-design-cancellable-function/NOTES.md b/problems/2650-design-cancellable-function/NOTES.md similarity index 100% rename from 2650-design-cancellable-function/NOTES.md rename to problems/2650-design-cancellable-function/NOTES.md diff --git a/problems/2650-design-cancellable-function/README.md b/problems/2650-design-cancellable-function/README.md new file mode 100644 index 000000000..7a2f86669 --- /dev/null +++ b/problems/2650-design-cancellable-function/README.md @@ -0,0 +1,129 @@ +

2650. Design Cancellable Function

Hard


Sometimes you have a long running task, and you may wish to cancel it before it completes. To help with this goal, write a function cancellable that accepts a generator object and returns an array of two values: a cancel function and a promise.

+ +

You may assume the generator function will only yield promises. It is your function's responsibility to pass the values resolved by the promise back to the generator. If the promise rejects, your function should throw that error back to the generator.

+ +

If the cancel callback is called before the generator is done, your function should throw an error back to the generator. That error should be the string "Cancelled" (Not an Error object). If the error was caught, the returned promise should resolve with the next value that was yielded or returned. Otherwise, the promise should reject with the thrown error. No more code should be executed.

+ +

When the generator is done, the promise your function returned should resolve the value the generator returned. If, however, the generator throws an error, the returned promise should reject with the error.

+ +

An example of how your code would be used:

+ +
function* tasks() {
+  const val = yield new Promise(resolve => resolve(2 + 2));
+  yield new Promise(resolve => setTimeout(resolve, 100));
+  return val + 1; // calculation shouldn't be done.
+}
+const [cancel, promise] = cancellable(tasks());
+setTimeout(cancel, 50);
+promise.catch(console.log); // logs "Cancelled" at t=50ms
+
+ +

If instead cancel() was not called or was called after t=100ms, the promise would have resolved 5.

+ +

 

+

Example 1:

+ +
Input: 
+generatorFunction = function*() { 
+  return 42; 
+}
+cancelledAt = 100
+Output: {"resolved": 42}
+Explanation:
+const generator = generatorFunction();
+const [cancel, promise] = cancellable(generator);
+setTimeout(cancel, 100);
+promise.then(console.log); // resolves 42 at t=0ms
+
+The generator immediately yields 42 and finishes. Because of that, the returned promise immediately resolves 42. Note that cancelling a finished generator does nothing.
+
+ +

Example 2:

+ +
Input:
+generatorFunction = function*() { 
+  const msg = yield new Promise(res => res("Hello")); 
+  throw `Error: ${msg}`; 
+}
+cancelledAt = null
+Output: {"rejected": "Error: Hello"}
+Explanation:
+A promise is yielded. The function handles this by waiting for it to resolve and then passes the resolved value back to the generator. Then an error is thrown which has the effect of causing the promise to reject with the same thrown error.
+
+ +

Example 3:

+ +
Input: 
+generatorFunction = function*() { 
+  yield new Promise(res => setTimeout(res, 200)); 
+  return "Success"; 
+}
+cancelledAt = 100
+Output: {"rejected": "Cancelled"}
+Explanation:
+While the function is waiting for the yielded promise to resolve, cancel() is called. This causes an error message to be sent back to the generator. Since this error is uncaught, the returned promise rejected with this error.
+
+ +

Example 4:

+ +
Input:
+generatorFunction = function*() { 
+  let result = 0; 
+  yield new Promise(res => setTimeout(res, 100));
+  result += yield new Promise(res => res(1)); 
+  yield new Promise(res => setTimeout(res, 100)); 
+  result += yield new Promise(res => res(1)); 
+  return result;
+}
+cancelledAt = null
+Output: {"resolved": 2}
+Explanation:
+4 promises are yielded. Two of those promises have their values added to the result. After 200ms, the generator finishes with a value of 2, and that value is resolved by the returned promise.
+
+ +

Example 5:

+ +
Input: 
+generatorFunction = function*() { 
+  let result = 0; 
+  try { 
+    yield new Promise(res => setTimeout(res, 100)); 
+    result += yield new Promise(res => res(1)); 
+    yield new Promise(res => setTimeout(res, 100)); 
+    result += yield new Promise(res => res(1)); 
+  } catch(e) { 
+    return result; 
+  } 
+  return result; 
+}
+cancelledAt = 150
+Output: {"resolved": 1}
+Explanation:
+The first two yielded promises resolve and cause the result to increment. However, at t=150ms, the generator is cancelled. The error sent to the generator is caught and the result is returned and finally resolved by the returned promise.
+
+ +

Example 6:

+ +
Input: 
+generatorFunction = function*() { 
+  try { 
+    yield new Promise((resolve, reject) => reject("Promise Rejected")); 
+  } catch(e) { 
+    let a = yield new Promise(resolve => resolve(2));
+    let b = yield new Promise(resolve => resolve(2)); 
+    return a + b; 
+  }; 
+}
+cancelledAt = null
+Output: {"resolved": 4}
+Explanation:
+The first yielded promise immediately rejects. This error is caught. Because the generator hasn't been cancelled, execution continues as usual. It ends up resolving 2 + 2 = 4.
+ +

 

+

Constraints:

+ +
    +
  • cancelledAt == null or 0 <= cancelledAt <= 1000
  • +
  • generatorFunction returns a generator object
  • +
+
\ No newline at end of file diff --git a/2665-counter-ii/2665-counter-ii.js b/problems/2665-counter-ii/2665-counter-ii.js similarity index 100% rename from 2665-counter-ii/2665-counter-ii.js rename to problems/2665-counter-ii/2665-counter-ii.js diff --git a/2665-counter-ii/2665-counter-ii.ts b/problems/2665-counter-ii/2665-counter-ii.ts similarity index 100% rename from 2665-counter-ii/2665-counter-ii.ts rename to problems/2665-counter-ii/2665-counter-ii.ts diff --git a/2665-counter-ii/NOTES.md b/problems/2665-counter-ii/NOTES.md similarity index 100% rename from 2665-counter-ii/NOTES.md rename to problems/2665-counter-ii/NOTES.md diff --git a/problems/2665-counter-ii/README.md b/problems/2665-counter-ii/README.md new file mode 100644 index 000000000..83e4bfe16 --- /dev/null +++ b/problems/2665-counter-ii/README.md @@ -0,0 +1,43 @@ +

2665. Counter II

Easy


Write a function createCounter. It should accept an initial integer init. It should return an object with three functions.

+ +

The three functions are:

+ +
    +
  • increment() increases the current value by 1 and then returns it.
  • +
  • decrement() reduces the current value by 1 and then returns it.
  • +
  • reset() sets the current value to init and then returns it.
  • +
+ +

 

+

Example 1:

+ +
Input: init = 5, calls = ["increment","reset","decrement"]
+Output: [6,5,4]
+Explanation:
+const counter = createCounter(5);
+counter.increment(); // 6
+counter.reset(); // 5
+counter.decrement(); // 4
+
+ +

Example 2:

+ +
Input: init = 0, calls = ["increment","increment","decrement","reset","reset"]
+Output: [1,2,1,0,0]
+Explanation:
+const counter = createCounter(0);
+counter.increment(); // 1
+counter.increment(); // 2
+counter.decrement(); // 1
+counter.reset(); // 0
+counter.reset(); // 0
+
+ +

 

+

Constraints:

+ +
    +
  • -1000 <= init <= 1000
  • +
  • total calls not to exceed 1000
  • +
+
\ No newline at end of file diff --git a/2666-allow-one-function-call/2666-allow-one-function-call.js b/problems/2666-allow-one-function-call/2666-allow-one-function-call.js similarity index 100% rename from 2666-allow-one-function-call/2666-allow-one-function-call.js rename to problems/2666-allow-one-function-call/2666-allow-one-function-call.js diff --git a/2666-allow-one-function-call/2666-allow-one-function-call.ts b/problems/2666-allow-one-function-call/2666-allow-one-function-call.ts similarity index 100% rename from 2666-allow-one-function-call/2666-allow-one-function-call.ts rename to problems/2666-allow-one-function-call/2666-allow-one-function-call.ts diff --git a/2666-allow-one-function-call/NOTES.md b/problems/2666-allow-one-function-call/NOTES.md similarity index 100% rename from 2666-allow-one-function-call/NOTES.md rename to problems/2666-allow-one-function-call/NOTES.md diff --git a/problems/2666-allow-one-function-call/README.md b/problems/2666-allow-one-function-call/README.md new file mode 100644 index 000000000..0e0e4d606 --- /dev/null +++ b/problems/2666-allow-one-function-call/README.md @@ -0,0 +1,38 @@ +

2666. Allow One Function Call

Easy


Given a function fn, return a new function that is identical to the original function except that it ensures fn is called at most once.

+ +
    +
  • The first time the returned function is called, it should return the same result as fn.
  • +
  • Every subsequent time it is called, it should return undefined.
  • +
+ +

 

+

Example 1:

+ +
Input: fn = (a,b,c) => (a + b + c), calls = [[1,2,3],[2,3,6]]
+Output: [{"calls":1,"value":6}]
+Explanation:
+const onceFn = once(fn);
+onceFn(1, 2, 3); // 6
+onceFn(2, 3, 6); // undefined, fn was not called
+
+ +

Example 2:

+ +
Input: fn = (a,b,c) => (a * b * c), calls = [[5,7,4],[2,3,6],[4,6,8]]
+Output: [{"calls":1,"value":140}]
+Explanation:
+const onceFn = once(fn);
+onceFn(5, 7, 4); // 140
+onceFn(2, 3, 6); // undefined, fn was not called
+onceFn(4, 6, 8); // undefined, fn was not called
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= calls.length <= 10
  • +
  • 1 <= calls[i].length <= 100
  • +
  • 2 <= JSON.stringify(calls).length <= 1000
  • +
+
\ No newline at end of file diff --git a/2667-create-hello-world-function/2667-create-hello-world-function.js b/problems/2667-create-hello-world-function/2667-create-hello-world-function.js similarity index 100% rename from 2667-create-hello-world-function/2667-create-hello-world-function.js rename to problems/2667-create-hello-world-function/2667-create-hello-world-function.js diff --git a/2667-create-hello-world-function/2667-create-hello-world-function.ts b/problems/2667-create-hello-world-function/2667-create-hello-world-function.ts similarity index 100% rename from 2667-create-hello-world-function/2667-create-hello-world-function.ts rename to problems/2667-create-hello-world-function/2667-create-hello-world-function.ts diff --git a/2667-create-hello-world-function/NOTES.md b/problems/2667-create-hello-world-function/NOTES.md similarity index 100% rename from 2667-create-hello-world-function/NOTES.md rename to problems/2667-create-hello-world-function/NOTES.md diff --git a/problems/2667-create-hello-world-function/README.md b/problems/2667-create-hello-world-function/README.md new file mode 100644 index 000000000..481129742 --- /dev/null +++ b/problems/2667-create-hello-world-function/README.md @@ -0,0 +1,31 @@ +

2667. Create Hello World Function

Easy


Write a function createHelloWorld. It should return a new function that always returns "Hello World". +

 

+

Example 1:

+ +
Input: args = []
+Output: "Hello World"
+Explanation:
+const f = createHelloWorld();
+f(); // "Hello World"
+
+The function returned by createHelloWorld should always return "Hello World".
+
+ +

Example 2:

+ +
Input: args = [{},null,42]
+Output: "Hello World"
+Explanation:
+const f = createHelloWorld();
+f({}, null, 42); // "Hello World"
+
+Any arguments could be passed to the function but it should still always return "Hello World".
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= args.length <= 10
  • +
+
\ No newline at end of file diff --git a/2675-array-of-objects-to-matrix/2675-array-of-objects-to-matrix.ts b/problems/2675-array-of-objects-to-matrix/2675-array-of-objects-to-matrix.ts similarity index 100% rename from 2675-array-of-objects-to-matrix/2675-array-of-objects-to-matrix.ts rename to problems/2675-array-of-objects-to-matrix/2675-array-of-objects-to-matrix.ts diff --git a/2675-array-of-objects-to-matrix/NOTES.md b/problems/2675-array-of-objects-to-matrix/NOTES.md similarity index 100% rename from 2675-array-of-objects-to-matrix/NOTES.md rename to problems/2675-array-of-objects-to-matrix/NOTES.md diff --git a/problems/2675-array-of-objects-to-matrix/README.md b/problems/2675-array-of-objects-to-matrix/README.md new file mode 100644 index 000000000..bf453cd01 --- /dev/null +++ b/problems/2675-array-of-objects-to-matrix/README.md @@ -0,0 +1,121 @@ +

2675. Array of Objects to Matrix

Medium


Write a function that converts an array of objects arr into a matrix m.

+ +

arr is an array of objects or arrays. Each item in the array can be deeply nested with child arrays and child objects. It can also contain numbers, strings, booleans, and null values.

+ +

The first row m should be the column names. If there is no nesting, the column names are the unique keys within the objects. If there is nesting, the column names are the respective paths in the object separated by ".".

+ +

Each of the remaining rows corresponds to an object in arr. Each value in the matrix corresponds to a value in an object. If a given object doesn't contain a value for a given column, the cell should contain an empty string "".

+ +

The columns in the matrix should be in lexographically ascending order.

+ +

 

+

Example 1:

+ +
Input: 
+arr = [
+  {"b": 1, "a": 2},
+  {"b": 3, "a": 4}
+]
+Output: 
+[
+  ["a", "b"],
+  [2, 1],
+  [4, 3]
+]
+
+Explanation:
+There are two unique column names in the two objects: "a" and "b".
+"a" corresponds with [2, 4].
+"b" coresponds with [1, 3].
+
+ +

Example 2:

+ +
Input: 
+arr = [
+  {"a": 1, "b": 2},
+  {"c": 3, "d": 4},
+  {}
+]
+Output: 
+[
+  ["a", "b", "c", "d"],
+  [1, 2, "", ""],
+  ["", "", 3, 4],
+  ["", "", "", ""]
+]
+
+Explanation:
+There are 4 unique column names: "a", "b", "c", "d".
+The first object has values associated with "a" and "b".
+The second object has values associated with "c" and "d".
+The third object has no keys, so it is just a row of empty strings.
+
+ +

Example 3:

+ +
Input: 
+arr = [
+  {"a": {"b": 1, "c": 2}},
+  {"a": {"b": 3, "d": 4}}
+]
+Output: 
+[
+  ["a.b", "a.c", "a.d"],
+  [1, 2, ""],
+  [3, "", 4]
+]
+
+Explanation:
+In this example, the objects are nested. The keys represent the full path to each value separated by periods.
+There are three paths: "a.b", "a.c", "a.d".
+
+ +

Example 4:

+ +
Input: 
+arr = [
+  [{"a": null}],
+  [{"b": true}],
+  [{"c": "x"}]
+]
+Output: 
+[
+  ["0.a", "0.b", "0.c"],
+  [null, "", ""],
+  ["", true, ""],
+  ["", "", "x"]
+]
+
+Explanation:
+Arrays are also considered objects with their keys being their indices.
+Each array has one element so the keys are "0.a", "0.b", and "0.c".
+
+ +

Example 5:

+ +
Input: 
+arr = [
+  {},
+  {},
+  {},
+]
+Output: 
+[
+  [],
+  [],
+  [],
+  []
+]
+
+Explanation:
+There are no keys so every row is an empty array.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= arr.length <= 1000
  • +
  • unique keys <= 1000
  • +
+
\ No newline at end of file diff --git a/2676-throttle/2676-throttle.js b/problems/2676-throttle/2676-throttle.js similarity index 100% rename from 2676-throttle/2676-throttle.js rename to problems/2676-throttle/2676-throttle.js diff --git a/2676-throttle/2676-throttle.ts b/problems/2676-throttle/2676-throttle.ts similarity index 100% rename from 2676-throttle/2676-throttle.ts rename to problems/2676-throttle/2676-throttle.ts diff --git a/2676-throttle/NOTES.md b/problems/2676-throttle/NOTES.md similarity index 100% rename from 2676-throttle/NOTES.md rename to problems/2676-throttle/NOTES.md diff --git a/problems/2676-throttle/README.md b/problems/2676-throttle/README.md new file mode 100644 index 000000000..4ccb45c9f --- /dev/null +++ b/problems/2676-throttle/README.md @@ -0,0 +1,46 @@ +

2676. Throttle

Medium


Given a function fn and a time in milliseconds t, return a throttled version of that function.

+ +

A throttled function is first called without delay and then, for a time interval of t milliseconds, can't be executed but should store the latest function arguments provided to call fn with them after the end of the delay.

+ +

For instance, t = 50ms, and the function was called at 30ms, 40ms, and 60ms. The first function call would block calling functions for the following t milliseconds. The second function call would save arguments, and the third call arguments should overwrite currently stored arguments from the second call because the second and third calls are called before 80ms. Once the delay has passed, the throttled function should be called with the latest arguments provided during the delay period, and it should also create another delay period of 80ms + t.

+ +

Throttle DiagramThe above diagram shows how throttle will transform events. Each rectangle represents 100ms and the throttle time is 400ms. Each color represents a different set of inputs.

+ +

 

+

Example 1:

+ +
Input: t = 100, calls = [{"t":20,"inputs":[1]}]
+Output: [{"t":20,"inputs":[1]}]
+Explanation: The 1st call is always called without delay
+
+ +

Example 2:

+ +
Input: t = 50, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]}]
+Output: [{"t":50,"inputs":[1]},{"t":100,"inputs":[2]}]
+Explanation: 
+The 1st is called a function with arguments (1) without delay.
+The 2nd is called at 75ms, within the delay period because 50ms + 50ms = 100ms, so the next call can be reached at 100ms. Therefore, we save arguments from the 2nd call to use them at the callback of the 1st call.
+
+ +

Example 3:

+ +
Input: t = 70, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]},{"t":90,"inputs":[8]},{"t": 140, "inputs":[5,7]},{"t": 300, "inputs": [9,4]}]
+Output: [{"t":50,"inputs":[1]},{"t":120,"inputs":[8]},{"t":190,"inputs":[5,7]},{"t":300,"inputs":[9,4]}]
+Explanation: 
+The 1st is called a function with arguments (1) without delay.
+The 2nd is called at 75ms within the delay period because 50ms + 70ms = 120ms, so it should only save arguments. 
+The 3rd is also called within the delay period, and because we need just the latest function arguments, we overwrite previous ones. After the delay period, we do a callback at 120ms with saved arguments. That callback makes another delay period of 120ms + 70ms = 190ms so that the next function can be called at 190ms.
+The 4th is called at 140ms in the delay period, so it should be called as a callback at 190ms. That will create another delay period of 190ms + 70ms = 260ms.
+The 5th is called at 300ms, but it is after 260ms, so it should be called immediately and should create another delay period of 300ms + 70ms = 370ms.
+ +

 

+

Constraints:

+ +
    +
  • 0 <= t <= 1000
  • +
  • 1 <= calls.length <= 10
  • +
  • 0 <= calls[i].t <= 1000
  • +
  • 0 <= calls[i].inputs[j], calls[i].inputs.length <= 10
  • +
+
\ No newline at end of file diff --git a/2677-chunk-array/2677-chunk-array.js b/problems/2677-chunk-array/2677-chunk-array.js similarity index 100% rename from 2677-chunk-array/2677-chunk-array.js rename to problems/2677-chunk-array/2677-chunk-array.js diff --git a/2677-chunk-array/2677-chunk-array.ts b/problems/2677-chunk-array/2677-chunk-array.ts similarity index 100% rename from 2677-chunk-array/2677-chunk-array.ts rename to problems/2677-chunk-array/2677-chunk-array.ts diff --git a/2677-chunk-array/NOTES.md b/problems/2677-chunk-array/NOTES.md similarity index 100% rename from 2677-chunk-array/NOTES.md rename to problems/2677-chunk-array/NOTES.md diff --git a/problems/2677-chunk-array/README.md b/problems/2677-chunk-array/README.md new file mode 100644 index 000000000..3f945f0a5 --- /dev/null +++ b/problems/2677-chunk-array/README.md @@ -0,0 +1,43 @@ +

2677. Chunk Array

Easy


Given an array arr and a chunk size size, return a chunked array. A chunked array contains the original elements in arr, but consists of subarrays each of length size. The length of the last subarray may be less than size if arr.length is not evenly divisible by size.

+ +

You may assume the array is the output of JSON.parse. In other words, it is valid JSON.

+ +

Please solve it without using lodash's _.chunk function.

+ +

 

+

Example 1:

+ +
Input: arr = [1,2,3,4,5], size = 1
+Output: [[1],[2],[3],[4],[5]]
+Explanation: The arr has been split into subarrays each with 1 element.
+
+ +

Example 2:

+ +
Input: arr = [1,9,6,3,2], size = 3
+Output: [[1,9,6],[3,2]]
+Explanation: The arr has been split into subarrays with 3 elements. However, only two elements are left for the 2nd subarray.
+
+ +

Example 3:

+ +
Input: arr = [8,5,3,2,6], size = 6
+Output: [[8,5,3,2,6]]
+Explanation: Size is greater than arr.length thus all elements are in the first subarray.
+
+ +

Example 4:

+ +
Input: arr = [], size = 1
+Output: []
+Explanation: There are no elements to be chunked so an empty array is returned.
+ +

 

+

Constraints:

+ +
    +
  • arr is a valid JSON array
  • +
  • 2 <= JSON.stringify(arr).length <= 105
  • +
  • 1 <= size <= arr.length + 1
  • +
+
\ No newline at end of file diff --git a/2678-number-of-senior-citizens/2678-number-of-senior-citizens.py b/problems/2678-number-of-senior-citizens/2678-number-of-senior-citizens.py similarity index 100% rename from 2678-number-of-senior-citizens/2678-number-of-senior-citizens.py rename to problems/2678-number-of-senior-citizens/2678-number-of-senior-citizens.py diff --git a/problems/2678-number-of-senior-citizens/README.md b/problems/2678-number-of-senior-citizens/README.md new file mode 100644 index 000000000..f48784b3e --- /dev/null +++ b/problems/2678-number-of-senior-citizens/README.md @@ -0,0 +1,37 @@ +

2678. Number of Senior Citizens

Easy


You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:

+ +
    +
  • The first ten characters consist of the phone number of passengers.
  • +
  • The next character denotes the gender of the person.
  • +
  • The following two characters are used to indicate the age of the person.
  • +
  • The last two characters determine the seat allotted to that person.
  • +
+ +

Return the number of passengers who are strictly more than 60 years old.

+ +

 

+

Example 1:

+ +
Input: details = ["7868190130M7522","5303914400F9211","9273338290F4010"]
+Output: 2
+Explanation: The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.
+
+ +

Example 2:

+ +
Input: details = ["1313579440F2036","2921522980M5644"]
+Output: 0
+Explanation: None of the passengers are older than 60.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= details.length <= 100
  • +
  • details[i].length == 15
  • +
  • details[i] consists of digits from '0' to '9'.
  • +
  • details[i][10] is either 'M' or 'F' or 'O'.
  • +
  • The phone numbers and seat numbers of the passengers are distinct.
  • +
+
\ No newline at end of file diff --git a/2690-infinite-method-object/2690-infinite-method-object.ts b/problems/2690-infinite-method-object/2690-infinite-method-object.ts similarity index 100% rename from 2690-infinite-method-object/2690-infinite-method-object.ts rename to problems/2690-infinite-method-object/2690-infinite-method-object.ts diff --git a/2690-infinite-method-object/NOTES.md b/problems/2690-infinite-method-object/NOTES.md similarity index 100% rename from 2690-infinite-method-object/NOTES.md rename to problems/2690-infinite-method-object/NOTES.md diff --git a/problems/2690-infinite-method-object/README.md b/problems/2690-infinite-method-object/README.md new file mode 100644 index 000000000..ab9fe5f55 --- /dev/null +++ b/problems/2690-infinite-method-object/README.md @@ -0,0 +1,29 @@ +

2690. Infinite Method Object

Easy


Write a function that returns an infinite-method object.

+ +

An infinite-method object is defined as an object that allows you to call any method and it will always return the name of the method.

+ +

For example, if you execute obj.abc123(), it will return "abc123".

+ +

 

+

Example 1:

+ +
Input: method = "abc123"
+Output: "abc123"
+Explanation:
+const obj = createInfiniteObject();
+obj['abc123'](); // "abc123"
+The returned string should always match the method name.
+ +

Example 2:

+ +
Input: method = ".-qw73n|^2It"
+Output: ".-qw73n|^2It"
+Explanation: The returned string should always match the method name.
+ +

 

+

Constraints:

+ +
    +
  • 0 <= method.length <= 1000
  • +
+
\ No newline at end of file diff --git a/2692-make-object-immutable/2692-make-object-immutable.ts b/problems/2692-make-object-immutable/2692-make-object-immutable.ts similarity index 100% rename from 2692-make-object-immutable/2692-make-object-immutable.ts rename to problems/2692-make-object-immutable/2692-make-object-immutable.ts diff --git a/2692-make-object-immutable/NOTES.md b/problems/2692-make-object-immutable/NOTES.md similarity index 100% rename from 2692-make-object-immutable/NOTES.md rename to problems/2692-make-object-immutable/NOTES.md diff --git a/problems/2692-make-object-immutable/README.md b/problems/2692-make-object-immutable/README.md new file mode 100644 index 000000000..591b6af7d --- /dev/null +++ b/problems/2692-make-object-immutable/README.md @@ -0,0 +1,78 @@ +

2692. Make Object Immutable

Medium


Write a function that takes an object obj and returns a new immutable version of this object.

+ +

An immutable object is an object that can't be altered and will throw an error if any attempt is made to alter it.

+ +

There are three types of error messages that can be produced from this new object.

+ +
    +
  • Attempting to modify a key on the object will result in this error message: `Error Modifying: ${key}`.
  • +
  • Attempting to modify an index on an array will result in this error message: `Error Modifying Index: ${index}`.
  • +
  • Attempting to call a method that mutates an array will result in this error message: `Error Calling Method: ${methodName}`. You may assume the only methods that can mutate an array are ['pop', 'push', 'shift', 'unshift', 'splice', 'sort', 'reverse'].
  • +
+ +

obj is a valid JSON object or array, meaning it is the output of JSON.parse().

+ +

Note that a string literal should be thrown, not an Error.

+ +

 

+

Example 1:

+ +
Input: 
+obj = {
+  "x": 5
+}
+fn = (obj) => { 
+  obj.x = 5;
+  return obj.x;
+}
+Output: {"value": null, "error": "Error Modifying: x"}
+Explanation: Attempting to modify a key on an object resuts in a thrown error. Note that it doesn't matter that the value was set to the same value as it was before.
+
+ +

Example 2:

+ +
Input: 
+obj = [1, 2, 3]
+fn = (arr) => { 
+  arr[1] = {}; 
+  return arr[2]; 
+}
+Output: {"value": null, "error": "Error Modifying Index: 1"}
+Explanation: Attempting to modify an array results in a thrown error.
+
+ +

Example 3:

+ +
Input: 
+obj = {
+  "arr": [1, 2, 3]
+}
+fn = (obj) => { 
+  obj.arr.push(4);
+  return 42;
+}
+Output: { "value": null, "error": "Error Calling Method: push"}
+Explanation: Calling a method that can result in a mutation results in a thrown error.
+
+ +

Example 4:

+ +
Input: 
+obj = {
+  "x": 2,
+  "y": 2
+}
+fn = (obj) => { 
+  return Object.keys(obj);
+}
+Output: {"value": ["x", "y"], "error": null}
+Explanation: No mutations were attempted so the function returns as normal.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= JSON.stringify(obj).length <= 105
  • +
+
\ No newline at end of file diff --git a/2694-event-emitter/2694-event-emitter.js b/problems/2694-event-emitter/2694-event-emitter.js similarity index 100% rename from 2694-event-emitter/2694-event-emitter.js rename to problems/2694-event-emitter/2694-event-emitter.js diff --git a/2694-event-emitter/NOTES.md b/problems/2694-event-emitter/NOTES.md similarity index 100% rename from 2694-event-emitter/NOTES.md rename to problems/2694-event-emitter/NOTES.md diff --git a/problems/2694-event-emitter/README.md b/problems/2694-event-emitter/README.md new file mode 100644 index 000000000..1771223aa --- /dev/null +++ b/problems/2694-event-emitter/README.md @@ -0,0 +1,73 @@ +

2694. Event Emitter

Medium


Design an EventEmitter class. This interface is similar (but with some differences) to the one found in Node.js or the Event Target interface of the DOM. The EventEmitter should allow for subscribing to events and emitting them.

+ +

Your EventEmitter class should have the following two methods:

+ +
    +
  • subscribe - This method takes in two arguments: the name of an event as a string and a callback function. This callback function will later be called when the event is emitted.
    + An event should be able to have multiple listeners for the same event. When emitting an event with multiple callbacks, each should be called in the order in which they were subscribed. An array of results should be returned. You can assume no callbacks passed to subscribe are referentially identical.
    + The subscribe method should also return an object with an unsubscribe method that enables the user to unsubscribe. When it is called, the callback should be removed from the list of subscriptions and undefined should be returned.
  • +
  • emit - This method takes in two arguments: the name of an event as a string and an optional array of arguments that will be passed to the callback(s). If there are no callbacks subscribed to the given event, return an empty array. Otherwise, return an array of the results of all callback calls in the order they were subscribed.
  • +
+ +

 

+

Example 1:

+ +
Input: actions = ["EventEmitter", "emit", "subscribe", "subscribe", "emit"], values = [[], ["firstEvent", "function cb1() { return 5; }"],  ["firstEvent", "function cb1() { return 5; }"], ["firstEvent"]]
+Output: [[],["emitted",[]],["subscribed"],["subscribed"],["emitted",[5,6]]]
+Explanation: 
+const emitter = new EventEmitter();
+emitter.emit("firstEvent"); // [], no callback are subscribed yet
+emitter.subscribe("firstEvent", function cb1() { return 5; });
+emitter.subscribe("firstEvent", function cb2() { return 6; });
+emitter.emit("firstEvent"); // [5, 6], returns the output of cb1 and cb2
+
+ +

Example 2:

+ +
Input: actions = ["EventEmitter", "subscribe", "emit", "emit"], values = [[], ["firstEvent", "function cb1(...args) { return args.join(','); }"], ["firstEvent", [1,2,3]], ["firstEvent", [3,4,6]]]
+Output: [[],["subscribed"],["emitted",["1,2,3"]],["emitted",["3,4,6"]]]
+Explanation: Note that the emit method should be able to accept an OPTIONAL array of arguments.
+
+const emitter = new EventEmitter();
+emitter.subscribe("firstEvent, function cb1(...args) { return args.join(','); });
+emitter.emit("firstEvent", [1, 2, 3]); // ["1,2,3"]
+emitter.emit("firstEvent", [3, 4, 6]); // ["3,4,6"]
+
+ +

Example 3:

+ +
Input: actions = ["EventEmitter", "subscribe", "emit", "unsubscribe", "emit"], values = [[], ["firstEvent", "(...args) => args.join(',')"], ["firstEvent", [1,2,3]], [0], ["firstEvent", [4,5,6]]]
+Output: [[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[]]]
+Explanation:
+const emitter = new EventEmitter();
+const sub = emitter.subscribe("firstEvent", (...args) => args.join(','));
+emitter.emit("firstEvent", [1, 2, 3]); // ["1,2,3"]
+sub.unsubscribe(); // undefined
+emitter.emit("firstEvent", [4, 5, 6]); // [], there are no subscriptions
+
+ +

Example 4:

+ +
Input: actions = ["EventEmitter", "subscribe", "subscribe", "unsubscribe", "emit"], values = [[], ["firstEvent", "x => x + 1"], ["firstEvent", "x => x + 2"], [0], ["firstEvent", [5]]]
+Output: [[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[7]]]
+Explanation:
+const emitter = new EventEmitter();
+const sub1 = emitter.subscribe("firstEvent", x => x + 1);
+const sub2 = emitter.subscribe("firstEvent", x => x + 2);
+sub1.unsubscribe(); // undefined
+emitter.emit("firstEvent", [5]); // [7]
+ +

 

+

Constraints:

+ +
    +
  • 1 <= actions.length <= 10
  • +
  • values.length === actions.length
  • +
  • All test cases are valid, e.g. you don't need to handle scenarios when unsubscribing from a non-existing subscription.
  • +
  • There are only 4 different actions: EventEmitter, emit, subscribe, and unsubscribe.
  • +
  • The EventEmitter action doesn't take any arguments.
  • +
  • The emit action takes between either 1 or 2 arguments. The first argument is the name of the event we want to emit, and the 2nd argument is passed to the callback functions.
  • +
  • The subscribe action takes 2 arguments, where the first one is the event name and the second is the callback function.
  • +
  • The unsubscribe action takes one argument, which is the 0-indexed order of the subscription made before.
  • +
+
\ No newline at end of file diff --git a/2695-array-wrapper/2695-array-wrapper.js b/problems/2695-array-wrapper/2695-array-wrapper.js similarity index 100% rename from 2695-array-wrapper/2695-array-wrapper.js rename to problems/2695-array-wrapper/2695-array-wrapper.js diff --git a/2695-array-wrapper/NOTES.md b/problems/2695-array-wrapper/NOTES.md similarity index 100% rename from 2695-array-wrapper/NOTES.md rename to problems/2695-array-wrapper/NOTES.md diff --git a/problems/2695-array-wrapper/README.md b/problems/2695-array-wrapper/README.md new file mode 100644 index 000000000..0b05f1af2 --- /dev/null +++ b/problems/2695-array-wrapper/README.md @@ -0,0 +1,46 @@ +

2695. Array Wrapper

Easy


Create a class ArrayWrapper that accepts an array of integers in its constructor. This class should have two features:

+ +
    +
  • When two instances of this class are added together with the + operator, the resulting value is the sum of all the elements in both arrays.
  • +
  • When the String() function is called on the instance, it will return a comma separated string surrounded by brackets. For example, [1,2,3].
  • +
+ +

 

+

Example 1:

+ +
Input: nums = [[1,2],[3,4]], operation = "Add"
+Output: 10
+Explanation:
+const obj1 = new ArrayWrapper([1,2]);
+const obj2 = new ArrayWrapper([3,4]);
+obj1 + obj2; // 10
+
+ +

Example 2:

+ +
Input: nums = [[23,98,42,70]], operation = "String"
+Output: "[23,98,42,70]"
+Explanation:
+const obj = new ArrayWrapper([23,98,42,70]);
+String(obj); // "[23,98,42,70]"
+
+ +

Example 3:

+ +
Input: nums = [[],[]], operation = "Add"
+Output: 0
+Explanation:
+const obj1 = new ArrayWrapper([]);
+const obj2 = new ArrayWrapper([]);
+obj1 + obj2; // 0
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= nums.length <= 1000
  • +
  • 0 <= nums[i] <= 1000
  • +
  • Note: nums is the array passed to the constructor
  • +
+
\ No newline at end of file diff --git a/2703-return-length-of-arguments-passed/2703-return-length-of-arguments-passed.js b/problems/2703-return-length-of-arguments-passed/2703-return-length-of-arguments-passed.js similarity index 100% rename from 2703-return-length-of-arguments-passed/2703-return-length-of-arguments-passed.js rename to problems/2703-return-length-of-arguments-passed/2703-return-length-of-arguments-passed.js diff --git a/2703-return-length-of-arguments-passed/NOTES.md b/problems/2703-return-length-of-arguments-passed/NOTES.md similarity index 100% rename from 2703-return-length-of-arguments-passed/NOTES.md rename to problems/2703-return-length-of-arguments-passed/NOTES.md diff --git a/problems/2703-return-length-of-arguments-passed/README.md b/problems/2703-return-length-of-arguments-passed/README.md new file mode 100644 index 000000000..a2bfeffae --- /dev/null +++ b/problems/2703-return-length-of-arguments-passed/README.md @@ -0,0 +1,30 @@ +

2703. Return Length of Arguments Passed

Easy


Write a function argumentsLength that returns the count of arguments passed to it. +

 

+

Example 1:

+ +
Input: argsArr = [5]
+Output: 1
+Explanation:
+argumentsLength(5); // 1
+
+One value was passed to the function so it should return 1.
+
+ +

Example 2:

+ +
Input: argsArr = [{}, null, "3"]
+Output: 3
+Explanation: 
+argumentsLength({}, null, "3"); // 3
+
+Three values were passed to the function so it should return 3.
+
+ +

 

+

Constraints:

+ +
    +
  • argsArr is a valid JSON array
  • +
  • 0 <= argsArr.length <= 100
  • +
+
\ No newline at end of file diff --git a/2704-to-be-or-not-to-be/2704-to-be-or-not-to-be.js b/problems/2704-to-be-or-not-to-be/2704-to-be-or-not-to-be.js similarity index 100% rename from 2704-to-be-or-not-to-be/2704-to-be-or-not-to-be.js rename to problems/2704-to-be-or-not-to-be/2704-to-be-or-not-to-be.js diff --git a/2704-to-be-or-not-to-be/NOTES.md b/problems/2704-to-be-or-not-to-be/NOTES.md similarity index 100% rename from 2704-to-be-or-not-to-be/NOTES.md rename to problems/2704-to-be-or-not-to-be/NOTES.md diff --git a/problems/2704-to-be-or-not-to-be/README.md b/problems/2704-to-be-or-not-to-be/README.md new file mode 100644 index 000000000..347eb016a --- /dev/null +++ b/problems/2704-to-be-or-not-to-be/README.md @@ -0,0 +1,29 @@ +

2704. To Be Or Not To Be

Easy


Write a function expect that helps developers test their code. It should take in any value val and return an object with the following two functions.

+ +
    +
  • toBe(val) accepts another value and returns true if the two values === each other. If they are not equal, it should throw an error "Not Equal".
  • +
  • notToBe(val) accepts another value and returns true if the two values !== each other. If they are equal, it should throw an error "Equal".
  • +
+ +

 

+

Example 1:

+ +
Input: func = () => expect(5).toBe(5)
+Output: {"value": true}
+Explanation: 5 === 5 so this expression returns true.
+
+ +

Example 2:

+ +
Input: func = () => expect(5).toBe(null)
+Output: {"error": "Not Equal"}
+Explanation: 5 !== null so this expression throw the error "Not Equal".
+
+ +

Example 3:

+ +
Input: func = () => expect(5).notToBe(null)
+Output: {"value": true}
+Explanation: 5 !== null so this expression returns true.
+
+
\ No newline at end of file diff --git a/2705-compact-object/2705-compact-object.js b/problems/2705-compact-object/2705-compact-object.js similarity index 100% rename from 2705-compact-object/2705-compact-object.js rename to problems/2705-compact-object/2705-compact-object.js diff --git a/2705-compact-object/NOTES.md b/problems/2705-compact-object/NOTES.md similarity index 100% rename from 2705-compact-object/NOTES.md rename to problems/2705-compact-object/NOTES.md diff --git a/problems/2705-compact-object/README.md b/problems/2705-compact-object/README.md new file mode 100644 index 000000000..f3e798d18 --- /dev/null +++ b/problems/2705-compact-object/README.md @@ -0,0 +1,33 @@ +

2705. Compact Object

Medium


Given an object or array obj, return a compact object. A compact object is the same as the original object, except with keys containing falsy values removed. This operation applies to the object and any nested objects. Arrays are considered objects where the indices are keys. A value is considered falsy when Boolean(value) returns false.

+ +

You may assume the obj is the output of JSON.parse. In other words, it is valid JSON.

+ +

 

+

Example 1:

+ +
Input: obj = [null, 0, false, 1]
+Output: [1]
+Explanation: All falsy values have been removed from the array.
+
+ +

Example 2:

+ +
Input: obj = {"a": null, "b": [false, 1]}
+Output: {"b": [1]}
+Explanation: obj["a"] and obj["b"][0] had falsy values and were removed.
+ +

Example 3:

+ +
Input: obj = [null, 0, 5, [0], [false, 16]]
+Output: [5, [], [16]]
+Explanation: obj[0], obj[1], obj[3][0], and obj[4][0] were falsy and removed.
+
+ +

 

+

Constraints:

+ +
    +
  • obj is a valid JSON object
  • +
  • 2 <= JSON.stringify(obj).length <= 106
  • +
+
\ No newline at end of file diff --git a/2706-buy-two-chocolates/2706-buy-two-chocolates.py b/problems/2706-buy-two-chocolates/2706-buy-two-chocolates.py similarity index 100% rename from 2706-buy-two-chocolates/2706-buy-two-chocolates.py rename to problems/2706-buy-two-chocolates/2706-buy-two-chocolates.py diff --git a/2706-buy-two-chocolates/NOTES.md b/problems/2706-buy-two-chocolates/NOTES.md similarity index 100% rename from 2706-buy-two-chocolates/NOTES.md rename to problems/2706-buy-two-chocolates/NOTES.md diff --git a/problems/2706-buy-two-chocolates/README.md b/problems/2706-buy-two-chocolates/README.md new file mode 100644 index 000000000..c6497e3fb --- /dev/null +++ b/problems/2706-buy-two-chocolates/README.md @@ -0,0 +1,30 @@ +

2706. Buy Two Chocolates

Easy


You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money.

+ +

You must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize the sum of the prices of the two chocolates you buy.

+ +

Return the amount of money you will have leftover after buying the two chocolates. If there is no way for you to buy two chocolates without ending up in debt, return money. Note that the leftover must be non-negative.

+ +

 

+

Example 1:

+ +
Input: prices = [1,2,2], money = 3
+Output: 0
+Explanation: Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0.
+
+ +

Example 2:

+ +
Input: prices = [3,2,3], money = 3
+Output: 3
+Explanation: You cannot buy 2 chocolates without going in debt, so we return 3.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= prices.length <= 50
  • +
  • 1 <= prices[i] <= 100
  • +
  • 1 <= money <= 100
  • +
+
\ No newline at end of file diff --git a/2707-extra-characters-in-a-string/2707-extra-characters-in-a-string.py b/problems/2707-extra-characters-in-a-string/2707-extra-characters-in-a-string.py similarity index 100% rename from 2707-extra-characters-in-a-string/2707-extra-characters-in-a-string.py rename to problems/2707-extra-characters-in-a-string/2707-extra-characters-in-a-string.py diff --git a/problems/2707-extra-characters-in-a-string/README.md b/problems/2707-extra-characters-in-a-string/README.md new file mode 100644 index 000000000..1f148b755 --- /dev/null +++ b/problems/2707-extra-characters-in-a-string/README.md @@ -0,0 +1,31 @@ +

2707. Extra Characters in a String

Medium


You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.

+ +

Return the minimum number of extra characters left over if you break up s optimally.

+ +

 

+

Example 1:

+ +
Input: s = "leetscode", dictionary = ["leet","code","leetcode"]
+Output: 1
+Explanation: We can break s in two substrings: "leet" from index 0 to 3 and "code" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.
+
+
+ +

Example 2:

+ +
Input: s = "sayhelloworld", dictionary = ["hello","world"]
+Output: 3
+Explanation: We can break s in two substrings: "hello" from index 3 to 7 and "world" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 50
  • +
  • 1 <= dictionary.length <= 50
  • +
  • 1 <= dictionary[i].length <= 50
  • +
  • dictionary[i] and s consists of only lowercase English letters
  • +
  • dictionary contains distinct words
  • +
+
\ No newline at end of file diff --git a/2709-greatest-common-divisor-traversal/2709-greatest-common-divisor-traversal.py b/problems/2709-greatest-common-divisor-traversal/2709-greatest-common-divisor-traversal.py similarity index 100% rename from 2709-greatest-common-divisor-traversal/2709-greatest-common-divisor-traversal.py rename to problems/2709-greatest-common-divisor-traversal/2709-greatest-common-divisor-traversal.py diff --git a/2709-greatest-common-divisor-traversal/NOTES.md b/problems/2709-greatest-common-divisor-traversal/NOTES.md similarity index 100% rename from 2709-greatest-common-divisor-traversal/NOTES.md rename to problems/2709-greatest-common-divisor-traversal/NOTES.md diff --git a/problems/2709-greatest-common-divisor-traversal/README.md b/problems/2709-greatest-common-divisor-traversal/README.md new file mode 100644 index 000000000..b66d140a1 --- /dev/null +++ b/problems/2709-greatest-common-divisor-traversal/README.md @@ -0,0 +1,38 @@ +

2709. Greatest Common Divisor Traversal

Hard


You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.

+ +

Your task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals that can take us from i to j.

+ +

Return true if it is possible to traverse between all such pairs of indices, or false otherwise.

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,6]
+Output: true
+Explanation: In this example, there are 3 possible pairs of indices: (0, 1), (0, 2), and (1, 2).
+To go from index 0 to index 1, we can use the sequence of traversals 0 -> 2 -> 1, where we move from index 0 to index 2 because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1, and then move from index 2 to index 1 because gcd(nums[2], nums[1]) = gcd(6, 3) = 3 > 1.
+To go from index 0 to index 2, we can just go directly because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1. Likewise, to go from index 1 to index 2, we can just go directly because gcd(nums[1], nums[2]) = gcd(3, 6) = 3 > 1.
+
+ +

Example 2:

+ +
Input: nums = [3,9,5]
+Output: false
+Explanation: No sequence of traversals can take us from index 0 to index 2 in this example. So, we return false.
+
+ +

Example 3:

+ +
Input: nums = [4,3,12,8]
+Output: true
+Explanation: There are 6 possible pairs of indices to traverse between: (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), and (2, 3). A valid sequence of traversals exists for each pair, so we return true.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 105
  • +
+
\ No newline at end of file diff --git a/2715-execute-cancellable-function-with-delay/2715-execute-cancellable-function-with-delay.js b/problems/2715-execute-cancellable-function-with-delay/2715-execute-cancellable-function-with-delay.js similarity index 100% rename from 2715-execute-cancellable-function-with-delay/2715-execute-cancellable-function-with-delay.js rename to problems/2715-execute-cancellable-function-with-delay/2715-execute-cancellable-function-with-delay.js diff --git a/2715-execute-cancellable-function-with-delay/NOTES.md b/problems/2715-execute-cancellable-function-with-delay/NOTES.md similarity index 100% rename from 2715-execute-cancellable-function-with-delay/NOTES.md rename to problems/2715-execute-cancellable-function-with-delay/NOTES.md diff --git a/problems/2715-execute-cancellable-function-with-delay/README.md b/problems/2715-execute-cancellable-function-with-delay/README.md new file mode 100644 index 000000000..e526cc681 --- /dev/null +++ b/problems/2715-execute-cancellable-function-with-delay/README.md @@ -0,0 +1,52 @@ +

2715. Execute Cancellable Function With Delay

Easy


Given a function fn, an array or arguments args, and a timeout t in milliseconds, return a cancel function cancelFn.

+ +

After a delay of tfn should be called with args passed as parameters unless cancelFn was called first. In that case, fn should never be called.

+ +

 

+

Example 1:

+ +
Input: fn = (x) => x * 5, args = [2], t = 20
+Output: [{"time": 20, "returned": 10}]
+Explanation: 
+const cancelTime = 50
+const cancel = cancellable((x) => x * 5, [2], 20); // fn(2) called at t=20ms
+setTimeout(cancel, cancelTime);
+
+The cancellation was scheduled to occur after a delay of cancelTime (50ms), which happened after the execution of fn(2) at 20ms.
+
+ +

Example 2:

+ +
Input: fn = (x) => x**2, args = [2], t = 100
+Output: []
+Explanation: 
+const cancelTime = 50 
+const cancel = cancellable((x) => x**2, [2], 100); // fn(2) not called
+setTimeout(cancel, cancelTime);
+
+The cancellation was scheduled to occur after a delay of cancelTime (50ms), which happened before the execution of fn(2) at 100ms, resulting in fn(2) never being called.
+
+ +

Example 3:

+ +
Input: fn = (x1, x2) => x1 * x2, args = [2,4], t = 30
+Output: [{"time": 30, "returned": 8}]
+Explanation:
+const cancelTime = 100
+const cancel = cancellable((x1, x2) => x1 * x2, [2,4], 30); // fn(2,4) called at t=30ms
+setTimeout(cancel, cancelTime);
+
+The cancellation was scheduled to occur after a delay of cancelTime (100ms), which happened after the execution of fn(2,4) at 30ms.
+
+ +

 

+

Constraints:

+ +
    +
  • fn is a function
  • +
  • args is a valid JSON array
  • +
  • 1 <= args.length <= 10
  • +
  • 20 <= t <= 1000
  • +
  • 10 <= cancelT <= 1000
  • +
+
\ No newline at end of file diff --git a/2721-execute-asynchronous-functions-in-parallel/2721-execute-asynchronous-functions-in-parallel.js b/problems/2721-execute-asynchronous-functions-in-parallel/2721-execute-asynchronous-functions-in-parallel.js similarity index 100% rename from 2721-execute-asynchronous-functions-in-parallel/2721-execute-asynchronous-functions-in-parallel.js rename to problems/2721-execute-asynchronous-functions-in-parallel/2721-execute-asynchronous-functions-in-parallel.js diff --git a/2721-execute-asynchronous-functions-in-parallel/NOTES.md b/problems/2721-execute-asynchronous-functions-in-parallel/NOTES.md similarity index 100% rename from 2721-execute-asynchronous-functions-in-parallel/NOTES.md rename to problems/2721-execute-asynchronous-functions-in-parallel/NOTES.md diff --git a/problems/2721-execute-asynchronous-functions-in-parallel/README.md b/problems/2721-execute-asynchronous-functions-in-parallel/README.md new file mode 100644 index 000000000..e35b51f27 --- /dev/null +++ b/problems/2721-execute-asynchronous-functions-in-parallel/README.md @@ -0,0 +1,58 @@ +

2721. Execute Asynchronous Functions in Parallel

Medium


Given an array of asynchronous functions functions, return a new promise promise. Each function in the array accepts no arguments and returns a promise.

+ +

promise resolves:

+ +
    +
  • When all the promises returned from functions were resolved successfully. The resolved value of promise should be an array of all the resolved values of promises in the same order as they were in the functions.
  • +
+ +

promise rejects:

+ +
    +
  • When any of the promises returned from functions were rejected. promise should also reject with the reason of the first rejection.
  • +
+ +

Please solve it without using the built-in Promise.all function.

+ +

 

+

Example 1:

+ +
Input: functions = [
+  () => new Promise(resolve => setTimeout(() => resolve(5), 200))
+]
+Output: {"t": 200, "resolved": [5]}
+Explanation: 
+promiseAll(functions).then(console.log); // [5]
+
+The single function was resolved at 200ms with a value of 5.
+
+ +

Example 2:

+ +
Input: functions = [
+    () => new Promise(resolve => setTimeout(() => resolve(1), 200)), 
+    () => new Promise((resolve, reject) => setTimeout(() => reject("Error"), 100))
+]
+Output: {"t": 100, "rejected": "Error"}
+Explanation: Since one of the promises rejected, the returned promise also rejected with the same error at the same time.
+
+ +

Example 3:

+ +
Input: functions = [
+    () => new Promise(resolve => setTimeout(() => resolve(4), 50)), 
+    () => new Promise(resolve => setTimeout(() => resolve(10), 150)), 
+    () => new Promise(resolve => setTimeout(() => resolve(16), 100))
+]
+Output: {"t": 150, "resolved": [4, 10, 16]}
+Explanation: All the promises resolved with a value. The returned promise resolved when the last promise resolved.
+
+ +

 

+

Constraints:

+ +
    +
  • functions is an array of functions that returns promises
  • +
  • 1 <= functions.length <= 10
  • +
+
\ No newline at end of file diff --git a/2722-join-two-arrays-by-id/2722-join-two-arrays-by-id.js b/problems/2722-join-two-arrays-by-id/2722-join-two-arrays-by-id.js similarity index 100% rename from 2722-join-two-arrays-by-id/2722-join-two-arrays-by-id.js rename to problems/2722-join-two-arrays-by-id/2722-join-two-arrays-by-id.js diff --git a/2722-join-two-arrays-by-id/NOTES.md b/problems/2722-join-two-arrays-by-id/NOTES.md similarity index 100% rename from 2722-join-two-arrays-by-id/NOTES.md rename to problems/2722-join-two-arrays-by-id/NOTES.md diff --git a/problems/2722-join-two-arrays-by-id/README.md b/problems/2722-join-two-arrays-by-id/README.md new file mode 100644 index 000000000..d76f4821c --- /dev/null +++ b/problems/2722-join-two-arrays-by-id/README.md @@ -0,0 +1,75 @@ +

2722. Join Two Arrays by ID

Medium


Given two arrays arr1 and arr2, return a new array joinedArray. All the objects in each of the two inputs arrays will contain an id field that has an integer value. joinedArray is an array formed by merging arr1 and arr2 based on their id key. The length of joinedArray should be the length of unique values of id. The returned array should be sorted in ascending order based on the id key.

+ +

If a given id exists in one array but not the other, the single object with that id should be included in the result array without modification.

+ +

If two objects share an id, their properties should be merged into a single object:

+ +
    +
  • If a key only exists in one object, that single key-value pair should be included in the object.
  • +
  • If a key is included in both objects, the value in the object from arr2 should override the value from arr1.
  • +
+ +

 

+

Example 1:

+ +
Input: 
+arr1 = [
+    {"id": 1, "x": 1},
+    {"id": 2, "x": 9}
+], 
+arr2 = [
+    {"id": 3, "x": 5}
+]
+Output: 
+[
+    {"id": 1, "x": 1},
+    {"id": 2, "x": 9},
+    {"id": 3, "x": 5}
+]
+Explanation: There are no duplicate ids so arr1 is simply concatenated with arr2.
+
+ +

Example 2:

+ +
Input: 
+arr1 = [
+    {"id": 1, "x": 2, "y": 3},
+    {"id": 2, "x": 3, "y": 6}
+], 
+arr2 = [
+    {"id": 2, "x": 10, "y": 20},
+    {"id": 3, "x": 0, "y": 0}
+]
+Output: 
+[
+    {"id": 1, "x": 2, "y": 3},
+    {"id": 2, "x": 10, "y": 20},
+    {"id": 3, "x": 0, "y": 0}
+]
+Explanation: The two objects with id=1 and id=3 are included in the result array without modifiction. The two objects with id=2 are merged together. The keys from arr2 override the values in arr1.
+
+ +

Example 3:

+ +
Input: 
+arr1 = [
+    {"id": 1, "b": {"b": 94},"v": [4, 3], "y": 48}
+]
+arr2 = [
+    {"id": 1, "b": {"c": 84}, "v": [1, 3]}
+]
+Output: [
+    {"id": 1, "b": {"c": 84}, "v": [1, 3], "y": 48}
+]
+Explanation: The two objects with id=1 are merged together. For the keys "b" and "v" the values from arr2 are used. Since the key "y" only exists in arr1, that value is taken form arr1.
+ +

 

+

Constraints:

+ +
    +
  • arr1 and arr2 are valid JSON arrays
  • +
  • Each object in arr1 and arr2 has a unique integer id key
  • +
  • 2 <= JSON.stringify(arr1).length <= 106
  • +
  • 2 <= JSON.stringify(arr2).length <= 106
  • +
+
\ No newline at end of file diff --git a/2723-add-two-promises/2723-add-two-promises.js b/problems/2723-add-two-promises/2723-add-two-promises.js similarity index 100% rename from 2723-add-two-promises/2723-add-two-promises.js rename to problems/2723-add-two-promises/2723-add-two-promises.js diff --git a/2723-add-two-promises/NOTES.md b/problems/2723-add-two-promises/NOTES.md similarity index 100% rename from 2723-add-two-promises/NOTES.md rename to problems/2723-add-two-promises/NOTES.md diff --git a/problems/2723-add-two-promises/README.md b/problems/2723-add-two-promises/README.md new file mode 100644 index 000000000..9c6b2e383 --- /dev/null +++ b/problems/2723-add-two-promises/README.md @@ -0,0 +1,27 @@ +

2723. Add Two Promises

Easy


Given two promises promise1 and promise2, return a new promise. promise1 and promise2 will both resolve with a number. The returned promise should resolve with the sum of the two numbers. +

 

+

Example 1:

+ +
Input: 
+promise1 = new Promise(resolve => setTimeout(() => resolve(2), 20)), 
+promise2 = new Promise(resolve => setTimeout(() => resolve(5), 60))
+Output: 7
+Explanation: The two input promises resolve with the values of 2 and 5 respectively. The returned promise should resolve with a value of 2 + 5 = 7. The time the returned promise resolves is not judged for this problem.
+
+ +

Example 2:

+ +
Input: 
+promise1 = new Promise(resolve => setTimeout(() => resolve(10), 50)), 
+promise2 = new Promise(resolve => setTimeout(() => resolve(-12), 30))
+Output: -2
+Explanation: The two input promises resolve with the values of 10 and -12 respectively. The returned promise should resolve with a value of 10 + -12 = -2.
+
+ +

 

+

Constraints:

+ +
    +
  • promise1 and promise2 are promises that resolve with a number
  • +
+
\ No newline at end of file diff --git a/2724-sort-by/2724-sort-by.js b/problems/2724-sort-by/2724-sort-by.js similarity index 100% rename from 2724-sort-by/2724-sort-by.js rename to problems/2724-sort-by/2724-sort-by.js diff --git a/2724-sort-by/NOTES.md b/problems/2724-sort-by/NOTES.md similarity index 100% rename from 2724-sort-by/NOTES.md rename to problems/2724-sort-by/NOTES.md diff --git a/problems/2724-sort-by/README.md b/problems/2724-sort-by/README.md new file mode 100644 index 000000000..3fb3c2327 --- /dev/null +++ b/problems/2724-sort-by/README.md @@ -0,0 +1,35 @@ +

2724. Sort By

Easy


Given an array arr and a function fn, return a sorted array sortedArr. You can assume fn only returns numbers and those numbers determine the sort order of sortedArr. sortedArray must be sorted in ascending order by fn output.

+ +

You may assume that fn will never duplicate numbers for a given array.

+ +

 

+

Example 1:

+ +
Input: arr = [5, 4, 1, 2, 3], fn = (x) => x
+Output: [1, 2, 3, 4, 5]
+Explanation: fn simply returns the number passed to it so the array is sorted in ascending order.
+
+ +

Example 2:

+ +
Input: arr = [{"x": 1}, {"x": 0}, {"x": -1}], fn = (d) => d.x
+Output: [{"x": -1}, {"x": 0}, {"x": 1}]
+Explanation: fn returns the value for the "x" key. So the array is sorted based on that value.
+
+ +

Example 3:

+ +
Input: arr = [[3, 4], [5, 2], [10, 1]], fn = (x) => x[1]
+Output: [[10, 1], [5, 2], [3, 4]]
+Explanation: arr is sorted in ascending order by number at index=1. 
+
+ +

 

+

Constraints:

+ +
    +
  • arr is a valid JSON array
  • +
  • fn is a function that returns a number
  • +
  • 1 <= arr.length <= 5 * 105
  • +
+
\ No newline at end of file diff --git a/2725-interval-cancellation/2725-interval-cancellation.js b/problems/2725-interval-cancellation/2725-interval-cancellation.js similarity index 100% rename from 2725-interval-cancellation/2725-interval-cancellation.js rename to problems/2725-interval-cancellation/2725-interval-cancellation.js diff --git a/2725-interval-cancellation/NOTES.md b/problems/2725-interval-cancellation/NOTES.md similarity index 100% rename from 2725-interval-cancellation/NOTES.md rename to problems/2725-interval-cancellation/NOTES.md diff --git a/problems/2725-interval-cancellation/README.md b/problems/2725-interval-cancellation/README.md new file mode 100644 index 000000000..e50cb3c43 --- /dev/null +++ b/problems/2725-interval-cancellation/README.md @@ -0,0 +1,91 @@ +

2725. Interval Cancellation

Easy


Given a function fn, an array of arguments args, and an interval time t, return a cancel function cancelFn. The function fn should be called with args immediately and then called again every t milliseconds until cancelFn is called.

+ +

 

+

Example 1:

+ +
Input: fn = (x) => x * 2, args = [4], t = 20
+Output: 
+[
+   {"time": 0, "returned": 8},
+   {"time": 20, "returned": 8},
+   {"time": 40, "returned": 8},
+   {"time": 60, "returned": 8},
+   {"time": 80, "returned": 8},
+   {"time": 100, "returned": 8}
+]
+Explanation: 
+const cancelT = 110
+const cancel = cancellable(x => x * 2, [4], 20);
+setTimeout(cancel, cancelT);
+
+Every 20ms, fn(4) is called. Until t=110ms, then it is cancelled.
+1st fn call is at 0ms. fn(4) returns 8.
+2nd fn call is at 20ms. fn(4) returns 8.
+3rd fn call is at 40ms. fn(4) returns 8.
+4th fn call is at 60ms. fn(4) returns 8.
+5th fn call is at 80ms. fn(4) returns 8.
+6th fn call is at 100ms. fn(4) returns 8.
+Cancelled at 110ms
+
+ +

Example 2:

+ +
Input: fn = (x1, x2) => (x1 * x2), args = [2, 5], t = 25
+Output: 
+[
+   {"time": 0, "returned": 10},
+   {"time": 25, "returned": 10},
+   {"time": 50, "returned": 10},
+   {"time": 75, "returned": 10},
+   {"time": 100, "returned": 10},
+   {"time": 125, "returned": 10}
+]
+Explanation: 
+const cancelT = 140
+const cancel = cancellable((x1, x2) => (x1 * x2), [2, 5], 25); 
+setTimeout(cancel, cancelT);
+
+Every 25ms, fn(2, 5) is called. Until t=140ms, then it is cancelled.
+1st fn call is at 0ms 
+2nd fn call is at 25ms 
+3rd fn call is at 50ms 
+4th fn call is at 75ms 
+5th fn call is at 100ms 
+6th fn call is at 125ms
+Cancelled at 140ms
+
+ +

Example 3:

+ +
Input: fn = (x1, x2, x3) => (x1 + x2 + x3), args = [5, 1, 3], t = 50
+Output: 
+[
+   {"time": 0, "returned": 9},
+   {"time": 50, "returned": 9},
+   {"time": 100, "returned": 9},
+   {"time": 150, "returned": 9}
+]
+Explanation: 
+const cancelT = 180
+const cancel = cancellable((x1, x2, x3) => (x1 + x2 + x3), [5, 1, 3], 50);
+setTimeout(cancel, cancelT);
+
+Every 50ms, fn(5, 1, 3) is called. Until t=180ms, then it is cancelled. 
+1st fn call is at 0ms
+2nd fn call is at 50ms
+3rd fn call is at 100ms
+4th fn call is at 150ms
+Cancelled at 180ms
+
+ +

 

+

Constraints:

+ +
    +
  • fn is a function
  • +
  • args is a valid JSON array
  • +
  • 1 <= args.length <= 10
  • +
  • 20 <= t <= 1000
  • +
  • 10 <= cancelT <= 1000
  • +
+
\ No newline at end of file diff --git a/2726-calculator-with-method-chaining/2726-calculator-with-method-chaining.js b/problems/2726-calculator-with-method-chaining/2726-calculator-with-method-chaining.js similarity index 100% rename from 2726-calculator-with-method-chaining/2726-calculator-with-method-chaining.js rename to problems/2726-calculator-with-method-chaining/2726-calculator-with-method-chaining.js diff --git a/2726-calculator-with-method-chaining/NOTES.md b/problems/2726-calculator-with-method-chaining/NOTES.md similarity index 100% rename from 2726-calculator-with-method-chaining/NOTES.md rename to problems/2726-calculator-with-method-chaining/NOTES.md diff --git a/problems/2726-calculator-with-method-chaining/README.md b/problems/2726-calculator-with-method-chaining/README.md new file mode 100644 index 000000000..5eb2d7577 --- /dev/null +++ b/problems/2726-calculator-with-method-chaining/README.md @@ -0,0 +1,53 @@ +

2726. Calculator with Method Chaining

Easy


Design a Calculator class. The class should provide the mathematical operations of addition, subtraction, multiplication, division, and exponentiation. It should also allow consecutive operations to be performed using method chaining. The Calculator class constructor should accept a number which serves as the initial value of result.

+ +

Your Calculator class should have the following methods:

+ +
    +
  • add - This method adds the given number value to the result and returns the updated Calculator.
  • +
  • subtract - This method subtracts the given number value from the result and returns the updated Calculator.
  • +
  • multiply - This method multiplies the result  by the given number value and returns the updated Calculator.
  • +
  • divide - This method divides the result by the given number value and returns the updated Calculator. If the passed value is 0, an error "Division by zero is not allowed" should be thrown.
  • +
  • power - This method raises the result to the power of the given number value and returns the updated Calculator.
  • +
  • getResult - This method returns the result.
  • +
+ +

Solutions within 10-5 of the actual result are considered correct.

+ +

 

+

Example 1:

+ +
Input: actions = ["Calculator", "add", "subtract", "getResult"], values = [10, 5, 7]
+Output: 8
+Explanation: 
+new Calculator(10).add(5).subtract(7).getResult() // 10 + 5 - 7 = 8
+
+ +

Example 2:

+ +
Input: actions = ["Calculator", "multiply", "power", "getResult"], values = [2, 5, 2]
+Output: 100
+Explanation: 
+new Calculator(2).multiply(5).power(2).getResult() // (2 * 5) ^ 2 = 100
+
+ +

Example 3:

+ +
Input: actions = ["Calculator", "divide", "getResult"], values = [20, 0]
+Output: "Division by zero is not allowed"
+Explanation: 
+new Calculator(20).divide(0).getResult() // 20 / 0 
+
+The error should be thrown because we cannot divide by zero.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= actions.length <= 2 * 104
  • +
  • 1 <= values.length <= 2 * 104 - 1
  • +
  • actions[i] is one of "Calculator", "add", "subtract", "multiply", "divide", "power", and "getResult"
  • +
  • Last action is always "getResult"
  • +
  • values is a JSON array of numbers
  • +
+
\ No newline at end of file diff --git a/2727-is-object-empty/2727-is-object-empty.js b/problems/2727-is-object-empty/2727-is-object-empty.js similarity index 100% rename from 2727-is-object-empty/2727-is-object-empty.js rename to problems/2727-is-object-empty/2727-is-object-empty.js diff --git a/2727-is-object-empty/NOTES.md b/problems/2727-is-object-empty/NOTES.md similarity index 100% rename from 2727-is-object-empty/NOTES.md rename to problems/2727-is-object-empty/NOTES.md diff --git a/problems/2727-is-object-empty/README.md b/problems/2727-is-object-empty/README.md new file mode 100644 index 000000000..fefb69ad3 --- /dev/null +++ b/problems/2727-is-object-empty/README.md @@ -0,0 +1,40 @@ +

2727. Is Object Empty

Easy


Given an object or an array, return if it is empty.

+ +
    +
  • An empty object contains no key-value pairs.
  • +
  • An empty array contains no elements.
  • +
+ +

You may assume the object or array is the output of JSON.parse.

+ +

 

+

Example 1:

+ +
Input: obj = {"x": 5, "y": 42}
+Output: false
+Explanation: The object has 2 key-value pairs so it is not empty.
+
+ +

Example 2:

+ +
Input: obj = {}
+Output: true
+Explanation: The object doesn't have any key-value pairs so it is empty.
+
+ +

Example 3:

+ +
Input: obj = [null, false, 0]
+Output: false
+Explanation: The array has 3 elements so it is not empty.
+
+ +

 

+

Constraints:

+ +
    +
  •  2 <= JSON.stringify(obj).length <= 105
  • +
+ +

 

+Can you solve it in O(1) time?
\ No newline at end of file diff --git a/2742-painting-the-walls/2742-painting-the-walls.py b/problems/2742-painting-the-walls/2742-painting-the-walls.py similarity index 100% rename from 2742-painting-the-walls/2742-painting-the-walls.py rename to problems/2742-painting-the-walls/2742-painting-the-walls.py diff --git a/2742-painting-the-walls/NOTES.md b/problems/2742-painting-the-walls/NOTES.md similarity index 100% rename from 2742-painting-the-walls/NOTES.md rename to problems/2742-painting-the-walls/NOTES.md diff --git a/problems/2742-painting-the-walls/README.md b/problems/2742-painting-the-walls/README.md new file mode 100644 index 000000000..cf18a4cbf --- /dev/null +++ b/problems/2742-painting-the-walls/README.md @@ -0,0 +1,34 @@ +

2742. Painting the Walls

Hard


You are given two 0-indexed integer arrays, cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available:

+ +
    +
  • A paid painter that paints the ith wall in time[i] units of time and takes cost[i] units of money.
  • +
  • A free painter that paints any wall in 1 unit of time at a cost of 0. But the free painter can only be used if the paid painter is already occupied.
  • +
+ +

Return the minimum amount of money required to paint the n walls.

+ +

 

+

Example 1:

+ +
Input: cost = [1,2,3,2], time = [1,2,3,2]
+Output: 3
+Explanation: The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.
+
+ +

Example 2:

+ +
Input: cost = [2,3,4,2], time = [1,1,1,1]
+Output: 4
+Explanation: The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= cost.length <= 500
  • +
  • cost.length == time.length
  • +
  • 1 <= cost[i] <= 106
  • +
  • 1 <= time[i] <= 500
  • +
+
\ No newline at end of file diff --git a/2743-count-substrings-without-repeating-character/2743-count-substrings-without-repeating-character.py b/problems/2743-count-substrings-without-repeating-character/2743-count-substrings-without-repeating-character.py similarity index 100% rename from 2743-count-substrings-without-repeating-character/2743-count-substrings-without-repeating-character.py rename to problems/2743-count-substrings-without-repeating-character/2743-count-substrings-without-repeating-character.py diff --git a/2743-count-substrings-without-repeating-character/NOTES.md b/problems/2743-count-substrings-without-repeating-character/NOTES.md similarity index 100% rename from 2743-count-substrings-without-repeating-character/NOTES.md rename to problems/2743-count-substrings-without-repeating-character/NOTES.md diff --git a/problems/2743-count-substrings-without-repeating-character/README.md b/problems/2743-count-substrings-without-repeating-character/README.md new file mode 100644 index 000000000..6d1af8316 --- /dev/null +++ b/problems/2743-count-substrings-without-repeating-character/README.md @@ -0,0 +1,38 @@ +

2743. Count Substrings Without Repeating Character

Medium


You are given a string s consisting only of lowercase English letters. We call a substring special if it contains no character which has occurred at least twice (in other words, it does not contain a repeating character). Your task is to count the number of special substrings. For example, in the string "pop", the substring "po" is a special substring, however, "pop" is not special (since 'p' has occurred twice).

+ +

Return the number of special substrings.

+ +

A substring is a contiguous sequence of characters within a string. For example, "abc" is a substring of "abcd", but "acd" is not.

+ +

 

+

Example 1:

+ +
Input: s = "abcd"
+Output: 10
+Explanation: Since each character occurs once, every substring is a special substring. We have 4 substrings of length one, 3 of length two, 2 of length three, and 1 substring of length four. So overall there are 4 + 3 + 2 + 1 = 10 special substrings.
+
+ +

Example 2:

+ +
Input: s = "ooo"
+Output: 3
+Explanation: Any substring with a length of at least two contains a repeating character. So we have to count the number of substrings of length one, which is 3.
+
+ +

Example 3:

+ +
Input: s = "abab"
+Output: 7
+Explanation: Special substrings are as follows (sorted by their start positions):
+Special substrings of length 1: "a", "b", "a", "b"
+Special substrings of length 2: "ab", "ba", "ab"
+And it can be shown that there are no special substrings with a length of at least three. So the answer would be 4 + 3 = 7.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s consists of lowercase English letters
  • +
+
\ No newline at end of file diff --git a/2751-robot-collisions/2751-robot-collisions.py b/problems/2751-robot-collisions/2751-robot-collisions.py similarity index 100% rename from 2751-robot-collisions/2751-robot-collisions.py rename to problems/2751-robot-collisions/2751-robot-collisions.py diff --git a/2751-robot-collisions/NOTES.md b/problems/2751-robot-collisions/NOTES.md similarity index 100% rename from 2751-robot-collisions/NOTES.md rename to problems/2751-robot-collisions/NOTES.md diff --git a/problems/2751-robot-collisions/README.md b/problems/2751-robot-collisions/README.md new file mode 100644 index 000000000..7e2147448 --- /dev/null +++ b/problems/2751-robot-collisions/README.md @@ -0,0 +1,53 @@ +

2751. Robot Collisions

Hard


There are n 1-indexed robots, each having a position on a line, health, and movement direction.

+ +

You are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left or 'R' for right). All integers in positions are unique.

+ +

All robots start moving on the line simultaneously at the same speed in their given directions. If two robots ever share the same position while moving, they will collide.

+ +

If two robots collide, the robot with lower health is removed from the line, and the health of the other robot decreases by one. The surviving robot continues in the same direction it was going. If both robots have the same health, they are both removed from the line.

+ +

Your task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final heath of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.

+ +

Return an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.

+ +

Note: The positions may be unsorted.

+ +
 
+ +

 

+

Example 1:

+ +

+ +
Input: positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = "RRRRR"
+Output: [2,17,9,15,10]
+Explanation: No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].
+
+ +

Example 2:

+ +

+ +
Input: positions = [3,5,2,6], healths = [10,10,15,12], directions = "RLRL"
+Output: [14]
+Explanation: There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].
+
+ +

Example 3:

+ +

+ +
Input: positions = [1,2,5,6], healths = [10,10,11,11], directions = "RLRL"
+Output: []
+Explanation: Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, [].
+ +

 

+

Constraints:

+ +
    +
  • 1 <= positions.length == healths.length == directions.length == n <= 105
  • +
  • 1 <= positions[i], healths[i] <= 109
  • +
  • directions[i] == 'L' or directions[i] == 'R'
  • +
  • All values in positions are distinct
  • +
+
\ No newline at end of file diff --git a/2762-continuous-subarrays/2762-continuous-subarrays.py b/problems/2762-continuous-subarrays/2762-continuous-subarrays.py similarity index 100% rename from 2762-continuous-subarrays/2762-continuous-subarrays.py rename to problems/2762-continuous-subarrays/2762-continuous-subarrays.py diff --git a/2762-continuous-subarrays/NOTES.md b/problems/2762-continuous-subarrays/NOTES.md similarity index 100% rename from 2762-continuous-subarrays/NOTES.md rename to problems/2762-continuous-subarrays/NOTES.md diff --git a/problems/2762-continuous-subarrays/README.md b/problems/2762-continuous-subarrays/README.md new file mode 100644 index 000000000..66023ae92 --- /dev/null +++ b/problems/2762-continuous-subarrays/README.md @@ -0,0 +1,45 @@ +

2762. Continuous Subarrays

Medium


You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:

+ +
    +
  • Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.
  • +
+ +

Return the total number of continuous subarrays.

+ +

A subarray is a contiguous non-empty sequence of elements within an array.

+ +

 

+

Example 1:

+ +
Input: nums = [5,4,2,4]
+Output: 8
+Explanation: 
+Continuous subarray of size 1: [5], [4], [2], [4].
+Continuous subarray of size 2: [5,4], [4,2], [2,4].
+Continuous subarray of size 3: [4,2,4].
+Thereare no subarrys of size 4.
+Total continuous subarrays = 4 + 3 + 1 = 8.
+It can be shown that there are no more continuous subarrays.
+
+ +

 

+ +

Example 2:

+ +
Input: nums = [1,2,3]
+Output: 6
+Explanation: 
+Continuous subarray of size 1: [1], [2], [3].
+Continuous subarray of size 2: [1,2], [2,3].
+Continuous subarray of size 3: [1,2,3].
+Total continuous subarrays = 3 + 2 + 1 = 6.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 109
  • +
+
\ No newline at end of file diff --git a/2778-sum-of-squares-of-special-elements/2778-sum-of-squares-of-special-elements.py b/problems/2778-sum-of-squares-of-special-elements/2778-sum-of-squares-of-special-elements.py similarity index 100% rename from 2778-sum-of-squares-of-special-elements/2778-sum-of-squares-of-special-elements.py rename to problems/2778-sum-of-squares-of-special-elements/2778-sum-of-squares-of-special-elements.py diff --git a/2778-sum-of-squares-of-special-elements/NOTES.md b/problems/2778-sum-of-squares-of-special-elements/NOTES.md similarity index 100% rename from 2778-sum-of-squares-of-special-elements/NOTES.md rename to problems/2778-sum-of-squares-of-special-elements/NOTES.md diff --git a/problems/2778-sum-of-squares-of-special-elements/README.md b/problems/2778-sum-of-squares-of-special-elements/README.md new file mode 100644 index 000000000..6bc603c48 --- /dev/null +++ b/problems/2778-sum-of-squares-of-special-elements/README.md @@ -0,0 +1,31 @@ +

2778. Sum of Squares of Special Elements

Easy


You are given a 1-indexed integer array nums of length n.

+ +

An element nums[i] of nums is called special if i divides n, i.e. n % i == 0.

+ +

Return the sum of the squares of all special elements of nums.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,3,4]
+Output: 21
+Explanation: There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4. 
+Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.  
+
+ +

Example 2:

+ +
Input: nums = [2,7,1,19,18,3]
+Output: 63
+Explanation: There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6. 
+Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63. 
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length == n <= 50
  • +
  • 1 <= nums[i] <= 50
  • +
+
\ No newline at end of file diff --git a/2784-check-if-array-is-good/2784-check-if-array-is-good.py b/problems/2784-check-if-array-is-good/2784-check-if-array-is-good.py similarity index 100% rename from 2784-check-if-array-is-good/2784-check-if-array-is-good.py rename to problems/2784-check-if-array-is-good/2784-check-if-array-is-good.py diff --git a/2784-check-if-array-is-good/NOTES.md b/problems/2784-check-if-array-is-good/NOTES.md similarity index 100% rename from 2784-check-if-array-is-good/NOTES.md rename to problems/2784-check-if-array-is-good/NOTES.md diff --git a/problems/2784-check-if-array-is-good/README.md b/problems/2784-check-if-array-is-good/README.md new file mode 100644 index 000000000..d26e29bea --- /dev/null +++ b/problems/2784-check-if-array-is-good/README.md @@ -0,0 +1,43 @@ +

2784. Check if Array is Good

Easy


You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].

+ +

base[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].

+ +

Return true if the given array is good, otherwise return false.

+ +

Note: A permutation of integers represents an arrangement of these numbers.

+ +

 

+

Example 1:

+ +
Input: nums = [2, 1, 3]
+Output: false
+Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.
+
+ +

Example 2:

+ +
Input: nums = [1, 3, 3, 2]
+Output: true
+Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.
+ +

Example 3:

+ +
Input: nums = [1, 1]
+Output: true
+Explanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.
+ +

Example 4:

+ +
Input: nums = [3, 4, 4, 1, 2, 1]
+Output: false
+Explanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 1 <= num[i] <= 200
  • +
+
\ No newline at end of file diff --git a/2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py b/problems/2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py similarity index 100% rename from 2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py rename to problems/2785-sort-vowels-in-a-string/2785-sort-vowels-in-a-string.py diff --git a/2785-sort-vowels-in-a-string/NOTES.md b/problems/2785-sort-vowels-in-a-string/NOTES.md similarity index 100% rename from 2785-sort-vowels-in-a-string/NOTES.md rename to problems/2785-sort-vowels-in-a-string/NOTES.md diff --git a/problems/2785-sort-vowels-in-a-string/README.md b/problems/2785-sort-vowels-in-a-string/README.md new file mode 100644 index 000000000..e66523485 --- /dev/null +++ b/problems/2785-sort-vowels-in-a-string/README.md @@ -0,0 +1,34 @@ +

2785. Sort Vowels in a String

Medium


Given a 0-indexed string s, permute s to get a new string t such that:

+ +
    +
  • All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].
  • +
  • The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].
  • +
+ +

Return the resulting string.

+ +

The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.

+ +

 

+

Example 1:

+ +
Input: s = "lEetcOde"
+Output: "lEOtcede"
+Explanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.
+
+ +

Example 2:

+ +
Input: s = "lYmpH"
+Output: "lYmpH"
+Explanation: There are no vowels in s (all characters in s are consonants), so we return "lYmpH".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s consists only of letters of the English alphabet in uppercase and lowercase.
  • +
+
\ No newline at end of file diff --git a/2788-split-strings-by-separator/2788-split-strings-by-separator.py b/problems/2788-split-strings-by-separator/2788-split-strings-by-separator.py similarity index 100% rename from 2788-split-strings-by-separator/2788-split-strings-by-separator.py rename to problems/2788-split-strings-by-separator/2788-split-strings-by-separator.py diff --git a/2788-split-strings-by-separator/NOTES.md b/problems/2788-split-strings-by-separator/NOTES.md similarity index 100% rename from 2788-split-strings-by-separator/NOTES.md rename to problems/2788-split-strings-by-separator/NOTES.md diff --git a/problems/2788-split-strings-by-separator/README.md b/problems/2788-split-strings-by-separator/README.md new file mode 100644 index 000000000..112411a2e --- /dev/null +++ b/problems/2788-split-strings-by-separator/README.md @@ -0,0 +1,53 @@ +

2788. Split Strings by Separator

Easy


Given an array of strings words and a character separator, split each string in words by separator.

+ +

Return an array of strings containing the new strings formed after the splits, excluding empty strings.

+ +

Notes

+ +
    +
  • separator is used to determine where the split should occur, but it is not included as part of the resulting strings.
  • +
  • A split may result in more than two strings.
  • +
  • The resulting strings must maintain the same order as they were initially given.
  • +
+ +

 

+

Example 1:

+ +
Input: words = ["one.two.three","four.five","six"], separator = "."
+Output: ["one","two","three","four","five","six"]
+Explanation: In this example we split as follows:
+
+"one.two.three" splits into "one", "two", "three"
+"four.five" splits into "four", "five"
+"six" splits into "six" 
+
+Hence, the resulting array is ["one","two","three","four","five","six"].
+ +

Example 2:

+ +
Input: words = ["$easy$","$problem$"], separator = "$"
+Output: ["easy","problem"]
+Explanation: In this example we split as follows: 
+
+"$easy$" splits into "easy" (excluding empty strings)
+"$problem$" splits into "problem" (excluding empty strings)
+
+Hence, the resulting array is ["easy","problem"].
+
+ +

Example 3:

+ +
Input: words = ["|||"], separator = "|"
+Output: []
+Explanation: In this example the resulting split of "|||" will contain only empty strings, so we return an empty array []. 
+ +

 

+

Constraints:

+ +
    +
  • 1 <= words.length <= 100
  • +
  • 1 <= words[i].length <= 20
  • +
  • characters in words[i] are either lowercase English letters or characters from the string ".,|$#@" (excluding the quotes)
  • +
  • separator is a character from the string ".,|$#@" (excluding the quotes)
  • +
+
\ No newline at end of file diff --git a/2789-largest-element-in-an-array-after-merge-operations/2789-largest-element-in-an-array-after-merge-operations.py b/problems/2789-largest-element-in-an-array-after-merge-operations/2789-largest-element-in-an-array-after-merge-operations.py similarity index 100% rename from 2789-largest-element-in-an-array-after-merge-operations/2789-largest-element-in-an-array-after-merge-operations.py rename to problems/2789-largest-element-in-an-array-after-merge-operations/2789-largest-element-in-an-array-after-merge-operations.py diff --git a/2789-largest-element-in-an-array-after-merge-operations/NOTES.md b/problems/2789-largest-element-in-an-array-after-merge-operations/NOTES.md similarity index 100% rename from 2789-largest-element-in-an-array-after-merge-operations/NOTES.md rename to problems/2789-largest-element-in-an-array-after-merge-operations/NOTES.md diff --git a/problems/2789-largest-element-in-an-array-after-merge-operations/README.md b/problems/2789-largest-element-in-an-array-after-merge-operations/README.md new file mode 100644 index 000000000..f5fb7353d --- /dev/null +++ b/problems/2789-largest-element-in-an-array-after-merge-operations/README.md @@ -0,0 +1,40 @@ +

2789. Largest Element in an Array after Merge Operations

Medium


You are given a 0-indexed array nums consisting of positive integers.

+ +

You can do the following operation on the array any number of times:

+ +
    +
  • Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.
  • +
+ +

Return the value of the largest element that you can possibly obtain in the final array.

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,7,9,3]
+Output: 21
+Explanation: We can apply the following operations on the array:
+- Choose i = 0. The resulting array will be nums = [5,7,9,3].
+- Choose i = 1. The resulting array will be nums = [5,16,3].
+- Choose i = 0. The resulting array will be nums = [21,3].
+The largest element in the final array is 21. It can be shown that we cannot obtain a larger element.
+
+ +

Example 2:

+ +
Input: nums = [5,3,3]
+Output: 11
+Explanation: We can do the following operations on the array:
+- Choose i = 1. The resulting array will be nums = [5,6].
+- Choose i = 0. The resulting array will be nums = [11].
+There is only one element in the final array, which is 11.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 106
  • +
+
\ No newline at end of file diff --git a/2798-number-of-employees-who-met-the-target/2798-number-of-employees-who-met-the-target.py b/problems/2798-number-of-employees-who-met-the-target/2798-number-of-employees-who-met-the-target.py similarity index 100% rename from 2798-number-of-employees-who-met-the-target/2798-number-of-employees-who-met-the-target.py rename to problems/2798-number-of-employees-who-met-the-target/2798-number-of-employees-who-met-the-target.py diff --git a/2798-number-of-employees-who-met-the-target/NOTES.md b/problems/2798-number-of-employees-who-met-the-target/NOTES.md similarity index 100% rename from 2798-number-of-employees-who-met-the-target/NOTES.md rename to problems/2798-number-of-employees-who-met-the-target/NOTES.md diff --git a/problems/2798-number-of-employees-who-met-the-target/README.md b/problems/2798-number-of-employees-who-met-the-target/README.md new file mode 100644 index 000000000..2493c83da --- /dev/null +++ b/problems/2798-number-of-employees-who-met-the-target/README.md @@ -0,0 +1,38 @@ +

2798. Number of Employees Who Met the Target

Easy


There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.

+ +

The company requires each employee to work for at least target hours.

+ +

You are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.

+ +

Return the integer denoting the number of employees who worked at least target hours.

+ +

 

+

Example 1:

+ +
Input: hours = [0,1,2,3,4], target = 2
+Output: 3
+Explanation: The company wants each employee to work for at least 2 hours.
+- Employee 0 worked for 0 hours and didn't meet the target.
+- Employee 1 worked for 1 hours and didn't meet the target.
+- Employee 2 worked for 2 hours and met the target.
+- Employee 3 worked for 3 hours and met the target.
+- Employee 4 worked for 4 hours and met the target.
+There are 3 employees who met the target.
+
+ +

Example 2:

+ +
Input: hours = [5,1,4,2,2], target = 6
+Output: 0
+Explanation: The company wants each employee to work for at least 6 hours.
+There are 0 employees who met the target.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n == hours.length <= 50
  • +
  • 0 <= hours[i], target <= 105
  • +
+
\ No newline at end of file diff --git a/2802-find-the-k-th-lucky-number/2802-find-the-k-th-lucky-number.py b/problems/2802-find-the-k-th-lucky-number/2802-find-the-k-th-lucky-number.py similarity index 100% rename from 2802-find-the-k-th-lucky-number/2802-find-the-k-th-lucky-number.py rename to problems/2802-find-the-k-th-lucky-number/2802-find-the-k-th-lucky-number.py diff --git a/2802-find-the-k-th-lucky-number/NOTES.md b/problems/2802-find-the-k-th-lucky-number/NOTES.md similarity index 100% rename from 2802-find-the-k-th-lucky-number/NOTES.md rename to problems/2802-find-the-k-th-lucky-number/NOTES.md diff --git a/problems/2802-find-the-k-th-lucky-number/README.md b/problems/2802-find-the-k-th-lucky-number/README.md new file mode 100644 index 000000000..9bf499270 --- /dev/null +++ b/problems/2802-find-the-k-th-lucky-number/README.md @@ -0,0 +1,33 @@ +

2802. Find The K-th Lucky Number

Medium


We know that 4 and 7 are lucky digits. Also, a number is called lucky if it contains only lucky digits.

+ +

You are given an integer k, return the kth lucky number represented as a string.

+ +

 

+

Example 1:

+ +
Input: k = 4
+Output: "47"
+Explanation: The first lucky number is 4, the second one is 7, the third one is 44 and the fourth one is 47.
+
+ +

Example 2:

+ +
Input: k = 10
+Output: "477"
+Explanation: Here are lucky numbers sorted in increasing order:
+4, 7, 44, 47, 74, 77, 444, 447, 474, 477. So the 10th lucky number is 477.
+ +

Example 3:

+ +
Input: k = 1000
+Output: "777747447"
+Explanation: It can be shown that the 1000th lucky number is 777747447.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= k <= 109
  • +
+
\ No newline at end of file diff --git a/2806-account-balance-after-rounded-purchase/2806-account-balance-after-rounded-purchase.py b/problems/2806-account-balance-after-rounded-purchase/2806-account-balance-after-rounded-purchase.py similarity index 100% rename from 2806-account-balance-after-rounded-purchase/2806-account-balance-after-rounded-purchase.py rename to problems/2806-account-balance-after-rounded-purchase/2806-account-balance-after-rounded-purchase.py diff --git a/2806-account-balance-after-rounded-purchase/NOTES.md b/problems/2806-account-balance-after-rounded-purchase/NOTES.md similarity index 100% rename from 2806-account-balance-after-rounded-purchase/NOTES.md rename to problems/2806-account-balance-after-rounded-purchase/NOTES.md diff --git a/problems/2806-account-balance-after-rounded-purchase/README.md b/problems/2806-account-balance-after-rounded-purchase/README.md new file mode 100644 index 000000000..34cc6fd74 --- /dev/null +++ b/problems/2806-account-balance-after-rounded-purchase/README.md @@ -0,0 +1,35 @@ +

2806. Account Balance After Rounded Purchase

Easy


Initially, you have a bank account balance of 100 dollars.

+ +

You are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars.

+ +

At the store where you will make the purchase, the purchase amount is rounded to the nearest multiple of 10. In other words, you pay a non-negative amount, roundedAmount, such that roundedAmount is a multiple of 10 and abs(roundedAmount - purchaseAmount) is minimized.

+ +

If there is more than one nearest multiple of 10, the largest multiple is chosen.

+ +

Return an integer denoting your account balance after making a purchase worth purchaseAmount dollars from the store.

+ +

Note: 0 is considered to be a multiple of 10 in this problem.

+ +

 

+

Example 1:

+ +
Input: purchaseAmount = 9
+Output: 90
+Explanation: In this example, the nearest multiple of 10 to 9 is 10. Hence, your account balance becomes 100 - 10 = 90.
+
+ +

Example 2:

+ +
Input: purchaseAmount = 15
+Output: 80
+Explanation: In this example, there are two nearest multiples of 10 to 15: 10 and 20. So, the larger multiple, 20, is chosen.
+Hence, your account balance becomes 100 - 20 = 80.
+
+ +

 

+

Constraints:

+ +
    +
  • 0 <= purchaseAmount <= 100
  • +
+
\ No newline at end of file diff --git a/2807-insert-greatest-common-divisors-in-linked-list/2807-insert-greatest-common-divisors-in-linked-list.py b/problems/2807-insert-greatest-common-divisors-in-linked-list/2807-insert-greatest-common-divisors-in-linked-list.py similarity index 100% rename from 2807-insert-greatest-common-divisors-in-linked-list/2807-insert-greatest-common-divisors-in-linked-list.py rename to problems/2807-insert-greatest-common-divisors-in-linked-list/2807-insert-greatest-common-divisors-in-linked-list.py diff --git a/2807-insert-greatest-common-divisors-in-linked-list/NOTES.md b/problems/2807-insert-greatest-common-divisors-in-linked-list/NOTES.md similarity index 100% rename from 2807-insert-greatest-common-divisors-in-linked-list/NOTES.md rename to problems/2807-insert-greatest-common-divisors-in-linked-list/NOTES.md diff --git a/problems/2807-insert-greatest-common-divisors-in-linked-list/README.md b/problems/2807-insert-greatest-common-divisors-in-linked-list/README.md new file mode 100644 index 000000000..7ff29adf9 --- /dev/null +++ b/problems/2807-insert-greatest-common-divisors-in-linked-list/README.md @@ -0,0 +1,36 @@ +

2807. Insert Greatest Common Divisors in Linked List

Medium


Given the head of a linked list head, in which each node contains an integer value.

+ +

Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.

+ +

Return the linked list after insertion.

+ +

The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.

+ +

 

+

Example 1:

+ +
Input: head = [18,6,10,3]
+Output: [18,6,6,2,10,1,3]
+Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).
+- We insert the greatest common divisor of 18 and 6 = 6 between the 1st and the 2nd nodes.
+- We insert the greatest common divisor of 6 and 10 = 2 between the 2nd and the 3rd nodes.
+- We insert the greatest common divisor of 10 and 3 = 1 between the 3rd and the 4th nodes.
+There are no more adjacent nodes, so we return the linked list.
+
+ +

Example 2:

+ +
Input: head = [7]
+Output: [7]
+Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes.
+There are no pairs of adjacent nodes, so we return the initial linked list.
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 5000].
  • +
  • 1 <= Node.val <= 1000
  • +
+
\ No newline at end of file diff --git a/2810-faulty-keyboard/2810-faulty-keyboard.py b/problems/2810-faulty-keyboard/2810-faulty-keyboard.py similarity index 100% rename from 2810-faulty-keyboard/2810-faulty-keyboard.py rename to problems/2810-faulty-keyboard/2810-faulty-keyboard.py diff --git a/2810-faulty-keyboard/NOTES.md b/problems/2810-faulty-keyboard/NOTES.md similarity index 100% rename from 2810-faulty-keyboard/NOTES.md rename to problems/2810-faulty-keyboard/NOTES.md diff --git a/problems/2810-faulty-keyboard/README.md b/problems/2810-faulty-keyboard/README.md new file mode 100644 index 000000000..16d683727 --- /dev/null +++ b/problems/2810-faulty-keyboard/README.md @@ -0,0 +1,45 @@ +

2810. Faulty Keyboard

Easy


Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.

+ +

You are given a 0-indexed string s, and you type each character of s using your faulty keyboard.

+ +

Return the final string that will be present on your laptop screen.

+ +

 

+

Example 1:

+ +
Input: s = "string"
+Output: "rtsng"
+Explanation: 
+After typing first character, the text on the screen is "s".
+After the second character, the text is "st". 
+After the third character, the text is "str".
+Since the fourth character is an 'i', the text gets reversed and becomes "rts".
+After the fifth character, the text is "rtsn". 
+After the sixth character, the text is "rtsng". 
+Therefore, we return "rtsng".
+
+ +

Example 2:

+ +
Input: s = "poiinter"
+Output: "ponter"
+Explanation: 
+After the first character, the text on the screen is "p".
+After the second character, the text is "po". 
+Since the third character you type is an 'i', the text gets reversed and becomes "op". 
+Since the fourth character you type is an 'i', the text gets reversed and becomes "po".
+After the fifth character, the text is "pon".
+After the sixth character, the text is "pont". 
+After the seventh character, the text is "ponte". 
+After the eighth character, the text is "ponter". 
+Therefore, we return "ponter".
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s consists of lowercase English letters.
  • +
  • s[0] != 'i'
  • +
+
\ No newline at end of file diff --git a/2811-check-if-it-is-possible-to-split-array/2811-check-if-it-is-possible-to-split-array.py b/problems/2811-check-if-it-is-possible-to-split-array/2811-check-if-it-is-possible-to-split-array.py similarity index 100% rename from 2811-check-if-it-is-possible-to-split-array/2811-check-if-it-is-possible-to-split-array.py rename to problems/2811-check-if-it-is-possible-to-split-array/2811-check-if-it-is-possible-to-split-array.py diff --git a/2811-check-if-it-is-possible-to-split-array/NOTES.md b/problems/2811-check-if-it-is-possible-to-split-array/NOTES.md similarity index 100% rename from 2811-check-if-it-is-possible-to-split-array/NOTES.md rename to problems/2811-check-if-it-is-possible-to-split-array/NOTES.md diff --git a/problems/2811-check-if-it-is-possible-to-split-array/README.md b/problems/2811-check-if-it-is-possible-to-split-array/README.md new file mode 100644 index 000000000..ee11d1376 --- /dev/null +++ b/problems/2811-check-if-it-is-possible-to-split-array/README.md @@ -0,0 +1,42 @@ +

2811. Check if it is Possible to Split Array

Medium


You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n non-empty arrays by performing a series of steps.

+ +

In each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two subarrays, if, for each resulting subarray, at least one of the following holds:

+ +
    +
  • The length of the subarray is one, or
  • +
  • The sum of elements of the subarray is greater than or equal to m.
  • +
+ +

Return true if you can split the given array into n arrays, otherwise return false.

+ +

Note: A subarray is a contiguous non-empty sequence of elements within an array.

+ +

 

+

Example 1:

+ +
Input: nums = [2, 2, 1], m = 4
+Output: true
+Explanation: We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.
+ +

Example 2:

+ +
Input: nums = [2, 1, 3], m = 5 
+Output: false
+Explanation: We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.
+ +

Example 3:

+ +
Input: nums = [2, 3, 3, 2, 3], m = 6
+Output: true
+Explanation: We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n == nums.length <= 100
  • +
  • 1 <= nums[i] <= 100
  • +
  • 1 <= m <= 200
  • +
+
\ No newline at end of file diff --git a/2812-find-the-safest-path-in-a-grid/2812-find-the-safest-path-in-a-grid.py b/problems/2812-find-the-safest-path-in-a-grid/2812-find-the-safest-path-in-a-grid.py similarity index 100% rename from 2812-find-the-safest-path-in-a-grid/2812-find-the-safest-path-in-a-grid.py rename to problems/2812-find-the-safest-path-in-a-grid/2812-find-the-safest-path-in-a-grid.py diff --git a/2812-find-the-safest-path-in-a-grid/NOTES.md b/problems/2812-find-the-safest-path-in-a-grid/NOTES.md similarity index 100% rename from 2812-find-the-safest-path-in-a-grid/NOTES.md rename to problems/2812-find-the-safest-path-in-a-grid/NOTES.md diff --git a/problems/2812-find-the-safest-path-in-a-grid/README.md b/problems/2812-find-the-safest-path-in-a-grid/README.md new file mode 100644 index 000000000..1565a57a7 --- /dev/null +++ b/problems/2812-find-the-safest-path-in-a-grid/README.md @@ -0,0 +1,54 @@ +

2812. Find the Safest Path in a Grid

Medium


You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:

+ +
    +
  • A cell containing a thief if grid[r][c] = 1
  • +
  • An empty cell if grid[r][c] = 0
  • +
+ +

You are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.

+ +

The safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.

+ +

Return the maximum safeness factor of all paths leading to cell (n - 1, n - 1).

+ +

An adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.

+ +

The Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.

+ +

 

+

Example 1:

+ +
Input: grid = [[1,0,0],[0,0,0],[0,0,1]]
+Output: 0
+Explanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).
+
+ +

Example 2:

+ +
Input: grid = [[0,0,1],[0,0,0],[0,0,0]]
+Output: 2
+Explanation: The path depicted in the picture above has a safeness factor of 2 since:
+- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.
+It can be shown that there are no other paths with a higher safeness factor.
+
+ +

Example 3:

+ +
Input: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]
+Output: 2
+Explanation: The path depicted in the picture above has a safeness factor of 2 since:
+- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.
+- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.
+It can be shown that there are no other paths with a higher safeness factor.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= grid.length == n <= 400
  • +
  • grid[i].length == n
  • +
  • grid[i][j] is either 0 or 1.
  • +
  • There is at least one thief in the grid.
  • +
+
\ No newline at end of file diff --git a/2816-double-a-number-represented-as-a-linked-list/2816-double-a-number-represented-as-a-linked-list.py b/problems/2816-double-a-number-represented-as-a-linked-list/2816-double-a-number-represented-as-a-linked-list.py similarity index 100% rename from 2816-double-a-number-represented-as-a-linked-list/2816-double-a-number-represented-as-a-linked-list.py rename to problems/2816-double-a-number-represented-as-a-linked-list/2816-double-a-number-represented-as-a-linked-list.py diff --git a/2816-double-a-number-represented-as-a-linked-list/NOTES.md b/problems/2816-double-a-number-represented-as-a-linked-list/NOTES.md similarity index 100% rename from 2816-double-a-number-represented-as-a-linked-list/NOTES.md rename to problems/2816-double-a-number-represented-as-a-linked-list/NOTES.md diff --git a/problems/2816-double-a-number-represented-as-a-linked-list/README.md b/problems/2816-double-a-number-represented-as-a-linked-list/README.md new file mode 100644 index 000000000..57ca97b02 --- /dev/null +++ b/problems/2816-double-a-number-represented-as-a-linked-list/README.md @@ -0,0 +1,28 @@ +

2816. Double a Number Represented as a Linked List

Medium


You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.

+ +

Return the head of the linked list after doubling it.

+ +

 

+

Example 1:

+ +
Input: head = [1,8,9]
+Output: [3,7,8]
+Explanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.
+
+ +

Example 2:

+ +
Input: head = [9,9,9]
+Output: [1,9,9,8]
+Explanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998. 
+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 104]
  • +
  • 0 <= Node.val <= 9
  • +
  • The input is generated such that the list represents a number that does not have leading zeros, except the number 0 itself.
  • +
+
\ No newline at end of file diff --git a/2824-count-pairs-whose-sum-is-less-than-target/2824-count-pairs-whose-sum-is-less-than-target.py b/problems/2824-count-pairs-whose-sum-is-less-than-target/2824-count-pairs-whose-sum-is-less-than-target.py similarity index 100% rename from 2824-count-pairs-whose-sum-is-less-than-target/2824-count-pairs-whose-sum-is-less-than-target.py rename to problems/2824-count-pairs-whose-sum-is-less-than-target/2824-count-pairs-whose-sum-is-less-than-target.py diff --git a/2824-count-pairs-whose-sum-is-less-than-target/NOTES.md b/problems/2824-count-pairs-whose-sum-is-less-than-target/NOTES.md similarity index 100% rename from 2824-count-pairs-whose-sum-is-less-than-target/NOTES.md rename to problems/2824-count-pairs-whose-sum-is-less-than-target/NOTES.md diff --git a/problems/2824-count-pairs-whose-sum-is-less-than-target/README.md b/problems/2824-count-pairs-whose-sum-is-less-than-target/README.md new file mode 100644 index 000000000..e97f1d5ce --- /dev/null +++ b/problems/2824-count-pairs-whose-sum-is-less-than-target/README.md @@ -0,0 +1,38 @@ +

2824. Count Pairs Whose Sum is Less than Target

Easy


Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target. +

 

+

Example 1:

+ +
Input: nums = [-1,1,2,3,1], target = 2
+Output: 3
+Explanation: There are 3 pairs of indices that satisfy the conditions in the statement:
+- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target
+- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target 
+- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target
+Note that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.
+
+ +

Example 2:

+ +
Input: nums = [-6,2,5,-2,-7,-1,3], target = -2
+Output: 10
+Explanation: There are 10 pairs of indices that satisfy the conditions in the statement:
+- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target
+- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target
+- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target
+- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target
+- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target
+- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target
+- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target
+- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target
+- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target
+- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length == n <= 50
  • +
  • -50 <= nums[i], target <= 50
  • +
+
\ No newline at end of file diff --git a/2825-make-string-a-subsequence-using-cyclic-increments/2825-make-string-a-subsequence-using-cyclic-increments.py b/problems/2825-make-string-a-subsequence-using-cyclic-increments/2825-make-string-a-subsequence-using-cyclic-increments.py similarity index 100% rename from 2825-make-string-a-subsequence-using-cyclic-increments/2825-make-string-a-subsequence-using-cyclic-increments.py rename to problems/2825-make-string-a-subsequence-using-cyclic-increments/2825-make-string-a-subsequence-using-cyclic-increments.py diff --git a/2825-make-string-a-subsequence-using-cyclic-increments/NOTES.md b/problems/2825-make-string-a-subsequence-using-cyclic-increments/NOTES.md similarity index 100% rename from 2825-make-string-a-subsequence-using-cyclic-increments/NOTES.md rename to problems/2825-make-string-a-subsequence-using-cyclic-increments/NOTES.md diff --git a/problems/2825-make-string-a-subsequence-using-cyclic-increments/README.md b/problems/2825-make-string-a-subsequence-using-cyclic-increments/README.md new file mode 100644 index 000000000..d0e26cf1c --- /dev/null +++ b/problems/2825-make-string-a-subsequence-using-cyclic-increments/README.md @@ -0,0 +1,42 @@ +

2825. Make String a Subsequence Using Cyclic Increments

Medium


You are given two 0-indexed strings str1 and str2.

+ +

In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.

+ +

Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.

+ +

Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.

+ +

 

+

Example 1:

+ +
Input: str1 = "abc", str2 = "ad"
+Output: true
+Explanation: Select index 2 in str1.
+Increment str1[2] to become 'd'. 
+Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.
+ +

Example 2:

+ +
Input: str1 = "zc", str2 = "ad"
+Output: true
+Explanation: Select indices 0 and 1 in str1. 
+Increment str1[0] to become 'a'. 
+Increment str1[1] to become 'd'. 
+Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.
+ +

Example 3:

+ +
Input: str1 = "ab", str2 = "d"
+Output: false
+Explanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once. 
+Therefore, false is returned.
+ +

 

+

Constraints:

+ +
    +
  • 1 <= str1.length <= 105
  • +
  • 1 <= str2.length <= 105
  • +
  • str1 and str2 consist of only lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/2833-furthest-point-from-origin/2833-furthest-point-from-origin.py b/problems/2833-furthest-point-from-origin/2833-furthest-point-from-origin.py similarity index 100% rename from 2833-furthest-point-from-origin/2833-furthest-point-from-origin.py rename to problems/2833-furthest-point-from-origin/2833-furthest-point-from-origin.py diff --git a/2833-furthest-point-from-origin/NOTES.md b/problems/2833-furthest-point-from-origin/NOTES.md similarity index 100% rename from 2833-furthest-point-from-origin/NOTES.md rename to problems/2833-furthest-point-from-origin/NOTES.md diff --git a/problems/2833-furthest-point-from-origin/README.md b/problems/2833-furthest-point-from-origin/README.md new file mode 100644 index 000000000..bfc086e86 --- /dev/null +++ b/problems/2833-furthest-point-from-origin/README.md @@ -0,0 +1,41 @@ +

2833. Furthest Point From Origin

Easy


You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.

+ +

In the ith move, you can choose one of the following directions:

+ +
    +
  • move to the left if moves[i] = 'L' or moves[i] = '_'
  • +
  • move to the right if moves[i] = 'R' or moves[i] = '_'
  • +
+ +

Return the distance from the origin of the furthest point you can get to after n moves.

+ +

 

+

Example 1:

+ +
Input: moves = "L_RL__R"
+Output: 3
+Explanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves "LLRLLLR".
+
+ +

Example 2:

+ +
Input: moves = "_R__LL_"
+Output: 5
+Explanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves "LRLLLLL".
+
+ +

Example 3:

+ +
Input: moves = "_______"
+Output: 7
+Explanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves "RRRRRRR".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= moves.length == n <= 50
  • +
  • moves consists only of characters 'L', 'R' and '_'.
  • +
+
\ No newline at end of file diff --git a/2834-find-the-minimum-possible-sum-of-a-beautiful-array/2834-find-the-minimum-possible-sum-of-a-beautiful-array.py b/problems/2834-find-the-minimum-possible-sum-of-a-beautiful-array/2834-find-the-minimum-possible-sum-of-a-beautiful-array.py similarity index 100% rename from 2834-find-the-minimum-possible-sum-of-a-beautiful-array/2834-find-the-minimum-possible-sum-of-a-beautiful-array.py rename to problems/2834-find-the-minimum-possible-sum-of-a-beautiful-array/2834-find-the-minimum-possible-sum-of-a-beautiful-array.py diff --git a/2834-find-the-minimum-possible-sum-of-a-beautiful-array/NOTES.md b/problems/2834-find-the-minimum-possible-sum-of-a-beautiful-array/NOTES.md similarity index 100% rename from 2834-find-the-minimum-possible-sum-of-a-beautiful-array/NOTES.md rename to problems/2834-find-the-minimum-possible-sum-of-a-beautiful-array/NOTES.md diff --git a/problems/2834-find-the-minimum-possible-sum-of-a-beautiful-array/README.md b/problems/2834-find-the-minimum-possible-sum-of-a-beautiful-array/README.md new file mode 100644 index 000000000..9cf6aa462 --- /dev/null +++ b/problems/2834-find-the-minimum-possible-sum-of-a-beautiful-array/README.md @@ -0,0 +1,50 @@ +

2834. Find the Minimum Possible Sum of a Beautiful Array

Medium


You are given positive integers n and target.

+ +

An array nums is beautiful if it meets the following conditions:

+ +
    +
  • nums.length == n.
  • +
  • nums consists of pairwise distinct positive integers.
  • +
  • There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.
  • +
+ +

Return the minimum possible sum that a beautiful array could have.

+ +

 

+

Example 1:

+ +
Input: n = 2, target = 3
+Output: 4
+Explanation: We can see that nums = [1,3] is beautiful.
+- The array nums has length n = 2.
+- The array nums consists of pairwise distinct positive integers.
+- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
+It can be proven that 4 is the minimum possible sum that a beautiful array could have.
+
+ +

Example 2:

+ +
Input: n = 3, target = 3
+Output: 8
+Explanation: We can see that nums = [1,3,4] is beautiful.
+- The array nums has length n = 3.
+- The array nums consists of pairwise distinct positive integers.
+- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
+It can be proven that 8 is the minimum possible sum that a beautiful array could have.
+
+ +

Example 3:

+ +
Input: n = 1, target = 1
+Output: 1
+Explanation: We can see, that nums = [1] is beautiful.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n <= 105
  • +
  • 1 <= target <= 105
  • +
+
\ No newline at end of file diff --git a/2849-determine-if-a-cell-is-reachable-at-a-given-time/2849-determine-if-a-cell-is-reachable-at-a-given-time.py b/problems/2849-determine-if-a-cell-is-reachable-at-a-given-time/2849-determine-if-a-cell-is-reachable-at-a-given-time.py similarity index 100% rename from 2849-determine-if-a-cell-is-reachable-at-a-given-time/2849-determine-if-a-cell-is-reachable-at-a-given-time.py rename to problems/2849-determine-if-a-cell-is-reachable-at-a-given-time/2849-determine-if-a-cell-is-reachable-at-a-given-time.py diff --git a/problems/2849-determine-if-a-cell-is-reachable-at-a-given-time/README.md b/problems/2849-determine-if-a-cell-is-reachable-at-a-given-time/README.md new file mode 100644 index 000000000..b806424de --- /dev/null +++ b/problems/2849-determine-if-a-cell-is-reachable-at-a-given-time/README.md @@ -0,0 +1,31 @@ +

2849. Determine if a Cell Is Reachable at a Given Time

Medium


You are given four integers sx, sy, fx, fy, and a non-negative integer t.

+ +

In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.

+ +

Return true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.

+ +

A cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.

+ +

 

+

Example 1:

+ +
Input: sx = 2, sy = 4, fx = 7, fy = 7, t = 6
+Output: true
+Explanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above. 
+
+ +

Example 2:

+ +
Input: sx = 3, sy = 1, fx = 7, fy = 3, t = 3
+Output: false
+Explanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= sx, sy, fx, fy <= 109
  • +
  • 0 <= t <= 109
  • +
+
\ No newline at end of file diff --git a/2864-maximum-odd-binary-number/2864-maximum-odd-binary-number.py b/problems/2864-maximum-odd-binary-number/2864-maximum-odd-binary-number.py similarity index 100% rename from 2864-maximum-odd-binary-number/2864-maximum-odd-binary-number.py rename to problems/2864-maximum-odd-binary-number/2864-maximum-odd-binary-number.py diff --git a/2864-maximum-odd-binary-number/NOTES.md b/problems/2864-maximum-odd-binary-number/NOTES.md similarity index 100% rename from 2864-maximum-odd-binary-number/NOTES.md rename to problems/2864-maximum-odd-binary-number/NOTES.md diff --git a/problems/2864-maximum-odd-binary-number/README.md b/problems/2864-maximum-odd-binary-number/README.md new file mode 100644 index 000000000..598ac2132 --- /dev/null +++ b/problems/2864-maximum-odd-binary-number/README.md @@ -0,0 +1,32 @@ +

2864. Maximum Odd Binary Number

Easy


You are given a binary string s that contains at least one '1'.

+ +

You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.

+ +

Return a string representing the maximum odd binary number that can be created from the given combination.

+ +

Note that the resulting string can have leading zeros.

+ +

 

+

Example 1:

+ +
Input: s = "010"
+Output: "001"
+Explanation: Because there is just one '1', it must be in the last position. So the answer is "001".
+
+ +

Example 2:

+ +
Input: s = "0101"
+Output: "1001"
+Explanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is "100". So the answer is "1001".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 100
  • +
  • s consists only of '0' and '1'.
  • +
  • s contains at least one '1'.
  • +
+
\ No newline at end of file diff --git a/2870-minimum-number-of-operations-to-make-array-empty/2870-minimum-number-of-operations-to-make-array-empty.py b/problems/2870-minimum-number-of-operations-to-make-array-empty/2870-minimum-number-of-operations-to-make-array-empty.py similarity index 100% rename from 2870-minimum-number-of-operations-to-make-array-empty/2870-minimum-number-of-operations-to-make-array-empty.py rename to problems/2870-minimum-number-of-operations-to-make-array-empty/2870-minimum-number-of-operations-to-make-array-empty.py diff --git a/2870-minimum-number-of-operations-to-make-array-empty/NOTES.md b/problems/2870-minimum-number-of-operations-to-make-array-empty/NOTES.md similarity index 100% rename from 2870-minimum-number-of-operations-to-make-array-empty/NOTES.md rename to problems/2870-minimum-number-of-operations-to-make-array-empty/NOTES.md diff --git a/problems/2870-minimum-number-of-operations-to-make-array-empty/README.md b/problems/2870-minimum-number-of-operations-to-make-array-empty/README.md new file mode 100644 index 000000000..e32a87163 --- /dev/null +++ b/problems/2870-minimum-number-of-operations-to-make-array-empty/README.md @@ -0,0 +1,39 @@ +

2870. Minimum Number of Operations to Make Array Empty

Medium


You are given a 0-indexed array nums consisting of positive integers.

+ +

There are two types of operations that you can apply on the array any number of times:

+ +
    +
  • Choose two elements with equal values and delete them from the array.
  • +
  • Choose three elements with equal values and delete them from the array.
  • +
+ +

Return the minimum number of operations required to make the array empty, or -1 if it is not possible.

+ +

 

+

Example 1:

+ +
Input: nums = [2,3,3,2,2,4,2,3,4]
+Output: 4
+Explanation: We can apply the following operations to make the array empty:
+- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].
+- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].
+- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].
+- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].
+It can be shown that we cannot make the array empty in less than 4 operations.
+
+ +

Example 2:

+ +
Input: nums = [2,1,2,2,3,3]
+Output: -1
+Explanation: It is impossible to empty the array.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= nums.length <= 105
  • +
  • 1 <= nums[i] <= 106
  • +
+
\ No newline at end of file diff --git a/2958-length-of-longest-subarray-with-at-most-k-frequency/2958-length-of-longest-subarray-with-at-most-k-frequency.py b/problems/2958-length-of-longest-subarray-with-at-most-k-frequency/2958-length-of-longest-subarray-with-at-most-k-frequency.py similarity index 100% rename from 2958-length-of-longest-subarray-with-at-most-k-frequency/2958-length-of-longest-subarray-with-at-most-k-frequency.py rename to problems/2958-length-of-longest-subarray-with-at-most-k-frequency/2958-length-of-longest-subarray-with-at-most-k-frequency.py diff --git a/2958-length-of-longest-subarray-with-at-most-k-frequency/NOTES.md b/problems/2958-length-of-longest-subarray-with-at-most-k-frequency/NOTES.md similarity index 100% rename from 2958-length-of-longest-subarray-with-at-most-k-frequency/NOTES.md rename to problems/2958-length-of-longest-subarray-with-at-most-k-frequency/NOTES.md diff --git a/problems/2958-length-of-longest-subarray-with-at-most-k-frequency/README.md b/problems/2958-length-of-longest-subarray-with-at-most-k-frequency/README.md new file mode 100644 index 000000000..768756e8a --- /dev/null +++ b/problems/2958-length-of-longest-subarray-with-at-most-k-frequency/README.md @@ -0,0 +1,44 @@ +

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/2962-count-subarrays-where-max-element-appears-at-least-k-times/2962-count-subarrays-where-max-element-appears-at-least-k-times.py b/problems/2962-count-subarrays-where-max-element-appears-at-least-k-times/2962-count-subarrays-where-max-element-appears-at-least-k-times.py similarity index 100% rename from 2962-count-subarrays-where-max-element-appears-at-least-k-times/2962-count-subarrays-where-max-element-appears-at-least-k-times.py rename to problems/2962-count-subarrays-where-max-element-appears-at-least-k-times/2962-count-subarrays-where-max-element-appears-at-least-k-times.py diff --git a/2962-count-subarrays-where-max-element-appears-at-least-k-times/NOTES.md b/problems/2962-count-subarrays-where-max-element-appears-at-least-k-times/NOTES.md similarity index 100% rename from 2962-count-subarrays-where-max-element-appears-at-least-k-times/NOTES.md rename to problems/2962-count-subarrays-where-max-element-appears-at-least-k-times/NOTES.md diff --git a/problems/2962-count-subarrays-where-max-element-appears-at-least-k-times/README.md b/problems/2962-count-subarrays-where-max-element-appears-at-least-k-times/README.md new file mode 100644 index 000000000..499c8675c --- /dev/null +++ b/problems/2962-count-subarrays-where-max-element-appears-at-least-k-times/README.md @@ -0,0 +1,30 @@ +

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/2966-divide-array-into-arrays-with-max-difference/2966-divide-array-into-arrays-with-max-difference.py b/problems/2966-divide-array-into-arrays-with-max-difference/2966-divide-array-into-arrays-with-max-difference.py similarity index 100% rename from 2966-divide-array-into-arrays-with-max-difference/2966-divide-array-into-arrays-with-max-difference.py rename to problems/2966-divide-array-into-arrays-with-max-difference/2966-divide-array-into-arrays-with-max-difference.py diff --git a/2966-divide-array-into-arrays-with-max-difference/NOTES.md b/problems/2966-divide-array-into-arrays-with-max-difference/NOTES.md similarity index 100% rename from 2966-divide-array-into-arrays-with-max-difference/NOTES.md rename to problems/2966-divide-array-into-arrays-with-max-difference/NOTES.md diff --git a/problems/2966-divide-array-into-arrays-with-max-difference/README.md b/problems/2966-divide-array-into-arrays-with-max-difference/README.md new file mode 100644 index 000000000..8e0024aa4 --- /dev/null +++ b/problems/2966-divide-array-into-arrays-with-max-difference/README.md @@ -0,0 +1,39 @@ +

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/2971-find-polygon-with-the-largest-perimeter/2971-find-polygon-with-the-largest-perimeter.py b/problems/2971-find-polygon-with-the-largest-perimeter/2971-find-polygon-with-the-largest-perimeter.py similarity index 100% rename from 2971-find-polygon-with-the-largest-perimeter/2971-find-polygon-with-the-largest-perimeter.py rename to problems/2971-find-polygon-with-the-largest-perimeter/2971-find-polygon-with-the-largest-perimeter.py diff --git a/problems/2971-find-polygon-with-the-largest-perimeter/README.md b/problems/2971-find-polygon-with-the-largest-perimeter/README.md new file mode 100644 index 000000000..c7d742d13 --- /dev/null +++ b/problems/2971-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/2976-minimum-cost-to-convert-string-i/2976-minimum-cost-to-convert-string-i.py b/problems/2976-minimum-cost-to-convert-string-i/2976-minimum-cost-to-convert-string-i.py similarity index 100% rename from 2976-minimum-cost-to-convert-string-i/2976-minimum-cost-to-convert-string-i.py rename to problems/2976-minimum-cost-to-convert-string-i/2976-minimum-cost-to-convert-string-i.py diff --git a/2976-minimum-cost-to-convert-string-i/NOTES.md b/problems/2976-minimum-cost-to-convert-string-i/NOTES.md similarity index 100% rename from 2976-minimum-cost-to-convert-string-i/NOTES.md rename to problems/2976-minimum-cost-to-convert-string-i/NOTES.md diff --git a/problems/2976-minimum-cost-to-convert-string-i/README.md b/problems/2976-minimum-cost-to-convert-string-i/README.md new file mode 100644 index 000000000..cc8d73c02 --- /dev/null +++ b/problems/2976-minimum-cost-to-convert-string-i/README.md @@ -0,0 +1,48 @@ +

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/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.py b/problems/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.py similarity index 100% rename from 2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.py rename to problems/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k.py diff --git a/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/NOTES.md b/problems/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/NOTES.md similarity index 100% rename from 2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/NOTES.md rename to problems/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/NOTES.md diff --git a/problems/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/README.md b/problems/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/README.md new file mode 100644 index 000000000..8da447843 --- /dev/null +++ b/problems/2997-minimum-number-of-operations-to-make-array-xor-equal-to-k/README.md @@ -0,0 +1,40 @@ +

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/3005-count-elements-with-maximum-frequency/3005-count-elements-with-maximum-frequency.py b/problems/3005-count-elements-with-maximum-frequency/3005-count-elements-with-maximum-frequency.py similarity index 100% rename from 3005-count-elements-with-maximum-frequency/3005-count-elements-with-maximum-frequency.py rename to problems/3005-count-elements-with-maximum-frequency/3005-count-elements-with-maximum-frequency.py diff --git a/3005-count-elements-with-maximum-frequency/NOTES.md b/problems/3005-count-elements-with-maximum-frequency/NOTES.md similarity index 100% rename from 3005-count-elements-with-maximum-frequency/NOTES.md rename to problems/3005-count-elements-with-maximum-frequency/NOTES.md diff --git a/problems/3005-count-elements-with-maximum-frequency/README.md b/problems/3005-count-elements-with-maximum-frequency/README.md new file mode 100644 index 000000000..2b9d7d587 --- /dev/null +++ b/problems/3005-count-elements-with-maximum-frequency/README.md @@ -0,0 +1,31 @@ +

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/3016-minimum-number-of-pushes-to-type-word-ii/3016-minimum-number-of-pushes-to-type-word-ii.py b/problems/3016-minimum-number-of-pushes-to-type-word-ii/3016-minimum-number-of-pushes-to-type-word-ii.py similarity index 100% rename from 3016-minimum-number-of-pushes-to-type-word-ii/3016-minimum-number-of-pushes-to-type-word-ii.py rename to problems/3016-minimum-number-of-pushes-to-type-word-ii/3016-minimum-number-of-pushes-to-type-word-ii.py diff --git a/3016-minimum-number-of-pushes-to-type-word-ii/NOTES.md b/problems/3016-minimum-number-of-pushes-to-type-word-ii/NOTES.md similarity index 100% rename from 3016-minimum-number-of-pushes-to-type-word-ii/NOTES.md rename to problems/3016-minimum-number-of-pushes-to-type-word-ii/NOTES.md diff --git a/problems/3016-minimum-number-of-pushes-to-type-word-ii/README.md b/problems/3016-minimum-number-of-pushes-to-type-word-ii/README.md new file mode 100644 index 000000000..c7bae1b53 --- /dev/null +++ b/problems/3016-minimum-number-of-pushes-to-type-word-ii/README.md @@ -0,0 +1,64 @@ +

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/3062-winner-of-the-linked-list-game/3062-winner-of-the-linked-list-game.py b/problems/3062-winner-of-the-linked-list-game/3062-winner-of-the-linked-list-game.py similarity index 100% rename from 3062-winner-of-the-linked-list-game/3062-winner-of-the-linked-list-game.py rename to problems/3062-winner-of-the-linked-list-game/3062-winner-of-the-linked-list-game.py diff --git a/3062-winner-of-the-linked-list-game/NOTES.md b/problems/3062-winner-of-the-linked-list-game/NOTES.md similarity index 100% rename from 3062-winner-of-the-linked-list-game/NOTES.md rename to problems/3062-winner-of-the-linked-list-game/NOTES.md diff --git a/problems/3062-winner-of-the-linked-list-game/README.md b/problems/3062-winner-of-the-linked-list-game/README.md new file mode 100644 index 000000000..bc4337555 --- /dev/null +++ b/problems/3062-winner-of-the-linked-list-game/README.md @@ -0,0 +1,77 @@ +

3062. Winner of the Linked List Game

Easy


You are given the head of a linked list of even length containing integers.

+ +

Each odd-indexed node contains an odd integer and each even-indexed node contains an even integer.

+ +

We call each even-indexed node and its next node a pair, e.g., the nodes with indices 0 and 1 are a pair, the nodes with indices 2 and 3 are a pair, and so on.

+ +

For every pair, we compare the values of the nodes in the pair:

+ +
    +
  • If the odd-indexed node is higher, the "Odd" team gets a point.
  • +
  • If the even-indexed node is higher, the "Even" team gets a point.
  • +
+ +

Return the name of the team with the higher points, if the points are equal, return "Tie".

+ +

 

+

Example 1:

+ +
+

Input: head = [2,1]

+ +

Output: "Even"

+ +

Explanation: There is only one pair in this linked list and that is (2,1). Since 2 > 1, the Even team gets the point.

+ +

Hence, the answer would be "Even".

+
+ +

Example 2:

+ +
+

Input: head = [2,5,4,7,20,5]

+ +

Output: "Odd"

+ +

Explanation: There are 3 pairs in this linked list. Let's investigate each pair individually:

+ +

(2,5) -> Since 2 < 5, The Odd team gets the point.

+ +

(4,7) -> Since 4 < 7, The Odd team gets the point.

+ +

(20,5) -> Since 20 > 5, The Even team gets the point.

+ +

The Odd team earned 2 points while the Even team got 1 point and the Odd team has the higher points.

+ +

Hence, the answer would be "Odd".

+
+ +

Example 3:

+ +
+

Input: head = [4,5,2,1]

+ +

Output: "Tie"

+ +

Explanation: There are 2 pairs in this linked list. Let's investigate each pair individually:

+ +

(4,5) -> Since 4 < 5, the Odd team gets the point.

+ +

(2,1) -> Since 2 > 1, the Even team gets the point.

+ +

Both teams earned 1 point.

+ +

Hence, the answer would be "Tie".

+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [2, 100].
  • +
  • The number of nodes in the list is even.
  • +
  • 1 <= Node.val <= 100
  • +
  • The value of each odd-indexed node is odd.
  • +
  • The value of each even-indexed node is even.
  • +
+
\ No newline at end of file diff --git a/3063-linked-list-frequency/3063-linked-list-frequency.py b/problems/3063-linked-list-frequency/3063-linked-list-frequency.py similarity index 100% rename from 3063-linked-list-frequency/3063-linked-list-frequency.py rename to problems/3063-linked-list-frequency/3063-linked-list-frequency.py diff --git a/problems/3063-linked-list-frequency/README.md b/problems/3063-linked-list-frequency/README.md new file mode 100644 index 000000000..452df8971 --- /dev/null +++ b/problems/3063-linked-list-frequency/README.md @@ -0,0 +1,43 @@ +

3063. Linked List Frequency

Medium


Given the head of a linked list containing k distinct elements, return the head to a linked list of length k containing the frequency of each distinct element in the given linked list in any order.

+ +

 

+

Example 1:

+ +
+

Input: head = [1,1,2,1,2,3]

+ +

Output: [3,2,1]

+ +

Explanation: There are 3 distinct elements in the list. The frequency of 1 is 3, the frequency of 2 is 2 and the frequency of 3 is 1. Hence, we return 3 -> 2 -> 1.

+ +

Note that 1 -> 2 -> 3, 1 -> 3 -> 2, 2 -> 1 -> 3, 2 -> 3 -> 1, and 3 -> 1 -> 2 are also valid answers.

+
+ +

Example 2:

+ +
+

Input: head = [1,1,2,2,2]

+ +

Output: [2,3]

+ +

Explanation: There are 2 distinct elements in the list. The frequency of 1 is 2 and the frequency of 2 is 3. Hence, we return 2 -> 3.

+
+ +

Example 3:

+ +
+

Input: head = [6,5,4,3,2,1]

+ +

Output: [1,1,1,1,1,1]

+ +

Explanation: There are 6 distinct elements in the list. The frequency of each of them is 1. Hence, we return 1 -> 1 -> 1 -> 1 -> 1 -> 1.

+
+ +

 

+

Constraints:

+ +
    +
  • The number of nodes in the list is in the range [1, 105].
  • +
  • 1 <= Node.val <= 105
  • +
+
\ No newline at end of file diff --git a/3068-find-the-maximum-sum-of-node-values/3068-find-the-maximum-sum-of-node-values.py b/problems/3068-find-the-maximum-sum-of-node-values/3068-find-the-maximum-sum-of-node-values.py similarity index 100% rename from 3068-find-the-maximum-sum-of-node-values/3068-find-the-maximum-sum-of-node-values.py rename to problems/3068-find-the-maximum-sum-of-node-values/3068-find-the-maximum-sum-of-node-values.py diff --git a/3068-find-the-maximum-sum-of-node-values/NOTES.md b/problems/3068-find-the-maximum-sum-of-node-values/NOTES.md similarity index 100% rename from 3068-find-the-maximum-sum-of-node-values/NOTES.md rename to problems/3068-find-the-maximum-sum-of-node-values/NOTES.md diff --git a/problems/3068-find-the-maximum-sum-of-node-values/README.md b/problems/3068-find-the-maximum-sum-of-node-values/README.md new file mode 100644 index 000000000..f988eb9ac --- /dev/null +++ b/problems/3068-find-the-maximum-sum-of-node-values/README.md @@ -0,0 +1,57 @@ +

3068. Find the Maximum Sum of Node Values

Hard


There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 0-indexed 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree. You are also given a positive integer k, and a 0-indexed array of non-negative integers nums of length n, where nums[i] represents the value of the node numbered i.

+ +

Alice wants the sum of values of tree nodes to be maximum, for which Alice can perform the following operation any number of times (including zero) on the tree:

+ +
    +
  • Choose any edge [u, v] connecting the nodes u and v, and update their values as follows: + +
      +
    • nums[u] = nums[u] XOR k
    • +
    • nums[v] = nums[v] XOR k
    • +
    +
  • +
+ +

Return the maximum possible sum of the values Alice can achieve by performing the operation any number of times.

+ +

 

+

Example 1:

+ +
Input: nums = [1,2,1], k = 3, edges = [[0,1],[0,2]]
+Output: 6
+Explanation: Alice can achieve the maximum sum of 6 using a single operation:
+- Choose the edge [0,2]. nums[0] and nums[2] become: 1 XOR 3 = 2, and the array nums becomes: [1,2,1] -> [2,2,2].
+The total sum of values is 2 + 2 + 2 = 6.
+It can be shown that 6 is the maximum achievable sum of values.
+
+ +

Example 2:

+ +
Input: nums = [2,3], k = 7, edges = [[0,1]]
+Output: 9
+Explanation: Alice can achieve the maximum sum of 9 using a single operation:
+- Choose the edge [0,1]. nums[0] becomes: 2 XOR 7 = 5 and nums[1] become: 3 XOR 7 = 4, and the array nums becomes: [2,3] -> [5,4].
+The total sum of values is 5 + 4 = 9.
+It can be shown that 9 is the maximum achievable sum of values.
+
+ +

Example 3:

+ +
Input: nums = [7,7,7,7,7,7], k = 3, edges = [[0,1],[0,2],[0,3],[0,4],[0,5]]
+Output: 42
+Explanation: The maximum achievable sum is 42 which can be achieved by Alice performing no operations.
+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= n == nums.length <= 2 * 104
  • +
  • 1 <= k <= 109
  • +
  • 0 <= nums[i] <= 109
  • +
  • edges.length == n - 1
  • +
  • edges[i].length == 2
  • +
  • 0 <= edges[i][0], edges[i][1] <= n - 1
  • +
  • The input is generated such that edges represent a valid tree.
  • +
+
\ No newline at end of file diff --git a/3075-maximize-happiness-of-selected-children/3075-maximize-happiness-of-selected-children.py b/problems/3075-maximize-happiness-of-selected-children/3075-maximize-happiness-of-selected-children.py similarity index 100% rename from 3075-maximize-happiness-of-selected-children/3075-maximize-happiness-of-selected-children.py rename to problems/3075-maximize-happiness-of-selected-children/3075-maximize-happiness-of-selected-children.py diff --git a/3075-maximize-happiness-of-selected-children/NOTES.md b/problems/3075-maximize-happiness-of-selected-children/NOTES.md similarity index 100% rename from 3075-maximize-happiness-of-selected-children/NOTES.md rename to problems/3075-maximize-happiness-of-selected-children/NOTES.md diff --git a/problems/3075-maximize-happiness-of-selected-children/README.md b/problems/3075-maximize-happiness-of-selected-children/README.md new file mode 100644 index 000000000..16567a73b --- /dev/null +++ b/problems/3075-maximize-happiness-of-selected-children/README.md @@ -0,0 +1,47 @@ +

3075. Maximize Happiness of Selected Children

Medium


You are given an array happiness of length n, and a positive integer k.

+ +

There are n children standing in a queue, where the ith child has happiness value happiness[i]. You want to select k children from these n children in k turns.

+ +

In each turn, when you select a child, the happiness value of all the children that have not been selected till now decreases by 1. Note that the happiness value cannot become negative and gets decremented only if it is positive.

+ +

Return the maximum sum of the happiness values of the selected children you can achieve by selecting k children.

+ +

 

+

Example 1:

+ +
Input: happiness = [1,2,3], k = 2
+Output: 4
+Explanation: We can pick 2 children in the following way:
+- Pick the child with the happiness value == 3. The happiness value of the remaining children becomes [0,1].
+- Pick the child with the happiness value == 1. The happiness value of the remaining child becomes [0]. Note that the happiness value cannot become less than 0.
+The sum of the happiness values of the selected children is 3 + 1 = 4.
+
+ +

Example 2:

+ +
Input: happiness = [1,1,1,1], k = 2
+Output: 1
+Explanation: We can pick 2 children in the following way:
+- Pick any child with the happiness value == 1. The happiness value of the remaining children becomes [0,0,0].
+- Pick the child with the happiness value == 0. The happiness value of the remaining child becomes [0,0].
+The sum of the happiness values of the selected children is 1 + 0 = 1.
+
+ +

Example 3:

+ +
Input: happiness = [2,3,4,5], k = 1
+Output: 5
+Explanation: We can pick 1 child in the following way:
+- Pick the child with the happiness value == 5. The happiness value of the remaining children becomes [1,2,3].
+The sum of the happiness values of the selected children is 5.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n == happiness.length <= 2 * 105
  • +
  • 1 <= happiness[i] <= 108
  • +
  • 1 <= k <= n
  • +
+
\ No newline at end of file diff --git a/3110-score-of-a-string/3110-score-of-a-string.py b/problems/3110-score-of-a-string/3110-score-of-a-string.py similarity index 100% rename from 3110-score-of-a-string/3110-score-of-a-string.py rename to problems/3110-score-of-a-string/3110-score-of-a-string.py diff --git a/3110-score-of-a-string/NOTES.md b/problems/3110-score-of-a-string/NOTES.md similarity index 100% rename from 3110-score-of-a-string/NOTES.md rename to problems/3110-score-of-a-string/NOTES.md diff --git a/problems/3110-score-of-a-string/README.md b/problems/3110-score-of-a-string/README.md new file mode 100644 index 000000000..5859fc385 --- /dev/null +++ b/problems/3110-score-of-a-string/README.md @@ -0,0 +1,37 @@ +

3110. Score of a String

Easy


You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.

+ +

Return the score of s.

+ +

 

+

Example 1:

+ +
+

Input: s = "hello"

+ +

Output: 13

+ +

Explanation:

+ +

The ASCII values of the characters in s are: 'h' = 104, 'e' = 101, 'l' = 108, 'o' = 111. So, the score of s would be |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13.

+
+ +

Example 2:

+ +
+

Input: s = "zaz"

+ +

Output: 50

+ +

Explanation:

+ +

The ASCII values of the characters in s are: 'z' = 122, 'a' = 97. So, the score of s would be |122 - 97| + |97 - 122| = 25 + 25 = 50.

+
+ +

 

+

Constraints:

+ +
    +
  • 2 <= s.length <= 100
  • +
  • s consists only of lowercase English letters.
  • +
+
\ No newline at end of file diff --git a/3189-minimum-moves-to-get-a-peaceful-board/3189-minimum-moves-to-get-a-peaceful-board.py b/problems/3189-minimum-moves-to-get-a-peaceful-board/3189-minimum-moves-to-get-a-peaceful-board.py similarity index 100% rename from 3189-minimum-moves-to-get-a-peaceful-board/3189-minimum-moves-to-get-a-peaceful-board.py rename to problems/3189-minimum-moves-to-get-a-peaceful-board/3189-minimum-moves-to-get-a-peaceful-board.py diff --git a/problems/3189-minimum-moves-to-get-a-peaceful-board/README.md b/problems/3189-minimum-moves-to-get-a-peaceful-board/README.md new file mode 100644 index 000000000..1b9e8c2c8 --- /dev/null +++ b/problems/3189-minimum-moves-to-get-a-peaceful-board/README.md @@ -0,0 +1,38 @@ +

3189. Minimum Moves to Get a Peaceful Board

Medium


Given a 2D array rooks of length n, where rooks[i] = [xi, yi] indicates the position of a rook on an n x n chess board. Your task is to move the rooks 1 cell at a time vertically or horizontally (to an adjacent cell) such that the board becomes peaceful.

+ +

A board is peaceful if there is exactly one rook in each row and each column.

+ +

Return the minimum number of moves required to get a peaceful board.

+ +

Note that at no point can there be two rooks in the same cell.

+ +

 

+

Example 1:

+ +
+

Input: rooks = [[0,0],[1,0],[1,1]]

+ +

Output: 3

+ +

Explanation:

+
+ +

Example 2:

+ +
+

Input: rooks = [[0,0],[0,1],[0,2],[0,3]]

+ +

Output: 6

+ +

Explanation:

+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= n == rooks.length <= 500
  • +
  • 0 <= xi, yi <= n - 1
  • +
  • The input is generated such that there are no 2 rooks in the same cell.
  • +
+
\ No newline at end of file