feat: populate note files with problem descriptions and code stubs
Add populate-notes.mjs that fetches problem descriptions and Python/C++ code stubs from LeetCode's GraphQL API. Populated all 197 NeetCode 150 note files with: - Problem description (examples, constraints) - Python code stub (function signature) - C++ code stub (function signature + includes) API responses cached in leetcode/.cache/leetcode/ for instant re-runs.
This commit is contained in:
@@ -1,18 +1,74 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0010. Regular Expression Matching :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0010. Regular Expression Matching][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0010. Regular Expression Matching][0010. Regular Expression Matching]]
|
||||
:END:
|
||||
|
||||
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.
|
||||
|
||||
Return a boolean indicating whether the matching covers the entire input string (not partial).
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "aa", p = "a"
|
||||
Output: false
|
||||
Explanation: "a" does not match the entire string "aa".
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
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".
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "ab", p = ".*"
|
||||
Output: true
|
||||
Explanation: ".*" means "zero or more (*) of any character (.)".
|
||||
#+end_src
|
||||
|
||||
|
||||
*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.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def isMatch(self, s: str, p: str) -> bool:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
bool isMatch(string s, string p) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,56 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0062. Unique Paths :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0062. Unique Paths][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0062. Unique Paths][0062. Unique Paths]]
|
||||
:END:
|
||||
|
||||
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 * 10^{9}~.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: m = 3, n = 7
|
||||
Output: 28
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
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
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= m, n <= 100~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def uniquePaths(self, m: int, n: int) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int uniquePaths(int m, int n) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,68 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0072. Edit Distance :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0072. Edit Distance][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0072. Edit Distance][0072. Edit Distance]]
|
||||
:END:
|
||||
|
||||
Given two strings ~word1~ and ~word2~, return /the minimum number of operations required to convert ~word1~ to ~word2~/.
|
||||
|
||||
You have the following three operations permitted on a word:
|
||||
|
||||
- Insert a character
|
||||
|
||||
- Delete a character
|
||||
|
||||
- Replace a character
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: word1 = "horse", word2 = "ros"
|
||||
Output: 3
|
||||
Explanation:
|
||||
horse -> rorse (replace 'h' with 'r')
|
||||
rorse -> rose (remove 'r')
|
||||
rose -> ros (remove 'e')
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: word1 = "intention", word2 = "execution"
|
||||
Output: 5
|
||||
Explanation:
|
||||
intention -> inention (remove 't')
|
||||
inention -> enention (replace 'i' with 'e')
|
||||
enention -> exention (replace 'n' with 'x')
|
||||
exention -> exection (replace 'n' with 'c')
|
||||
exection -> execution (insert 'u')
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~0 <= word1.length, word2.length <= 500~
|
||||
|
||||
- ~word1~ and ~word2~ consist of lowercase English letters.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def minDistance(self, word1: str, word2: str) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int minDistance(string word1, string word2) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,80 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0097. Interleaving String :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0097. Interleaving String][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0097. Interleaving String][0097. Interleaving String]]
|
||||
:END:
|
||||
|
||||
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 = s_{1} + s_{2} + ... + s_{n}~
|
||||
|
||||
- ~t = t_{1} + t_{2} + ... + t_{m}~
|
||||
|
||||
- ~|n - m| <= 1~
|
||||
|
||||
- The *interleaving* is ~s_{1} + t_{1} + s_{2} + t_{2} + s_{3} + t_{3} + ...~ or ~t_{1} + s_{1} + t_{2} + s_{2} + t_{3} + s_{3} + ...~
|
||||
|
||||
*Note:* ~a + b~ is the concatenation of strings ~a~ and ~b~.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
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.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
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.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s1 = "", s2 = "", s3 = ""
|
||||
Output: true
|
||||
#+end_src
|
||||
|
||||
|
||||
*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?
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def isInterleave(self, s1: str, s2: str, s3: str) -> bool:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
bool isInterleave(string s1, string s2, string s3) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,64 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0115. Distinct Subsequences :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0115. Distinct Subsequences][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0115. Distinct Subsequences][0115. Distinct Subsequences]]
|
||||
:END:
|
||||
|
||||
Given two strings s and t, return the number of distinct subsequences of s which equals t.
|
||||
|
||||
The test cases are generated so that the answer fits on a 32-bit signed integer.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "rabbbit", t = "rabbit"
|
||||
Output: 3
|
||||
Explanation:
|
||||
As shown below, there are 3 ways you can generate "rabbit" from s.
|
||||
rabbbit
|
||||
rabbbit
|
||||
rabbbit
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "babgbag", t = "bag"
|
||||
Output: 5
|
||||
Explanation:
|
||||
As shown below, there are 5 ways you can generate "bag" from s.
|
||||
babgbag
|
||||
babgbag
|
||||
babgbag
|
||||
babgbag
|
||||
babgbag
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length, t.length <= 1000~
|
||||
|
||||
- ~s~ and ~t~ consist of English letters.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def numDistinct(self, s: str, t: str) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int numDistinct(string s, string t) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
+42
-3
@@ -1,18 +1,57 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0309. Best Time to Buy And Sell Stock With Cooldown :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0309. Best Time to Buy And Sell Stock With Cooldown][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0309. Best Time to Buy And Sell Stock With Cooldown][0309. Best Time to Buy And Sell Stock With Cooldown]]
|
||||
:END:
|
||||
|
||||
You are given an array ~prices~ where ~prices[i]~ is the price of a given stock on the ~i^{th}~ day.
|
||||
|
||||
Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:
|
||||
|
||||
- After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).
|
||||
|
||||
*Note:* You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: prices = [1,2,3,0,2]
|
||||
Output: 3
|
||||
Explanation: transactions = [buy, sell, cooldown, buy, sell]
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: prices = [1]
|
||||
Output: 0
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= prices.length <= 5000~
|
||||
|
||||
- ~0 <= prices[i] <= 1000~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def maxProfit(self, prices: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int maxProfit(vector<int>& prices) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,59 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0312. Burst Balloons :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0312. Burst Balloons][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0312. Burst Balloons][0312. Burst Balloons]]
|
||||
:END:
|
||||
|
||||
You are given ~n~ balloons, indexed from ~0~ to ~n - 1~. Each balloon is painted with a number on it represented by an array ~nums~. You are asked to burst all the balloons.
|
||||
|
||||
If you burst the ~i^{th}~ balloon, you will get ~nums[i - 1] * nums[i] * nums[i + 1]~ coins. If ~i - 1~ or ~i + 1~ goes out of bounds of the array, then treat it as if there is a balloon with a ~1~ painted on it.
|
||||
|
||||
Return /the maximum coins you can collect by bursting the balloons wisely/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [3,1,5,8]
|
||||
Output: 167
|
||||
Explanation:
|
||||
nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
|
||||
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,5]
|
||||
Output: 10
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~n == nums.length~
|
||||
|
||||
- ~1 <= n <= 300~
|
||||
|
||||
- ~0 <= nums[i] <= 100~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def maxCoins(self, nums: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int maxCoins(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
+52
-3
@@ -1,18 +1,67 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0329. Longest Increasing Path In a Matrix :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0329. Longest Increasing Path In a Matrix][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0329. Longest Increasing Path In a Matrix][0329. Longest Increasing Path In a Matrix]]
|
||||
:END:
|
||||
|
||||
Given an ~m x n~ integers ~matrix~, return /the length of the longest increasing path in /~matrix~.
|
||||
|
||||
From each cell, you can either move in four directions: left, right, up, or down. You *may not* move *diagonally* or move *outside the boundary* (i.e., wrap-around is not allowed).
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: matrix = [[9,9,4],[6,6,8],[2,1,1]]
|
||||
Output: 4
|
||||
Explanation: The longest increasing path is [1, 2, 6, 9].
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: matrix = [[3,4,5],[3,2,6],[2,2,1]]
|
||||
Output: 4
|
||||
Explanation: The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: matrix = [[1]]
|
||||
Output: 1
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~m == matrix.length~
|
||||
|
||||
- ~n == matrix[i].length~
|
||||
|
||||
- ~1 <= m, n <= 200~
|
||||
|
||||
- ~0 <= matrix[i][j] <= 2^{31} - 1~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def longestIncreasingPath(self, matrix: List[List[int]]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int longestIncreasingPath(vector<vector<int>>& matrix) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,66 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0494. Target Sum :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0494. Target Sum][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0494. Target Sum][0494. Target Sum]]
|
||||
:END:
|
||||
|
||||
You are given an integer array ~nums~ and an integer ~target~.
|
||||
|
||||
You want to build an *expression* out of nums by adding one of the symbols ~'+'~ and ~'-'~ before each integer in nums and then concatenate all the integers.
|
||||
|
||||
- For example, if ~nums = [2, 1]~, you can add a ~'+'~ before ~2~ and a ~'-'~ before ~1~ and concatenate them to build the expression ~"+2-1"~.
|
||||
|
||||
Return the number of different *expressions* that you can build, which evaluates to ~target~.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,1,1,1,1], target = 3
|
||||
Output: 5
|
||||
Explanation: There are 5 ways to assign symbols to make the sum of nums be target 3.
|
||||
-1 + 1 + 1 + 1 + 1 = 3
|
||||
+1 - 1 + 1 + 1 + 1 = 3
|
||||
+1 + 1 - 1 + 1 + 1 = 3
|
||||
+1 + 1 + 1 - 1 + 1 = 3
|
||||
+1 + 1 + 1 + 1 - 1 = 3
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1], target = 1
|
||||
Output: 1
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 20~
|
||||
|
||||
- ~0 <= nums[i] <= 1000~
|
||||
|
||||
- ~0 <= sum(nums[i]) <= 1000~
|
||||
|
||||
- ~-1000 <= target <= 1000~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def findTargetSumWays(self, nums: List[int], target: int) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int findTargetSumWays(vector<int>& nums, int target) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,75 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0518. Coin Change II :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0518. Coin Change II][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0518. Coin Change II][0518. Coin Change II]]
|
||||
:END:
|
||||
|
||||
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:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
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
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: amount = 3, coins = [2]
|
||||
Output: 0
|
||||
Explanation: the amount of 3 cannot be made up just with coins of 2.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: amount = 10, coins = [10]
|
||||
Output: 1
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= coins.length <= 300~
|
||||
|
||||
- ~1 <= coins[i] <= 5000~
|
||||
|
||||
- All the values of ~coins~ are *unique*.
|
||||
|
||||
- ~0 <= amount <= 5000~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def change(self, amount: int, coins: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int change(int amount, vector<int>& coins) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,68 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 1143. Longest Common Subsequence :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*1143. Longest Common Subsequence][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*1143. Longest Common Subsequence][1143. Longest Common Subsequence]]
|
||||
:END:
|
||||
|
||||
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:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: text1 = "abcde", text2 = "ace"
|
||||
Output: 3
|
||||
Explanation: The longest common subsequence is "ace" and its length is 3.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: text1 = "abc", text2 = "abc"
|
||||
Output: 3
|
||||
Explanation: The longest common subsequence is "abc" and its length is 3.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: text1 = "abc", text2 = "def"
|
||||
Output: 0
|
||||
Explanation: There is no such common subsequence, so the result is 0.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= text1.length, text2.length <= 1000~
|
||||
|
||||
- ~text1~ and ~text2~ consist of only lowercase English characters.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def longestCommonSubsequence(self, text1: str, text2: str) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int longestCommonSubsequence(string text1, string text2) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,73 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 1220. Count Vowels Permutation :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*1220. Count Vowels Permutation][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*1220. Count Vowels Permutation][1220. Count Vowels Permutation]]
|
||||
:END:
|
||||
|
||||
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:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: n = 1
|
||||
Output: 5
|
||||
Explanation: All possible strings are: "a", "e", "i" , "o" and "u".
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: n = 2
|
||||
Output: 10
|
||||
Explanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3: *
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: n = 5
|
||||
Output: 68
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= n <= 2 * 10^4~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def countVowelPermutation(self, n: int) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int countVowelPermutation(int n) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
+53
-3
@@ -1,18 +1,68 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 1911. Maximum Alternating Subsequence Sum :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*1911. Maximum Alternating Subsequence Sum][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*1911. Maximum Alternating Subsequence Sum][1911. Maximum Alternating Subsequence Sum]]
|
||||
:END:
|
||||
|
||||
The *alternating sum* of a *0-indexed* array is defined as the *sum* of the elements at *even* indices *minus* the *sum* of the elements at *odd* indices.
|
||||
|
||||
- For example, the alternating sum of ~[4,2,5,3]~ is ~(4 + 5) - (2 + 3) = 4~.
|
||||
|
||||
Given an array ~nums~, return /the *maximum alternating sum* of any subsequence of /~nums~/ (after *reindexing* the elements of the subsequence)/.
|
||||
|
||||
A *subsequence* of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, ~[2,7,4]~ is a subsequence of ~[4,2,3,7,2,1,4]~ (the underlined elements), while ~[2,4,2]~ is not.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [4,2,5,3]
|
||||
Output: 7
|
||||
Explanation: It is optimal to choose the subsequence [4,2,5] with alternating sum (4 + 5) - 2 = 7.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [5,6,7,8]
|
||||
Output: 8
|
||||
Explanation: It is optimal to choose the subsequence [8] with alternating sum 8.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [6,2,1,2,4,5]
|
||||
Output: 10
|
||||
Explanation: It is optimal to choose the subsequence [6,1,5] with alternating sum (6 + 5) - 1 = 10.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 10^{5}~
|
||||
|
||||
- ~1 <= nums[i] <= 10^{5}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def maxAlternatingSum(self, nums: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
long long maxAlternatingSum(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user