question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
construct-the-minimum-bitwise-array-i | C# Linq 1 line | c-linq-1-line-by-gbamqzkdyg-xgij | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\ncsharp []\npublic class Solution {\n public int[] MinBitwiseArray(IList<int> num | gbamqzkdyg | NORMAL | 2024-10-14T08:13:32.961343+00:00 | 2024-10-14T08:13:32.961377+00:00 | 7 | false | # Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```csharp []\npublic class Solution {\n public int[] MinBitwiseArray(IList<int> nums) => nums.Select(num => num % 2 == 0 ? -1 : num - ((num + 1) & (-num - 1)) / 2).ToArray();\n}\n``` | 0 | 0 | ['C#'] | 0 |
construct-the-minimum-bitwise-array-i | brute force | brute-force-by-user5285zn-jiuu | \nrust []\nfn f(x: i32) -> i32 {\n for y in 1..x {\n if (y | (y+1)) as i32 == x {return y}\n }\n -1\n}\nimpl Solution {\n pub fn min_bitwise | user5285Zn | NORMAL | 2024-10-14T04:56:38.174853+00:00 | 2024-10-14T04:56:38.174888+00:00 | 1 | false | \n```rust []\nfn f(x: i32) -> i32 {\n for y in 1..x {\n if (y | (y+1)) as i32 == x {return y}\n }\n -1\n}\nimpl Solution {\n pub fn min_bitwise_array(nums: Vec<i32>) -> Vec<i32> {\n nums.into_iter().map(f).collect()\n }\n}\n``` | 0 | 0 | ['Rust'] | 0 |
construct-the-minimum-bitwise-array-i | Min Bitwise Array - JS | min-bitwise-array-js-by-zemamba-g5ft | javascript []\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar minBitwiseArray = function(nums) {\n ans = []\n for (let i = 0; i < nums.le | zemamba | NORMAL | 2024-10-13T20:29:29.510840+00:00 | 2024-10-13T20:29:29.510867+00:00 | 5 | false | ```javascript []\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar minBitwiseArray = function(nums) {\n ans = []\n for (let i = 0; i < nums.length; i++) {\n for (let j = 1; j < nums[i]; j++) {\n if ((j | (j + 1)) == nums[i]) {\n ans.push(j)\n break\n ... | 0 | 0 | ['JavaScript'] | 0 |
construct-the-minimum-bitwise-array-i | See the python solution | see-the-python-solution-by-testcasefail-cg2p | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | TestCaseFail | NORMAL | 2024-10-13T18:25:11.429933+00:00 | 2024-10-13T18:25:11.429953+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
construct-the-minimum-bitwise-array-i | C++ Solution | c-solution-by-user1122v-2dv8 | \n# Code\ncpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int>& nums) {\n for(int i = 0; i < nums.size(); i++){\n in | user1122v | NORMAL | 2024-10-13T17:56:40.686586+00:00 | 2024-10-13T17:56:40.686628+00:00 | 9 | false | \n# Code\n```cpp []\nclass Solution {\npublic:\n vector<int> minBitwiseArray(vector<int>& nums) {\n for(int i = 0; i < nums.size(); i++){\n int flag = 0;\n for(int j = 1; j < nums[i]; j++){\n if((j | (j + 1)) == nums[i]){\n nums[i] = j;\n ... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | [C++/Java/Python] DP Solution O(N^2) | cjavapython-dp-solution-on2-by-lee215-gmg2 | Intuition\ndp[i][j] means the number of possible permutations of first i + 1 digits,\nwhere the i + 1th digit is j + 1th smallest in the rest of unused digits.\ | lee215 | NORMAL | 2018-09-09T03:11:12.918248+00:00 | 2020-01-31T07:54:49.540221+00:00 | 19,948 | false | # Intuition\n`dp[i][j]` means the number of possible permutations of first `i + 1` digits,\nwhere the `i + 1`th digit is `j + 1`th smallest in the rest of unused digits.\n\n\nOk, may not make sense ... Let\'s see the following diagram.\n\n... | 288 | 9 | [] | 49 |
valid-permutations-for-di-sequence | Easy-to-understand solution with detailed explanation | easy-to-understand-solution-with-detaile-jmb5 | \nBefore diving into the state transition function, let us first start with a simple example.\n\n### 1. a simple example\n\nIn the following discussion, for sim | wxd_sjtu | NORMAL | 2018-11-23T07:57:21.259281+00:00 | 2018-11-23T07:57:21.259326+00:00 | 7,633 | false | \nBefore diving into the state transition function, let us first start with a simple example.\n\n### 1. a simple example\n\nIn the following discussion, for simplification, I will use both notation DI-seq and DI-rule instead of DI sequence.\n\nConsider a permutation 1032, which is based on a DI-seq "DID", how to use it... | 164 | 2 | [] | 19 |
valid-permutations-for-di-sequence | Top-down with Memo -> Bottom-up DP -> N^3 DP -> N^2 DP -> O(N) space | top-down-with-memo-bottom-up-dp-n3-dp-n2-f8t1 | Top-down with Memo:\n\nDefinition: helper(String s, Map<String, Long> map): Answer to s.\n\nIntuition: Insert the largest number into appropriate postion.\n\neg | wangzi6147 | NORMAL | 2018-09-09T22:02:54.189890+00:00 | 2018-10-18T02:01:41.061592+00:00 | 5,593 | false | **Top-down with Memo:**\n\nDefinition: `helper(String s, Map<String, Long> map)`: Answer to `s`.\n\nIntuition: Insert the largest number into appropriate postion.\n\neg. `s=\'IIDD\'`, we can only insert `4` between `I` and `D`. We break the remained numbers `0, 1, 2, 3` into two groups both with the size of 2. We have ... | 38 | 1 | [] | 6 |
valid-permutations-for-di-sequence | Share my O(N^3) => O(N^2) C++ DP solution. Including the thoughts of improvement. | share-my-on3-on2-c-dp-solution-including-lsv6 | Came up with the original idea during contest, so might not be the best. But it works.\nc++\nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n | xidui | NORMAL | 2018-09-09T03:20:21.534047+00:00 | 2018-10-17T13:58:10.604683+00:00 | 3,498 | false | Came up with the original idea during contest, so might not be the best. But it works.\n```c++\nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n int N = S.length() + 1;\n int MOD = 1e9 + 7;\n // dp[i][j] number of permutation whose length is i and end with j\n int dp[202][... | 25 | 1 | [] | 6 |
valid-permutations-for-di-sequence | How to define the DP states (with clear picture explanation) | how-to-define-the-dp-states-with-clear-p-2w5m | When I tried to understand lee215\'s solution, I got stuck. Then I redescribe this process to better understand the whole process. Credits go to lee215. \nThe | liketheflower | NORMAL | 2020-07-02T03:46:16.981643+00:00 | 2021-06-17T18:54:53.931041+00:00 | 2,190 | false | When I tried to understand lee215\'s [solution](https://leetcode.com/problems/valid-permutations-for-di-sequence/discuss/168278/C++JavaPython-DP-Solution-O(N2)), I got stuck. Then I redescribe this process to better understand the whole process. Credits go to lee215. \nThe intuition is: given a string s, results of th... | 21 | 2 | [] | 4 |
valid-permutations-for-di-sequence | Python DP approach (+ some Explanation) | python-dp-approach-some-explanation-by-w-1io4 | Most of us here are preparing for programming Interviews and those interviews have a threshold of about 45 minutes, and you have to come-up with an approach, wr | wizard_ | NORMAL | 2020-06-27T06:31:12.855432+00:00 | 2020-06-27T06:31:12.855480+00:00 | 888 | false | Most of us here are preparing for programming Interviews and those interviews have a threshold of about 45 minutes, and you have to come-up with an approach, write code, and explain. If you spend some time on the discuss section, you will realize there are some awesome solutions, which take you more than an interview-t... | 17 | 1 | [] | 1 |
valid-permutations-for-di-sequence | Python O(N^3)/O(N^2) time O(N) space DP solution with clear explanation (no "relative rank" stuff) | python-on3on2-time-on-space-dp-solution-atmk5 | Since I didn\'t understand the relative rank stuff, I found this problem to be quite confusing until I saw this thread:\nhttps://leetcode.com/problems/valid-per | wynning | NORMAL | 2018-10-27T23:35:39.578844+00:00 | 2018-10-27T23:35:39.578883+00:00 | 1,096 | false | Since I didn\'t understand the relative rank stuff, I found this problem to be quite confusing until I saw this thread:\nhttps://leetcode.com/problems/valid-permutations-for-di-sequence/discuss/169126/Visualization-Key-to-the-DP-solution:-imagine-cutting-a-piece-of-paper-and-separating-the-halves\n\n**Property: If we i... | 10 | 1 | [] | 2 |
valid-permutations-for-di-sequence | Why Backtracking + Memoization is working ?? | why-backtracking-memoization-is-working-ac2j0 | To all Coders of the Leetcode Community this post needs to be addressed \nwhy this solution is working ??\n```\nclass Solution {\npublic:\n \n int mod = 1 | njcoder | NORMAL | 2022-07-06T14:04:29.998988+00:00 | 2022-07-06T14:04:50.661159+00:00 | 889 | false | To all Coders of the Leetcode Community this post needs to be addressed \nwhy this solution is working ??\n```\nclass Solution {\npublic:\n \n int mod = 1e9 + 7;\n \n int n;\n \n vector<int> vis;\n \n int dp[202][202];\n \n long long func(int i,int j,string &s){\n if(i == n) return ... | 9 | 1 | [] | 1 |
valid-permutations-for-di-sequence | C++ | Memoization | Backtracking | Easy | c-memoization-backtracking-easy-by-vaibh-qv4e | \nclass Solution {\npublic:\n int vis[201];\n long long int dp[202][202];\n int mod=1000000007;\n int util(string &s,int index,int prev){\n i | vaibhavagrwal | NORMAL | 2021-06-20T17:04:28.950693+00:00 | 2021-06-20T17:04:28.950739+00:00 | 1,437 | false | ```\nclass Solution {\npublic:\n int vis[201];\n long long int dp[202][202];\n int mod=1000000007;\n int util(string &s,int index,int prev){\n if(index==s.size()) return 1;\n \n if(dp[index][prev]!=-1) return dp[index][prev];\n \n long long int cnt=0;\n if(s[index]=... | 7 | 0 | ['Dynamic Programming', 'Backtracking', 'Memoization', 'C'] | 3 |
valid-permutations-for-di-sequence | C++ Soln || BackTracking + DP | c-soln-backtracking-dp-by-mitedyna-mo08 | \n#define mod 1000000007;\nclass Solution {\npublic:\n vector<int> vis;\n int dp[201][202];\n int sol(string &s, int ind, int prev){\n if(ind==s | mitedyna | NORMAL | 2021-06-04T21:54:43.898302+00:00 | 2021-06-04T21:54:43.898341+00:00 | 949 | false | ```\n#define mod 1000000007;\nclass Solution {\npublic:\n vector<int> vis;\n int dp[201][202];\n int sol(string &s, int ind, int prev){\n if(ind==s.length()+1){return 1;}\n if(dp[ind][prev+1]!=-1)return dp[ind][prev+1];\n long ans=0;\n for(int i=0;i<=s.length();i++){\n if... | 6 | 1 | ['Dynamic Programming', 'Backtracking', 'C'] | 2 |
valid-permutations-for-di-sequence | DP O(N^2), Space O(N), With intuitive walkthrough about how to derive it. | dp-on2-space-on-with-intuitive-walkthrou-tkaa | Knowing that we only have to figure out how many permutaitons there are, I stopped thinking about index orders, and instead thought about paths.\n\nConceptually | johnb003 | NORMAL | 2020-10-04T04:51:45.745883+00:00 | 2020-10-04T04:51:45.745957+00:00 | 689 | false | Knowing that we only have to figure out how many permutaitons there are, I stopped thinking about index orders, and instead thought about paths.\n\nConceptually, with D alone there\'s only one path.\n\n```\n * \n \\\n * (ending)\n ```\n \n If we do DI, then the up path can end either between the existing two nodes... | 6 | 1 | [] | 0 |
valid-permutations-for-di-sequence | Java DFS with memo | java-dfs-with-memo-by-mostlyjoking-thyy | \n\nclass Solution {\n private static int MOD = 1000000007;\n public int numPermsDISequence(String S) {\n int res = 0;\n Integer[][] dp = ne | mostlyjoking | NORMAL | 2020-05-25T20:03:00.952317+00:00 | 2020-05-25T20:03:00.952374+00:00 | 804 | false | \n```\nclass Solution {\n private static int MOD = 1000000007;\n public int numPermsDISequence(String S) {\n int res = 0;\n Integer[][] dp = new Integer[S.length() + 1][S.length() + 1];\n \n for (int i = 0; i <= S.length(); i++) {\n res += dfs(i, S.length() - i, dp, S, 0);\n... | 5 | 0 | [] | 3 |
valid-permutations-for-di-sequence | Java sol | java-sol-by-cuny-66brother-8i9i | \nclass Solution {\n int mod=1000000007;\n long dp[][];\n public int numPermsDISequence(String s) {//i: string index end: end with number end\n | CUNY-66brother | NORMAL | 2020-05-01T11:46:30.108331+00:00 | 2020-05-01T11:46:30.108365+00:00 | 625 | false | ```\nclass Solution {\n int mod=1000000007;\n long dp[][];\n public int numPermsDISequence(String s) {//i: string index end: end with number end\n int len=s.length();\n long res=0;\n dp=new long[len+1][len+1];\n dp[0][0]=1;\n for(int i=1;i<=s.length();i++){\n cha... | 4 | 0 | [] | 0 |
valid-permutations-for-di-sequence | Backtracking to DP Java Solution | backtracking-to-dp-java-solution-by-nave-0fw0 | Idea\nWe will try all possibilities for all positions and backtracking when we can\'t go further. seen maintains the visited numbers in per recursion tree branc | naveen_kothamasu | NORMAL | 2019-05-10T01:11:45.153681+00:00 | 2019-05-10T01:16:08.057815+00:00 | 745 | false | **Idea**\nWe will try all possibilities for all positions and backtracking when we can\'t go further. `seen` maintains the visited numbers in per recursion tree branch.\n\n**Solution1** **TLE**\n```\nclass Solution {\n int[] seen = null;\n public int numPermsDISequence(String s) {\n seen = new int[s.length... | 4 | 0 | [] | 1 |
valid-permutations-for-di-sequence | Backtracking+memoization is working . Why?? | backtrackingmemoization-is-working-why-b-9hjf | Doubt\n Since to decide a unique state , we need:\n\n 1.index at which we are currently in string s\n 2.previous element chosen\n | anupamraZ | NORMAL | 2023-04-08T04:56:30.258408+00:00 | 2023-04-08T04:56:30.258438+00:00 | 302 | false | # Doubt\n Since to decide a unique state , we need:\n\n 1.index at which we are currently in string s\n 2.previous element chosen\n 3.set of numbers that are used or left.Here vis vector.\n\n But i have done memoization over first two, but the soln is working.Can\'t understand why??... | 3 | 0 | ['Backtracking', 'Memoization', 'C++'] | 0 |
valid-permutations-for-di-sequence | MEMO/C++ | memoc-by-anurag852001-3ew7 | \tclass Solution {\n\tpublic:\n int dp[201][201];\n int mod=1e9+7;\n int util(string &s,vector&visited,int curr,int index,int n){\n if(index==s. | anurag852001 | NORMAL | 2022-06-15T10:24:04.288640+00:00 | 2022-06-15T10:24:04.288686+00:00 | 794 | false | \tclass Solution {\n\tpublic:\n int dp[201][201];\n int mod=1e9+7;\n int util(string &s,vector<int>&visited,int curr,int index,int n){\n if(index==s.length())\n return 1;\n if(dp[curr][index]!=-1)\n return dp[curr][index];\n int res=0;\n visited[curr]=true;\n ... | 3 | 0 | ['Dynamic Programming'] | 1 |
valid-permutations-for-di-sequence | Detailed explanation and intuition | detailed-explanation-and-intuition-by-se-4a7p | Intuition\n\nThe possible lengths of s, and the fact that there\'s a modulo involved, hints that were dealing with some sort of recursive function.\n\nIndeed, w | sebnyberg | NORMAL | 2022-11-05T14:51:59.733483+00:00 | 2022-11-05T15:03:13.975716+00:00 | 429 | false | # Intuition\n\nThe possible lengths of `s`, and the fact that there\'s a modulo involved, hints that were dealing with some sort of recursive function.\n\nIndeed, we have a very large number of alternatives for each step. For a 200 character string, there are 200 valid first choices to explore (some of which may later ... | 2 | 0 | ['Go'] | 0 |
valid-permutations-for-di-sequence | Python|DP|10 lines of code| Detailed comments | pythondp10-lines-of-code-detailed-commen-q6qd | ```\ndef numPermsDISequence(self, s: str) -> int:\n n = len(s)\n \n # len(dp) is the length of remaining unused set as remain_set\n | user5318zb | NORMAL | 2022-05-12T04:29:20.046687+00:00 | 2022-05-12T04:29:20.046727+00:00 | 528 | false | ```\ndef numPermsDISequence(self, s: str) -> int:\n n = len(s)\n \n # len(dp) is the length of remaining unused set as remain_set\n # dp[i] means the last digit of any permutation formed by used set is remain_set[i]\n # so, initially, remain_set = [0, 1, ..,n]\n # dp[i] = 1\n ... | 2 | 0 | [] | 0 |
valid-permutations-for-di-sequence | C++ | DFS + MEMO | c-dfs-memo-by-kumarabhi98-v0se | \nclass Solution {\npublic:\n int mod = 1e9+7;\n int dfs(vector<vector<int>> &dp,vector<bool> &vis,string &s,int in,int n,int last){\n if(in>=s.siz | kumarabhi98 | NORMAL | 2022-03-24T17:11:27.424880+00:00 | 2022-03-24T17:11:27.424923+00:00 | 575 | false | ```\nclass Solution {\npublic:\n int mod = 1e9+7;\n int dfs(vector<vector<int>> &dp,vector<bool> &vis,string &s,int in,int n,int last){\n if(in>=s.size()) return 1;\n if(dp[in][last]!=-1) return dp[in][last];\n if(s[in]==\'D\'){ \n long re = 0;\n for(int i = 0; i<last; ... | 2 | 0 | ['Dynamic Programming', 'C'] | 1 |
valid-permutations-for-di-sequence | Python3 divide and conquer solution, slightly quicker than official divide and conquer solution | python3-divide-and-conquer-solution-slig-apg8 | \nfrom functools import lru_cache\n\n\nclass Solution:\n def __init__(self):\n self.mod = 10 ** 9 + 7\n\n @lru_cache(maxsize=None)\n def nCk(sel | cava | NORMAL | 2019-12-04T07:19:37.417556+00:00 | 2019-12-04T07:19:37.417595+00:00 | 432 | false | ```\nfrom functools import lru_cache\n\n\nclass Solution:\n def __init__(self):\n self.mod = 10 ** 9 + 7\n\n @lru_cache(maxsize=None)\n def nCk(self, n, k):\n if k == 1: return n\n if k == 0 or n == k: return 1\n return self.nCk(n - 1, k - 1) + self.nCk(n - 1, k)\n\n @lru_cache(m... | 2 | 2 | ['Divide and Conquer', 'Python3'] | 1 |
valid-permutations-for-di-sequence | Python recursive solution(Time out and just for reference) | python-recursive-solutiontime-out-and-ju-gq2j | \nclass Solution(object):\n def numPermsDISequence(self, S):\n """\n :type S: str\n :rtype: int\n """\n n = len(S)\n | cslzy | NORMAL | 2018-09-09T09:46:46.356936+00:00 | 2018-10-18T02:34:32.677979+00:00 | 335 | false | ```\nclass Solution(object):\n def numPermsDISequence(self, S):\n """\n :type S: str\n :rtype: int\n """\n n = len(S)\n \n def helper(S, D, I):\n if S == \'\': return 1\n sign = S[0]\n S = S[1:]\n \n count = 0\n ... | 2 | 3 | [] | 0 |
valid-permutations-for-di-sequence | C++ || Bactracking || Memoization | c-bactracking-memoization-by-akash92-5blh | Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to explore all possible combinations to get the total count of valid permutatio | akash92 | NORMAL | 2024-09-16T10:34:30.451733+00:00 | 2024-09-16T10:34:30.451756+00:00 | 246 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to explore all possible combinations to get the total count of valid permutations\nFor this we only need previous element and current index to decide current element\n\n# Complexity\n- Time complexity: $$O(n^3)$$\n<!-- Add your ti... | 1 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | ✅Easiest Approach || RECURSIVE -> MEMOIZATION || Jai Shree Ram🚩🚩 | easiest-approach-recursive-memoization-j-8ylo | Approach and Intuition\n- Visualising all the possible permuations and returning only valid ones\n- Taking a prev value which checks the prev value taken , now | vermayugam_29 | NORMAL | 2024-04-28T19:38:35.017352+00:00 | 2024-04-28T19:38:35.017372+00:00 | 236 | false | # Approach and Intuition\n- Visualising all the possible permuations and returning only valid ones\n- Taking a prev value which checks the prev value taken , now if prev is -1 this means we can taking any integer .\n- If `s[i] == \'I\'` then we need to take only that element which is not visited yet and is `> than prev... | 1 | 1 | ['Dynamic Programming', 'Backtracking', 'Recursion', 'Python', 'C++', 'Java', 'Python3'] | 1 |
valid-permutations-for-di-sequence | explained why backtrack + memorization working | explained-why-backtrack-memorization-wor-hssz | why it works without explicitly saving the state of the visited array?\n\n\nWhen we backtrack and return from a recursive call, we reset _ visited[curr] to fals | demon_code | NORMAL | 2023-09-15T20:38:42.767177+00:00 | 2023-09-15T20:38:42.767205+00:00 | 404 | false | why it works without explicitly saving the state of the visited array?\n\n\nWhen we backtrack and return from a recursive call, we reset ```_ visited[curr] to false _``` which means that the state of visited is restored to what it was before the recursive call.\n\nThe memoization table dp is used to store and retrieve ... | 1 | 0 | ['Backtracking', 'Memoization', 'C'] | 0 |
valid-permutations-for-di-sequence | Solution | solution-by-deleted_user-btew | C++ []\nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n int n = S.length(), mod = 1e9 + 7;\n vector<vector<int>> dp(n + 1, | deleted_user | NORMAL | 2023-05-11T22:05:47.224145+00:00 | 2023-05-11T22:18:32.504069+00:00 | 267 | false | ```C++ []\nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n int n = S.length(), mod = 1e9 + 7;\n vector<vector<int>> dp(n + 1, vector<int>(n + 1));\n for (int j = 0; j <= n; j++) dp[0][j] = 1;\n for (int i = 0; i < n; i++)\n if (S[i] == \'I\')\n ... | 1 | 1 | ['C++', 'Java', 'Python3'] | 0 |
valid-permutations-for-di-sequence | DP Solution | dp-solution-by-garima1501-3qr2 | To add a new character to a sequence we only have to consider the last element-\n\nLets say currently DID sequence is 1032- this can form\n\nDIDI - in cases whe | garima1501 | NORMAL | 2022-10-02T06:55:30.737862+00:00 | 2022-10-02T07:01:45.913923+00:00 | 386 | false | To add a new character to a sequence we only have to consider the last element-\n\nLets say currently DID sequence is 1032- this can form\n\nDIDI - in cases where we end with 3,4\nDIDD - in cases where we end with 0,1,2\n\nSo just use the last element value to create a new sequence.\n\n```\nclass Solution:\n def num... | 1 | 0 | ['Python3'] | 0 |
valid-permutations-for-di-sequence | Python solution: tricky question | python-solution-tricky-question-by-huiki-6wb2 | \nclass Solution:\n # an implicit DP problem\n # For simplicity, let\'s consider the sequence "D"\n # So we have the sequences [0,1] to permute\n # | huikinglam02 | NORMAL | 2022-07-25T22:30:33.523858+00:00 | 2022-07-25T22:31:01.982591+00:00 | 244 | false | ```\nclass Solution:\n # an implicit DP problem\n # For simplicity, let\'s consider the sequence "D"\n # So we have the sequences [0,1] to permute\n # The valid permutation is [1,0]\n # Now let\'s go to "DI", we add the number 2\n # and let\'s separate the cases in which the sequence ends with differe... | 1 | 0 | [] | 0 |
valid-permutations-for-di-sequence | Beats 100% Other's Solutions | beats-100-others-solutions-by-day_trippe-qzg3 | \nclass Solution:\n def numPermsDISequence(self, S: str) -> int:\n dp = [1] * (len(S) + 1)\n for a, b in zip(\'I\' + S, S):\n dp = l | Day_Tripper | NORMAL | 2022-07-17T06:54:39.101665+00:00 | 2022-07-17T06:54:39.101832+00:00 | 246 | false | ```\nclass Solution:\n def numPermsDISequence(self, S: str) -> int:\n dp = [1] * (len(S) + 1)\n for a, b in zip(\'I\' + S, S):\n dp = list(itertools.accumulate(dp[:-1] if a == b else dp[-1:0:-1]))\n return dp[0] % (10**9 + 7)\n``` | 1 | 0 | [] | 0 |
valid-permutations-for-di-sequence | [Python3] top-down dp | python3-top-down-dp-by-ye15-7hl9 | \n\nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n \n @cache \n def fn(i, x): \n """Return number of valid | ye15 | NORMAL | 2021-06-09T20:27:53.897620+00:00 | 2021-06-09T20:27:53.897664+00:00 | 553 | false | \n```\nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n \n @cache \n def fn(i, x): \n """Return number of valid permutation given x numbers smaller than previous one."""\n if i == len(s): return 1 \n if s[i] == "D": \n if x == 0: re... | 1 | 0 | ['Python3'] | 3 |
valid-permutations-for-di-sequence | Simple C++ solution | simple-c-solution-by-caspar-chen-hku-tnde | \nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n int n = S.length(), mod = 1e9 + 7;\n vector<vector<int>> dp(n + 1, vector<in | caspar-chen-hku | NORMAL | 2020-05-22T09:43:41.729001+00:00 | 2020-05-22T09:43:41.729036+00:00 | 388 | false | ```\nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n int n = S.length(), mod = 1e9 + 7;\n vector<vector<int>> dp(n + 1, vector<int>(n + 1));\n for (int j = 0; j <= n; j++){\n dp[0][j] = 1;\n } \n for (int i = 0; i < n; i++){\n if (S[i] == \'I\... | 1 | 0 | [] | 2 |
valid-permutations-for-di-sequence | C++ DP 100%/100% | c-dp-100100-by-tkwind-o8sp | I highly doubt if this is a real interview question or merely from contest, which adopts ideas/techniques in some fields. \n \nThe main challege to apply DP is | tkwind | NORMAL | 2020-01-26T00:12:13.521917+00:00 | 2020-01-26T00:14:24.060978+00:00 | 405 | false | I highly doubt if this is a real interview question or merely from contest, which adopts ideas/techniques in some fields. \n \nThe main challege to apply DP is the state space is too large, if remembering which numbers have been assigned. This challenge can be overcomed by using ranking. For people with background in d... | 1 | 0 | [] | 2 |
valid-permutations-for-di-sequence | [JAVA] DFS with memo | java-dfs-with-memo-by-flyflyflyalex-nseo | \'\'\'\n\n\tclass Solution {\n\t\tint MOD = (int)1e9 + 7;\n\t\tpublic int numPermsDISequence(String s) {\n\t\t\tif (s == null || s.length() == 0) {\n\t\t\t\tret | flyflyflyalex | NORMAL | 2020-01-16T22:58:10.285566+00:00 | 2020-01-28T00:26:05.587467+00:00 | 336 | false | \'\'\'\n\n\tclass Solution {\n\t\tint MOD = (int)1e9 + 7;\n\t\tpublic int numPermsDISequence(String s) {\n\t\t\tif (s == null || s.length() == 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tSet<Integer> hashSet = new HashSet<>();\n\t\t\tfor (int i = 0; i <= s.length(); i++) {\n\t\t\t\thashSet.add(i);\n\t\t\t}\n\n\t\t\tlong re... | 1 | 0 | [] | 0 |
valid-permutations-for-di-sequence | Java Solution !!! | java-solution-by-kylewzk-f3i9 | \n public int numPermsDISequence(String S) {\n int len = S.length(), N = len + 1, mod = 1000000007;\n int[][] dp = new int[N+1][N];\n \n | kylewzk | NORMAL | 2019-03-18T05:44:24.123336+00:00 | 2019-03-18T05:44:24.123384+00:00 | 556 | false | ```\n public int numPermsDISequence(String S) {\n int len = S.length(), N = len + 1, mod = 1000000007;\n int[][] dp = new int[N+1][N];\n \n for(int i = 0; i < N; i++) dp[1][i] = 1;\n \n for(int i = 1; i <= len; i++) {\n if(S.charAt(i-1) == \'D\') for(int j = N - i... | 1 | 0 | [] | 0 |
valid-permutations-for-di-sequence | 10 lines C++, Time O(n^2), Space O(n), with remark | 10-lines-c-time-on2-space-on-with-remark-p266 | C++\n// K(s, x) = nums of perms with tail ranking x\n// K(s + \'I\') = K(s, x) + K(s, x+1) + ... + K(s, s.len)\n// K(s + \'D\') = K(s, 0) + K(s, 1) + ... + K(s, | pjincz | NORMAL | 2018-11-29T08:28:01.202452+00:00 | 2018-11-29T08:28:01.202511+00:00 | 450 | false | ```C++\n// K(s, x) = nums of perms with tail ranking x\n// K(s + \'I\') = K(s, x) + K(s, x+1) + ... + K(s, s.len)\n// K(s + \'D\') = K(s, 0) + K(s, 1) + ... + K(s, x - 1)\n\n// G(s, 0) = 0\n// G(s, x) = K(s, 0) + K(s, 1) + ... + K(s, x - 1)\n\n// K(s + \'I\') = K(s, x) + K(s, x+1) + ... + K(s, s.len) = G(s, s.len + 1) ... | 1 | 1 | [] | 1 |
valid-permutations-for-di-sequence | C++ STL partial_sum, 0ms | c-stl-partial_sum-0ms-by-0xffffffff-9bma | class Solution {\n public:\n int numPermsDISequence(string S) {\n int n = S.size() + 1, d = 0, i = 0;\n vector<int> arr(n, 1);\n | 0xffffffff | NORMAL | 2018-09-09T23:32:58.083920+00:00 | 2018-09-17T08:21:41.759783+00:00 | 378 | false | class Solution {\n public:\n int numPermsDISequence(string S) {\n int n = S.size() + 1, d = 0, i = 0;\n vector<int> arr(n, 1);\n auto func = [](int a, int b) { return (a + b) % 1000000007; };\n for (char c : S) {\n if (c == \'D\') {\n ... | 1 | 1 | [] | 1 |
valid-permutations-for-di-sequence | C++ O(n^2) solution with only one 1D array. Extremely intuitive detailed thought process | c-on2-solution-with-only-one-1d-array-ex-3wje | \nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n int MOD = 1e9 + 7;\n deque<int> memo;\n memo.push_back(1);\n f | chenbai10 | NORMAL | 2018-09-09T06:04:04.474024+00:00 | 2018-09-09T06:04:04.474078+00:00 | 519 | false | ```\nclass Solution {\npublic:\n int numPermsDISequence(string S) {\n int MOD = 1e9 + 7;\n deque<int> memo;\n memo.push_back(1);\n for (int i = 0; i < S.size(); i++) {\n if (S[i] == \'D\') {\n memo.push_back(0);\n for (int j = i; j >= 0; j--) {\n ... | 1 | 1 | [] | 1 |
valid-permutations-for-di-sequence | DP, DFS up and down | dp-dfs-up-and-down-by-luudanhhieu-6rjj | Approach
n := len(s), up + down + start = n
DP dp := make([][]int, n+1) caching for process at index start with up and down is meaning for total greater and les | luudanhhieu | NORMAL | 2025-04-04T16:14:58.540682+00:00 | 2025-04-04T16:14:58.540682+00:00 | 1 | false | # Approach
- `n := len(s)`, `up + down + start = n`
- DP `dp := make([][]int, n+1)` caching for process at index `start` with `up` and `down` is meaning for total greater and less than number is picking at index `start`.
# Complexity
- Time complexity:O(n^2)
- Space complexity:O(n^2)
# Code
```golang []
func numPer... | 0 | 0 | ['Go'] | 0 |
valid-permutations-for-di-sequence | C++ dfs dp memo | c-dp-memo-by-user5976fh-8kpe | null | user5976fh | NORMAL | 2025-03-10T00:57:38.451127+00:00 | 2025-03-10T00:58:22.839421+00:00 | 8 | false | ```cpp []
class Solution {
public:
vector<vector<int>> dp;
const int m = 1e9 + 7;
string s;
int numPermsDISequence(string str) {
s = str;
int n = s.size();
dp.resize(n, vector<int>(n + 1, -1));
int ans = 0;
for (int i = 0; i <= n; ++i){
ans = (ans... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | Optimizing DI Sequence Permutations: A Python & C++ Dynamic Programming Solution 🚀🔥 | optimizing-di-sequence-permutations-a-py-m0od | Intuition 🤔The problem revolves around arranging a permutation of numbers based on D (descending) and I (ascending) constraints. Using dynamic programming, we c | py_rex_47 | NORMAL | 2025-02-09T13:33:17.837559+00:00 | 2025-02-09T13:33:17.837559+00:00 | 11 | false | # Intuition 🤔
The problem revolves around arranging a permutation of numbers based on `D` (descending) and `I` (ascending) constraints. Using dynamic programming, we can keep track of valid permutations for each step and build the solution iteratively.
# Approach 🛠️
- Use a 2D DP table, where `dp[i][j]` represents t... | 0 | 0 | ['String', 'Dynamic Programming', 'Python', 'C++', 'Python3'] | 0 |
valid-permutations-for-di-sequence | In depth explanation of relative ranking approach (Base case + State transition + Answer) . | in-depth-explanation-of-relative-ranking-dkpg | IntuitionFirstly, let's define the dp state and then understand its meaning in depth .
dp[i][j] here represents the number of ways to constuct the permutation u | _rkpro | NORMAL | 2025-01-25T04:24:13.556464+00:00 | 2025-01-25T04:24:13.556464+00:00 | 9 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Firstly, let's define the $$dp$$ state and then understand its meaning in depth .
$$dp[i][j]\ $$here represents the number of ways to constuct the permutation using numbers from $$0$$ to $$i$$ and the $$(i+1)^{th}$$ number of this permutati... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | DP - All possible permutations | dp-all-possible-permutations-by-vats_lc-mqxd | Code | vats_lc | NORMAL | 2025-01-04T13:30:31.666121+00:00 | 2025-01-04T13:30:31.666121+00:00 | 8 | false | # Code
```cpp []
const int MOD = 1e9 + 7;
class Solution {
public:
int getAns(int i, int n, char ch, int num, string& s, vector<int>& count,
vector<vector<int>>& dp) {
if (i == n) {
for (int j = 0; j <= n; j++)
if (count[j] == 1) {
if (ch == 'D'... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | 903. Valid Permutations for DI Sequence | 903-valid-permutations-for-di-sequence-b-cnlv | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-02T02:51:43.906811+00:00 | 2025-01-02T02:51:43.906811+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | EASY DP || C++ || 👍✅ | easy-dp-c-by-athar4403-b1j8 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Athar4403 | NORMAL | 2024-10-18T05:10:59.441929+00:00 | 2024-10-18T05:10:59.441963+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(N^3)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N^2)\n<!-- Add your space complexity here, e.g.... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | 903. Valid Permutations for DI Sequence.cpp | 903-valid-permutations-for-di-sequencecp-5mdt | Code\n\nclass Solution {\npublic:\n int MOD = 1e9+7;\n long long dp[202][202];\n long long perms(string &s, int n, int pos, int prev, vector<bool> &vis | 202021ganesh | NORMAL | 2024-08-15T12:15:06.906799+00:00 | 2024-08-15T12:15:06.906831+00:00 | 4 | false | **Code**\n```\nclass Solution {\npublic:\n int MOD = 1e9+7;\n long long dp[202][202];\n long long perms(string &s, int n, int pos, int prev, vector<bool> &visited) {\n if(pos >= n) return 1; \n if(dp[pos][prev] != -1) return dp[pos][prev];\n long long ans = 0;\n for(int i=0;i<=n;i++... | 0 | 0 | ['C'] | 0 |
valid-permutations-for-di-sequence | Dynamic Programming O(n^3) Time Complexity | dynamic-programming-on3-time-complexity-0mxlu | Intuition\n- We can solve this using Dynamic Programming\n- we need to fix valid elements and at the need to check whether we can form a valid permutation or no | yash559 | NORMAL | 2024-08-15T01:36:32.380919+00:00 | 2024-08-15T01:36:32.380946+00:00 | 11 | false | # Intuition\n- We can solve this using Dynamic Programming\n- we need to fix valid elements and at the need to check whether we can form a valid permutation or not \n- if we can then add 1 and check for remaining combinations\n\n# Complexity\n- Time complexity: $$O(n^3)$$\n<!-- Add your time complexity here, e.g. $$O(n... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | help me out please | help-me-out-please-by-lerno_breed-b9ij | \n Describe your first thoughts on how to solve this problem. \n## Why this is not working \n\n\n# Code\n\nclass Solution {\npublic:\n // Brute force\n in | lerno_breed | NORMAL | 2024-07-30T10:15:56.356722+00:00 | 2024-07-30T10:15:56.356757+00:00 | 5 | false | \n<!-- Describe your first thoughts on how to solve this problem. -->\n## Why this is not working \n\n\n# Code\n```\nclass Solution {\npublic:\n // Brute force\n int f(int i, string temp, int prev, string s) {\n int n = s.size();\n if (i == n) {\n \n for (int j = 0; j <= n; j++) {\... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | Valid Permutation For DI sequence | valid-permutation-for-di-sequence-by-nae-iom0 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Naeem_ABD | NORMAL | 2024-07-16T18:19:14.689998+00:00 | 2024-07-16T18:19:14.690034+00:00 | 11 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
valid-permutations-for-di-sequence | Extremely simple, clear & fast, 20 lines, Runtime: 100%, Memory: 100%, O(n²) | extremely-simple-clear-fast-20-lines-run-r9gq | Intuition & Approach\n Describe your first thoughts on how to solve this problem. \n\nInitially I struggled to find a good solution, calculating permutations is | FSGT | NORMAL | 2024-05-28T13:33:16.278833+00:00 | 2024-05-28T13:47:48.835918+00:00 | 15 | false | # Intuition & Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nInitially I struggled to find a good solution, calculating permutations is very expensive, and with a complicated condition it would be difficult to reuse previously calculated permutations if I also need to keep track of whi... | 0 | 0 | ['Recursion', 'Memoization', 'C#'] | 0 |
valid-permutations-for-di-sequence | Combinatorics Approach 2x+ times faster than DP | combinatorics-approach-2x-times-faster-t-7t3h | Intuition\nFirst, we simplify the input into a series of transitions up and down by some amounts. III becomes a transition with +3 and DDDDD represents one with | jmavis | NORMAL | 2024-04-19T23:20:58.119763+00:00 | 2024-04-22T19:56:55.869807+00:00 | 9 | false | # Intuition\nFirst, we simplify the input into a series of transitions up and down by some amounts. III becomes a transition with +3 and DDDDD represents one with -4. Here is a representation of "DDIIIIDDD" with 3 transition points.\n\n \nidx =... | 0 | 0 | ['Python3'] | 0 |
valid-permutations-for-di-sequence | 👍Runtime 598 ms Beats 100.00% of users with Scala | runtime-598-ms-beats-10000-of-users-with-c0zh | Code\n\nobject Solution {\n def numPermsDISequence(s: String): Int = {\n val n = s.length()\n val dp = Array.ofDim[Int](n + 2, 2)\n val | pvt2024 | NORMAL | 2024-04-11T02:27:42.563647+00:00 | 2024-04-11T02:27:42.563666+00:00 | 1 | false | # Code\n```\nobject Solution {\n def numPermsDISequence(s: String): Int = {\n val n = s.length()\n val dp = Array.ofDim[Int](n + 2, 2)\n val mod = 1000000007\n dp(1)(0) = 1\n\n for (i <- 1 to n) {\n if (s.charAt(i - 1) == \'I\') {\n for (j <- 0 to i) dp(j ... | 0 | 0 | ['Scala'] | 0 |
valid-permutations-for-di-sequence | Solution Valid Permutations for DI Sequence | solution-valid-permutations-for-di-seque-6wj3 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Suyono-Sukorame | NORMAL | 2024-03-03T13:57:50.479317+00:00 | 2024-03-03T13:57:50.479345+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['PHP'] | 0 |
valid-permutations-for-di-sequence | The constraint is sort of too loose for backtracking to pass | the-constraint-is-sort-of-too-loose-for-3ouxc | Code\n\nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n N = len(s)+1\n seen = set([])\n @cache\n def dp(i,prev): | MaxOrgus | NORMAL | 2024-02-27T04:15:46.468555+00:00 | 2024-02-27T04:15:46.468578+00:00 | 9 | false | # Code\n```\nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n N = len(s)+1\n seen = set([])\n @cache\n def dp(i,prev):\n if i == N-1:\n return 1\n res = 0\n if prev == -1:\n for k in range(N):\n ... | 0 | 0 | ['Backtracking', 'Python3'] | 0 |
valid-permutations-for-di-sequence | revised_backtrack... | revised_backtrack-by-aman_17000s-flj2 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | aman_17000s | NORMAL | 2024-02-24T10:48:51.642920+00:00 | 2024-02-24T10:48:51.642955+00:00 | 11 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Backtracking', 'C++'] | 0 |
valid-permutations-for-di-sequence | Dynamic Programming for Permutations with DI Sequence | dynamic-programming-for-permutations-wit-8p1r | Intuition\nThe problem involves finding the number of valid permutations based on a given string s, where \'I\' indicates that the next digit should be greater, | davitacols | NORMAL | 2024-02-23T21:38:03.963171+00:00 | 2024-02-23T21:38:03.963208+00:00 | 9 | false | # Intuition\nThe problem involves finding the number of valid permutations based on a given string `s`, where \'I\' indicates that the next digit should be greater, and \'D\' indicates that the next digit should be smaller. The intuition is to use dynamic programming to build a 2D array `dp` to keep track of the number... | 0 | 0 | ['Python'] | 0 |
valid-permutations-for-di-sequence | Efficient JS solution - DP O(N^2) (Beat 100% time) | efficient-js-solution-dp-on2-beat-100-ti-7xdi | \n\nPro tip: Xi\xE8 \uD83D\uDC9C She\'s really cute tho.\n\n# Complexity\n- Time complexity: O(n^2)\n- Space complexity: O(n)\n\n# Code\njs\nlet MOD = 100000000 | CuteTN | NORMAL | 2024-01-30T02:33:17.476018+00:00 | 2024-01-30T02:33:17.476051+00:00 | 6 | false | \n\nPro tip: Xi\xE8 \uD83D\uDC9C She\'s really cute tho.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```js\nlet MOD = 1000000007;\nlet pre = new Uint32Array(201);... | 0 | 0 | ['Dynamic Programming', 'JavaScript'] | 0 |
valid-permutations-for-di-sequence | ✅ C++ Solution DP Memoization ✅ | c-solution-dp-memoization-by-atom-1-grrh | \n\n# Code\n\nclass Solution {\npublic:\n int mod = 1e9+7;\n int solve(int i,int ind, string &s,vector<int> &visited,vector<vector<int>> &dp){\n if | atom-1 | NORMAL | 2024-01-08T13:12:50.506281+00:00 | 2024-01-08T13:12:50.506318+00:00 | 76 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int mod = 1e9+7;\n int solve(int i,int ind, string &s,vector<int> &visited,vector<vector<int>> &dp){\n if(ind==s.size()) return 1;\n\n if(dp[i][ind]!=-1) return dp[i][ind];\n\n long long int ans = 0;\n if(s[ind]==\'I\'){\n for(... | 0 | 0 | ['String', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
valid-permutations-for-di-sequence | python DP top down + backtracking | python-dp-top-down-backtracking-by-harry-nkyl | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | harrychen1995 | NORMAL | 2023-11-21T16:09:23.367090+00:00 | 2023-11-21T16:09:23.367120+00:00 | 20 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Dynamic Programming', 'Backtracking', 'Python3'] | 0 |
valid-permutations-for-di-sequence | Dynamic programming with top to down approach | dynamic-programming-with-top-to-down-app-qiso | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | geeknkta | NORMAL | 2023-11-01T06:58:44.300633+00:00 | 2023-11-01T06:58:44.300659+00:00 | 19 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | Dynamic programming with top to down approach | dynamic-programming-with-top-to-down-app-5qgp | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | geeknkta | NORMAL | 2023-11-01T06:58:43.006844+00:00 | 2023-11-01T06:58:43.006871+00:00 | 10 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | java easy memoization after recursion | DP | java-easy-memoization-after-recursion-dp-hrn7 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | vishal_113 | NORMAL | 2023-10-25T18:53:49.482344+00:00 | 2023-10-25T18:53:49.482363+00:00 | 97 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 0 |
valid-permutations-for-di-sequence | simple easy to understand c++ solution | simple-easy-to-understand-c-solution-by-n5euk | class Solution {\npublic:\n int numPermsDISequence(string s) {\n constexpr int mod=1\'000\'000\'007;\n int n=s.length();\n vector>DP(n+1 | ar2609034 | NORMAL | 2023-10-17T14:07:23.286734+00:00 | 2023-10-17T14:07:23.286753+00:00 | 4 | false | class Solution {\npublic:\n int numPermsDISequence(string s) {\n constexpr int mod=1\'000\'000\'007;\n int n=s.length();\n vector<vector<int>>DP(n+1, vector<int>(n+1));\n for(int i=0;i<=n;++i){\n DP[0][i]=1;\n }\n for(int i=1;i<=n;++i){\n if(s[i-1]==\'I... | 0 | 0 | [] | 0 |
valid-permutations-for-di-sequence | Easiest Solution | easiest-solution-by-kunal7216-lnpl | \n\n# Code\njava []\nclass Solution {\n public int numPermsDISequence(String s) {\n\tint n = s.length();\n\tint[][] dp = new int [n+2][2];\n\tint mod = 10000 | Kunal7216 | NORMAL | 2023-09-24T15:44:42.358383+00:00 | 2023-09-24T15:44:42.358405+00:00 | 68 | false | \n\n# Code\n```java []\nclass Solution {\n public int numPermsDISequence(String s) {\n\tint n = s.length();\n\tint[][] dp = new int [n+2][2];\n\tint mod = 1000000007;\n\tdp[1][0] = 1;\n\tfor(int i = 1; i<=n; i++){\n\t\tif(s.charAt(i-1)==\'I\') {\n\t\t\tfor(int j = 0; j<=i; j++) dp[j+1][i&1]=(dp[j][(i+1)&1] + dp[j][i... | 0 | 0 | ['C++', 'Java'] | 0 |
valid-permutations-for-di-sequence | Editorial-like solution, simple to understand with multiple approaches from Brute-force to optimal | editorial-like-solution-simple-to-unders-ee9v | The problem asks what is the number of valid permutations that follow a string of "DI" instructions, if a number i is used in a podition with \'D\' the next num | itaib2004 | NORMAL | 2023-08-02T09:38:37.534688+00:00 | 2023-08-02T09:38:37.534710+00:00 | 52 | false | The problem asks what is the number of valid permutations that follow a string of `"DI"` instructions, if a number `i` is used in a podition with `\'D\'` the next number must be in the range `0 <= j < i`, likewise if it\'s in an `\'I\'` position the next number must be `i < j <= n` where `n` is the length if the string... | 0 | 0 | ['Python3'] | 0 |
valid-permutations-for-di-sequence | Simple C++ Solution | Dynamic Programming | Recursion | Memoization | simple-c-solution-dynamic-programming-re-55jb | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rj_9999 | NORMAL | 2023-07-07T10:03:50.466912+00:00 | 2023-07-07T10:03:50.466940+00:00 | 77 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 1 |
valid-permutations-for-di-sequence | Scala solution | scala-solution-by-malovig-mu9v | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | malovig | NORMAL | 2023-06-13T14:55:04.926856+00:00 | 2023-06-13T14:55:04.926881+00:00 | 10 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n^2)\n<!-- Add your space complexity here, e.... | 0 | 0 | ['Scala'] | 0 |
valid-permutations-for-di-sequence | c++ 3ms dp top down + prefix sum | c-3ms-dp-top-down-prefix-sum-by-vedantna-3sy3 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | vedantnaudiyal | NORMAL | 2023-04-29T11:54:37.331369+00:00 | 2023-04-29T11:54:37.331410+00:00 | 58 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 1 |
valid-permutations-for-di-sequence | O(n^2) DP with O(n) space | on2-dp-with-on-space-by-xjpig-ebf6 | Intuition\n Describe your first thoughts on how to solve this problem. \n- dp[j] in the i-th round memorizes the number of permutations ends with j for s[0:i].\ | XJPIG | NORMAL | 2023-04-26T04:19:42.404935+00:00 | 2023-04-26T04:19:42.404964+00:00 | 28 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- dp[j] in the i-th round memorizes the number of permutations ends with j for s[0:i].\n\n- When s[i] is \'D\', update the ndp[j] with sum(dp[j:i]), which increases each element larger than j by one in the prefix.\n- When s[i] is \'I\', u... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | Python (Simple DP) | python-simple-dp-by-rnotappl-yy2k | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rnotappl | NORMAL | 2023-02-25T13:29:51.610198+00:00 | 2023-02-25T13:29:51.610236+00:00 | 76 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Python3'] | 0 |
valid-permutations-for-di-sequence | C++ Easy Solution✅|Using DP & Backtraking🔥|Optimal Solution | c-easy-solutionusing-dp-backtrakingoptim-8bda | \n\n# Complexity\n- Time complexity:O(NNN)\n\n- Space complexity:O(N*N)\n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\npublic:\n | Jayesh_06 | NORMAL | 2023-02-18T06:40:56.343790+00:00 | 2023-02-18T06:40:56.343840+00:00 | 114 | false | \n\n# Complexity\n- Time complexity:O($$N*N*N$$)\n\n- Space complexity:O($$N*N$$)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int mod=1e9+7;\n //TC=O(N*N*N)\n //SC=O(N*N)\n int find(int ind,int pre,string& s,int n,vector<bool>& vis,vector<vector<int>>&... | 0 | 0 | ['Dynamic Programming', 'Backtracking', 'Memoization', 'C++'] | 0 |
valid-permutations-for-di-sequence | [Scala] Clean Functional DP | scala-clean-functional-dp-by-heavenwatch-qbwr | Let dp[i][j] be the number of permutations that s[i:] could form with the first number be the jth smallest candidate number.\n\nThen if s[i] == \'D\', because f | heavenwatcher | NORMAL | 2023-02-13T00:37:55.175611+00:00 | 2023-02-13T00:40:18.610089+00:00 | 19 | false | Let `dp[i][j]` be the number of permutations that `s[i:]` could form with the first number be the `j`th smallest candidate number.\n\nThen if `s[i] == \'D\'`, because for `dp[i][j]` we already choose the `j`th smallest possible value, we can only choose the candidate numbers before `j` for the `i+1`th position. So `dp[... | 0 | 0 | [] | 0 |
valid-permutations-for-di-sequence | Easy C++ Beginner Friendly DP + Backtracking Solution | easy-c-beginner-friendly-dp-backtracking-zbfx | \n\n# Code\n\nclass Solution {\npublic:\n vector<int> vis;\n int dp[202][202];\n int mod = 1000000007;\n int recur(string &s, int i, int n,int idx){ | kartikdangi01 | NORMAL | 2023-01-24T17:36:34.157807+00:00 | 2023-01-24T17:36:34.157838+00:00 | 78 | false | \n\n# Code\n```\nclass Solution {\npublic:\n vector<int> vis;\n int dp[202][202];\n int mod = 1000000007;\n int recur(string &s, int i, int n,int idx){\n if(idx==n-1){\n return 1;\n }\n if(dp[idx][i]!=-1)\n return dp[idx][i];\n \n int res = 0;\n ... | 0 | 0 | ['Dynamic Programming', 'Backtracking', 'C++'] | 0 |
valid-permutations-for-di-sequence | C solution beats 100% | c-solution-beats-100-by-obose-v1fq | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is asking us to find the number of permutations of a string of length n tha | Obose | NORMAL | 2023-01-18T03:01:27.390736+00:00 | 2023-01-18T03:01:27.390773+00:00 | 51 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is asking us to find the number of permutations of a string of length n that satisfy the condition that the string only contains \'I\' and \'D\' and where \'I\' represents increasing and \'D\' represents decreasing.\n\n\n# App... | 0 | 0 | ['C'] | 0 |
valid-permutations-for-di-sequence | Detailed comments for an O(N^2) solution | detailed-comments-for-an-on2-solution-by-czt0 | \n# Code\n\nclass Solution {\npublic:\n\n int numPermsDISequence(string s) {\n int N = s.size() + 1;\n vector<vector<int>> dp(N, vector<int>(N) | cal_apple | NORMAL | 2023-01-06T08:52:58.617419+00:00 | 2023-01-06T08:52:58.617454+00:00 | 55 | false | \n# Code\n```\nclass Solution {\npublic:\n\n int numPermsDISequence(string s) {\n int N = s.size() + 1;\n vector<vector<int>> dp(N, vector<int>(N));\n const int mod = 1e9 + 7;\n\n // dp[i][j] : answers for length=i+1 (using number [0,1,..,i]) that ends with j (j <= i)\n for (int j ... | 0 | 0 | ['C++'] | 0 |
valid-permutations-for-di-sequence | Just a runnable solution | just-a-runnable-solution-by-ssrlive-4e9e | Code\n\nimpl Solution {\n pub fn num_perms_di_sequence(s: String) -> i32 {\n let n = s.len();\n let m = 1_000_000_007;\n let mut dp = ve | ssrlive | NORMAL | 2023-01-03T07:31:48.025936+00:00 | 2023-01-03T07:31:48.025976+00:00 | 26 | false | # Code\n```\nimpl Solution {\n pub fn num_perms_di_sequence(s: String) -> i32 {\n let n = s.len();\n let m = 1_000_000_007;\n let mut dp = vec![vec![0; n + 1]; n + 1];\n dp[0][0] = 1;\n for i in 1..=n {\n for j in 0..=i {\n if s.chars().nth(i - 1).unwrap()... | 0 | 0 | ['Rust'] | 0 |
valid-permutations-for-di-sequence | [Python3] | Top-Down DP O(N^2) | python3-top-down-dp-on2-by-swapnilsingh4-03vp | \nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n n,ans = len(s),0\n mod = 1_00_00_00_000 + 7\n memo = [[-1] * 201 for | swapnilsingh421 | NORMAL | 2022-12-16T12:44:38.593003+00:00 | 2022-12-16T12:44:38.593031+00:00 | 126 | false | ```\nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n n,ans = len(s),0\n mod = 1_00_00_00_000 + 7\n memo = [[-1] * 201 for i in range(201)]\n def dp(ind,prevNum):\n if ind < 0:\n return 1\n if memo[ind][prevNum] != -1:\n ... | 0 | 0 | ['Dynamic Programming', 'Python', 'Python3'] | 0 |
valid-permutations-for-di-sequence | Python | Backtracking, works and easy to understand | python-backtracking-works-and-easy-to-un-qhda | python\nfrom functools import lru_cache\nclass Solution:\n def numPermsDISequence(self, s):\n return self.backtrack(s) % (10**9 + 7)\n\n def backtr | steve-jokes | NORMAL | 2022-11-30T06:50:18.097049+00:00 | 2022-11-30T06:50:18.097090+00:00 | 90 | false | ```python\nfrom functools import lru_cache\nclass Solution:\n def numPermsDISequence(self, s):\n return self.backtrack(s) % (10**9 + 7)\n\n def backtrack(self, s): # with pruning and memo\n L = len(s)\n nums = set(range(-1, L + 1)) # dummy -1 as \'pre\', only happens when idx == 0 (in which... | 0 | 0 | ['Backtracking', 'Memoization', 'Python'] | 0 |
valid-permutations-for-di-sequence | C++ || Backtracking + Memoization | c-backtracking-memoization-by-rohitraj13-seb1 | \nclass Solution {\npublic:\n int visited[201];\n int mod = 1e9+7;\n map<pair<int,int>,int>mp;\n int solve(int idx , int last,string &s){\n / | rohitraj13may1998 | NORMAL | 2022-11-07T16:31:02.168103+00:00 | 2022-11-07T16:31:02.168145+00:00 | 119 | false | ```\nclass Solution {\npublic:\n int visited[201];\n int mod = 1e9+7;\n map<pair<int,int>,int>mp;\n int solve(int idx , int last,string &s){\n //base case\n if(idx<0)return 1;\n \n if(mp.count({idx,last}))\n return mp[{idx,last}];\n int ans = 0 ;\n \n ... | 0 | 0 | ['Dynamic Programming', 'Backtracking', 'Memoization', 'C++'] | 0 |
valid-permutations-for-di-sequence | js solution dp | js-solution-dp-by-renettadonathanrbo95-veuy | \nvar numPermsDISequence = function(s) {\n let mod = 10**9+7,res = 0\n const dp = new Array(s.length+1).fill().map(()=>new Array)\n dp[0][0]=1\n for | renettadonathanrbo95 | NORMAL | 2022-11-07T08:56:00.549537+00:00 | 2022-11-07T08:56:00.549584+00:00 | 39 | false | ```\nvar numPermsDISequence = function(s) {\n let mod = 10**9+7,res = 0\n const dp = new Array(s.length+1).fill().map(()=>new Array)\n dp[0][0]=1\n for(i=1;i<s.length+1;i++) {\n if(s[i-1]===\'D\') {\n dp[i][i]=0\n for(j=i-1;j>=0;j--) {\n dp[i][j]=(dp[i][j+1]+dp[i-... | 0 | 0 | ['JavaScript'] | 0 |
valid-permutations-for-di-sequence | [C++] Beginner Friendly, DP Solution | c-beginner-friendly-dp-solution-by-hardi-jrgs | \nclass Solution {\npublic:\n int mod=1000000007;\n int solve(string &s, int index, vector<bool> &vis, int last, vector<vector<int> > &dp){\n //if | hardikjain40153 | NORMAL | 2022-08-22T19:03:35.648661+00:00 | 2022-08-22T19:03:35.648708+00:00 | 214 | false | ```\nclass Solution {\npublic:\n int mod=1000000007;\n int solve(string &s, int index, vector<bool> &vis, int last, vector<vector<int> > &dp){\n //if we reach the last index, there will be single element left we can do this in one way.\n if(index == s.size()){\n return 1;\n }\n ... | 0 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C'] | 0 |
valid-permutations-for-di-sequence | Java, time O(N^2), space O(N), 3ms=>2ms, dp[n+1] | java-time-on2-space-on-3ms2ms-dpn1-by-vk-7ss1 | \npublic int numPermsDISequence(String s) {\n\tint n = s.length();\n\tint[][] dp = new int [n+2][2];\n\tint mod = 1000000007;\n\tdp[1][0] = 1;\n\tfor(int i = 1; | vkochengin | NORMAL | 2022-08-19T18:55:26.868210+00:00 | 2022-08-20T07:51:42.833535+00:00 | 157 | false | ```\npublic int numPermsDISequence(String s) {\n\tint n = s.length();\n\tint[][] dp = new int [n+2][2];\n\tint mod = 1000000007;\n\tdp[1][0] = 1;\n\tfor(int i = 1; i<=n; i++){\n\t\tif(s.charAt(i-1)==\'I\') {\n\t\t\tfor(int j = 0; j<=i; j++) dp[j+1][i&1]=(dp[j][(i+1)&1] + dp[j][i&1])%mod; \n\t\t} else {\n\t\t\tfor(int ... | 0 | 0 | ['Dynamic Programming', 'Java'] | 0 |
valid-permutations-for-di-sequence | python3 solution | python3-solution-by-daheofdiamond-zfc5 | Solution, requires a bit of observation\n\n\nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n myStore = [1]\n \n for ind | daheofdiamond | NORMAL | 2022-07-30T00:23:07.200012+00:00 | 2022-07-30T00:23:07.200049+00:00 | 177 | false | Solution, requires a bit of observation\n\n```\nclass Solution:\n def numPermsDISequence(self, s: str) -> int:\n myStore = [1]\n \n for index, val in enumerate(s):\n if val == 0:\n continue\n temp = []\n for i in range(index + 2):\n ... | 0 | 0 | ['Python3'] | 0 |
valid-permutations-for-di-sequence | JAVA Solution | java-solution-by-user6539fn-mioy | class Solution {\n private static final int mod = 1000000007;\n int[] seen = null;\n Integer[][] dp = null;\n public int numPermsDISequence(String s | user6539fn | NORMAL | 2022-07-29T07:26:55.530688+00:00 | 2022-07-29T07:26:55.530744+00:00 | 159 | false | class Solution {\n private static final int mod = 1000000007;\n int[] seen = null;\n Integer[][] dp = null;\n public int numPermsDISequence(String s) {\n dp = new Integer[s.length()][s.length()+1];\n seen = new int[s.length()+1];\n int count = 0;\n for(int i=0; i <= s.length(); i... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 0 |
valid-permutations-for-di-sequence | ANYONE CAN MODIFY THIS BFS approach with TLE? | anyone-can-modify-this-bfs-approach-with-cwhu | \nclass Solution {\npublic:\n int numPermsDISequence(string s) {\n int n=s.length();\n queue<pair<string,unordered_set<int>>> q;\n unord | Fullmetal_01 | NORMAL | 2022-07-06T12:47:49.126826+00:00 | 2022-07-07T05:52:07.527555+00:00 | 65 | false | ```\nclass Solution {\npublic:\n int numPermsDISequence(string s) {\n int n=s.length();\n queue<pair<string,unordered_set<int>>> q;\n unordered_set<int> v;\n string str="";\n for(int i=0;i<=n;++i)\n {\n str="";\n v.clear();\n str+=(i+\'0\');\... | 0 | 0 | ['Breadth-First Search', 'C'] | 0 |
valid-permutations-for-di-sequence | C++ Easy | c-easy-by-subhrajit123-18b8 | class Solution {\npublic:\n int mod = 1e9 + 7;\n // unordered_setst;\n int perm(int i, int prev, int n, string &s, vector>&dp, vector&vis)\n {\n | Subhrajit123 | NORMAL | 2022-07-06T11:46:49.372375+00:00 | 2022-07-06T11:47:32.850386+00:00 | 262 | false | class Solution {\npublic:\n int mod = 1e9 + 7;\n // unordered_set<int>st;\n int perm(int i, int prev, int n, string &s, vector<vector<int>>&dp, vector<bool>&vis)\n {\n //cout<<"HERE"<<i<<"\\n";\n if(i<0)\n {\n return 1;\n }\n if(dp[i][prev] != -1)\n {\n ... | 0 | 0 | ['Dynamic Programming', 'C'] | 0 |
valid-permutations-for-di-sequence | EASY C++ SOLUTION DP | RECURSION | MEMOIZATION | easy-c-solution-dp-recursion-memoization-f8ar | \nclass Solution {\npublic:\n \n int dp[201][201];\n int m = 1e9+7;\n int helper(string &s, int i, vector<bool> &visit, int start){\n if(i==s | jatinbansal1179 | NORMAL | 2022-07-06T11:15:27.397477+00:00 | 2022-07-06T11:15:27.397526+00:00 | 548 | false | ```\nclass Solution {\npublic:\n \n int dp[201][201];\n int m = 1e9+7;\n int helper(string &s, int i, vector<bool> &visit, int start){\n if(i==s.length()){\n return 1;\n }\n \n if(dp[i][start]!=-1){\n return dp[i][start];\n }\n if(s[i]==\'D\'){... | 0 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++'] | 1 |
valid-permutations-for-di-sequence | Easy C++ Solution | easy-c-solution-by-abhi-1301-iwp0 | \nusing ll = long long;\n\nll dp[205][205];\nconst ll mod = 1e9 + 7;\nint n;\n\nll solve(int index, string &s, vector<int> &v, int piche)\n{\n if (index >= s | Abhi-1301 | NORMAL | 2022-07-06T10:10:12.451897+00:00 | 2022-07-06T10:10:12.451937+00:00 | 747 | false | ```\nusing ll = long long;\n\nll dp[205][205];\nconst ll mod = 1e9 + 7;\nint n;\n\nll solve(int index, string &s, vector<int> &v, int piche)\n{\n if (index >= s.size())\n return 1;\n\n if (dp[index][piche] != -1)\n return dp[index][piche];\n\n dp[index][piche] = 0;\n\n if (s[index] == \'D\')\n... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'C', 'C++'] | 2 |
valid-permutations-for-di-sequence | C# Solution | c-solution-by-rwdenier-iq42 | \n//This is based on a couple others..\n//I take no credit other than the obvious refactoring.\n//I deliberately chose the one that seemed easier to understand, | rwdenier | NORMAL | 2022-06-20T03:24:59.077889+00:00 | 2022-06-20T03:24:59.077929+00:00 | 93 | false | ```\n//This is based on a couple others..\n//I take no credit other than the obvious refactoring.\n//I deliberately chose the one that seemed easier to understand, not the fastest.\n\npublic class Solution \n{\n //Number of Permutations Table - Using long to avoid a lot of mod operations.\n long [,] np;\n int ... | 0 | 0 | [] | 0 |
valid-permutations-for-di-sequence | 🔥 First Javascript Solution | first-javascript-solution-by-joenix-91z1 | \nfunction numPermsDISequence(s) {\n let mod = 1e9 + 7, dp = [[1], []], res = 0\n\n for (let i = 1; i <= S.length; i++) {\n for (let j = 0; j <= i; | joenix | NORMAL | 2022-05-19T11:46:56.339096+00:00 | 2022-05-19T11:46:56.339136+00:00 | 88 | false | ```\nfunction numPermsDISequence(s) {\n let mod = 1e9 + 7, dp = [[1], []], res = 0\n\n for (let i = 1; i <= S.length; i++) {\n for (let j = 0; j <= i; j++) {\n let l = 0, r = j\n if (s.charAt(i-1) === \'D\') {\n l = j, r = i\n }\n dp[1][j] = 0\n ... | 0 | 0 | ['JavaScript'] | 0 |
valid-permutations-for-di-sequence | C++ | Memoization solution | c-memoization-solution-by-diavolos-l3jb | ```\nclass Solution {\nprivate:\n int n,mod=1000000000+7;\n vector>mem;\n int solve(string &s,int index,int prev,vector&seen){\n if(index==n){\n | Diavolos | NORMAL | 2022-05-19T08:30:33.657073+00:00 | 2022-05-19T08:30:33.657114+00:00 | 692 | false | ```\nclass Solution {\nprivate:\n int n,mod=1000000000+7;\n vector<vector<int>>mem;\n int solve(string &s,int index,int prev,vector<bool>&seen){\n if(index==n){\n return 1;\n } else if(mem[index][prev]!=-1){\n return mem[index][prev];\n } else {\n int ans=0... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'C', 'C++'] | 1 |
valid-permutations-for-di-sequence | PYTHON SOLUTION || EASY || EXPLAINED || DP || WELL WRITTTEN CODE|| | python-solution-easy-explained-dp-well-w-c30f | Try putting Value at the position keeping in mind that the current value should be increasing or decreasing \nTo check this check s[pos - 1] \nNow since we cann | reaper_27 | NORMAL | 2022-03-16T12:46:46.690586+00:00 | 2022-03-16T12:46:46.690613+00:00 | 456 | false | Try putting Value at the position keeping in mind that the current value should be increasing or decreasing \nTo check this check s[pos - 1] \nNow since we cannot repeat any digit we should use a dictionary to keep in check what value we used so far .\n\nOnce you find the no. of answer having index = i and last item =... | 0 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Python', 'Python3'] | 1 |
valid-permutations-for-di-sequence | MEMOIZATION DP | memoization-dp-by-atharva20194080-jmgn | \nclass Solution {\npublic:\n int dp[203][203];\n int mod=1e9+7;\n int solve(int index , string& s, vector<int> & visited , int prev){\n if(inde | atharva20194080 | NORMAL | 2022-03-15T10:55:11.078320+00:00 | 2022-03-15T10:55:11.078347+00:00 | 177 | false | ```\nclass Solution {\npublic:\n int dp[203][203];\n int mod=1e9+7;\n int solve(int index , string& s, vector<int> & visited , int prev){\n if(index==s.size()) return 1;\n if(dp[index][prev]!=-1) return dp[index][prev];\n int n=s.size();\n long long temp=0;\n if(s[index]==\'D... | 0 | 0 | [] | 1 |
valid-permutations-for-di-sequence | Compiling both O(n^2) approaches. | compiling-both-on2-approaches-by-josshei-92n4 | The first approach is based on this post by lee215.\n\nIn both the cases we are avoiding looping through the values already looped through by the previous eleme | jossheim | NORMAL | 2021-07-01T00:53:46.926865+00:00 | 2021-07-01T01:27:17.448990+00:00 | 422 | false | The first approach is based on [this](https://leetcode.com/problems/valid-permutations-for-di-sequence/discuss/168278/C%2B%2BJavaPython-DP-Solution-O(N2)) post by lee215.\n\nIn both the cases we are avoiding looping through the values already looped through by the previous element by just using the previous values to m... | 0 | 0 | [] | 0 |
valid-permutations-for-di-sequence | C++ Easy | c-easy-by-aaditya-pal-ouzv | c++\nclass Solution {\npublic:\n int n;\n string s;\n int mod = 1e9 + 7;\n map<pair<int,int>,int>dp;\n int countways(int id,int prev,vector<bool> | aaditya-pal | NORMAL | 2021-05-29T20:35:28.717124+00:00 | 2021-05-29T20:35:28.717156+00:00 | 319 | false | ```c++\nclass Solution {\npublic:\n int n;\n string s;\n int mod = 1e9 + 7;\n map<pair<int,int>,int>dp;\n int countways(int id,int prev,vector<bool>&taken){\n\n if(id==n+1){\n return 1;\n }\n if(dp.find({id,prev})!=dp.end()) return dp[{id,prev}];\n int ans = 0;\n ... | 0 | 0 | [] | 0 |
valid-permutations-for-di-sequence | Java - DP - O(N^3) | java-dp-on3-by-kataria_aakash-4kuh | \nclass Solution {\n int MOD = 1000000007;\n Map<Integer, Integer> cache;\n public int numPermsDISequence(String s) {\n cache = new HashMap<>(); | kataria_aakash | NORMAL | 2021-05-15T17:58:04.744129+00:00 | 2021-05-15T17:58:45.764806+00:00 | 237 | false | ```\nclass Solution {\n int MOD = 1000000007;\n Map<Integer, Integer> cache;\n public int numPermsDISequence(String s) {\n cache = new HashMap<>();\n return dpRec(s, 0, 0, s.length(), new boolean[s.length()+1]);\n }\n private int dpRec(String s, int i, int x, int y, boolean[] vis) {\n ... | 0 | 0 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.