id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n= nums.size();\n vector<vector<int>> sets(n);\n sets[0].push_back(nums[0]);\n for(int i= 1; i< n; i++) {\n int mx= 0, index= -1;\n for(int j= i-1; j>= 0; j--) {\n int ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n= nums.size();\n vector<vector<int>> sets(n);\n sets[0].push_back(nums[0]);\n for(int i= 1; i< n; i++) {\n int mx= 0, index= -1;\n for(int j= i-1; j>= 0; j--) {\n int ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "const int maxN = 100000 + 1;\n\nclass Solution {\npublic:\n class SegmentTree {\n public:\n vector<int> seg;\n \n SegmentTree() {\n seg = vector<int>(maxN * 4 + 10, 0);\n }\n \n int query(int l, int r) {\n return query_util(0, 0, max... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\nint findanswer(vector<int>&nums,int prev,int curr,vector<vector<int>>&dp)\n{\n if(curr>=nums.size())\n {\n return 0;\n }\n if(dp[prev+1][curr+1]!=-1)\n {\n return dp[prev+1][curr+1];\n }\n int ans1=findanswer(nums,prev,curr+1,dp);\n int ans2=... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\nint findanswer(vector<int>&nums,int prev,int curr,vector<vector<int>>&dp)\n{\n if(curr>=nums.size())\n {\n return 0;\n }\n if(dp[prev+1][curr+1]!=-1)\n {\n return dp[prev+1][curr+1];\n }\n int ans1=findanswer(nums,prev,curr+1,dp);\n int ans2=... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n\n int find(vector<int> &nums,int i,int prev,vector<vector<short>>&dp)\n {\n if(i==nums.size())\n return 0;\n if(dp[i][prev+1]!=-1)\n return dp[i][prev+1];\n\n int take=INT_MIN;\n if(prev==-1||nums[prev]<nums[i])\n take=1+fin... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> nums_sort;\n int i, j;\n int** ans;\n for (i=0;i<nums.size();i++) {\n nums_sort.push_back(nums[i]);\n }\n sort(nums_sort.begin(), nums_sort.end());\n i=1;\n w... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n = (int)nums.size();\n vector<int> nums_ori = nums;\n sort(nums.begin(), nums.end());\n int i = 1;\n while (i < nums.size())\n {\n if (nums[i] == nums[i - 1])\n nums.erase(nums.begin() + i);\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> t1 = nums;\n vector<int> t;\n int n = nums.size();\n sort(t1.begin(),t1.end());\n int a = t1[0];\n t.push_back(a);\n for(int i=1;i<nums.size();i++){\n if(t1[i]==a){\... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n = (int)nums.size();\n vector<int> sorted(nums.begin(), nums.end());\n sort(sorted.begin(),sorted.end());\n sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());\n int m = (int)sorted.s... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lcs(vector<int>& nums, vector<int>& sortedNums) {\n int n = nums.size();\n int m = sortedNums.size();\n vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));\n\n // Building the LCS dp table\n for (int i = 1; i <= n; i++) {\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lcs(vector<int>& nums, vector<int>& sortedNums) {\n int n = nums.size();\n int m = sortedNums.size();\n vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n \n int lengthOfLIS(vector<int>& nums) {\n vector<int>temp = nums;\n sort(temp.begin(),temp.end());... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int>v=nums;\n int n=nums.size();\n sort(v.begin(),v.end());\n vector<int>temp;\n temp.push_back(v[0]);\n for(int i=1;i<n;i++){\n if(temp.back()==v[i]) continue;\n els... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int>ord = nums;\n sort(ord.begin(),ord.end());\n vector<int>ord2;\n ord2.push_back(ord[0]);\n for(int i=1;i<nums.size();i++){\n if(ord[i]!=ord2.back()){\n ord2.push_back(... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> nums1 = nums;\n vector<int> m;\n int n = nums.size();\n sort(nums.begin(), nums.end());\n for(int i=0; i<n; i++){\n if(m.empty()){\n m.push_back(nums[i]);\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n set<int> res(nums.begin(),nums.end());\n vector<int> v(res.begin(),res.end());\n int m = v.size();\n int n = nums.size();\n vector<vector<int>> dp(m+1, vector<int>(n+1,0));\n for(int i = 1; i <= ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n set<int> orderedSet(nums.begin(), nums.end());\n vector<int> arr(orderedSet.begin(), orderedSet.end());\n int n = nums.size();\n \n vector<vector<int>> dp(arr.size() + 1, vector<int>(n + 1, 0));\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int function(vector<int>&a1,vector<int>&a2,int n,int m,vector<vector<int>>&dp){\n if(n==0 || m==0){\n return 0;\n }\n if(dp[n][m]!=-1){\n return dp[n][m];\n }\n if(a1[n-1]==a2[m-1]){\n return dp[n][m]=1+funct... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n set<int> tmp(nums.begin(), nums.end());\n vector<int> mySet(tmp.begin(), tmp.end());\n int n = nums.size(), m = mySet.size();\n\n vector<vector<int>> dp(n, vector<int>(m, 0));\n\n // initial\n dp... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n\n int LIStabulation(vector<int>& nums, set<int>& st) {\n int n = nums.size();\n int m = st.size();\n vector<int> v2(st.begin(), st.end());\n\n vector<vector<int>> dp(n+1, vector<int> (m+1, 0));\n\n for(int i=1; i<n+1; i++) {\n for... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> sorted = nums;\n set<int> set1(nums.begin(), nums.end());\n vector<vector<int>> dp(nums.size()+1, vector<int>(set1.size()+1, 0));\n auto it = set1.begin();\n for(int i=1; i<=nums.size(); i++... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> sorted = nums;\n set<int> set1(nums.begin(), nums.end());\n vector<vector<int>> dp(nums.size()+1, vector<int>(set1.size()+1, 0));\n auto it = set1.begin();\n for(int i=1; i<=nums.size(); i++... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int LIS(vector<int> &text1, vector<int> &text2, int n, int m, vector<vector<int>>&dp)\n {\n for(int i=0;i<n+1;i++)\n {\n for(int j=0;j<m+1;j++)\n {\n if(i==0||j==0)\n dp[i][j]=0;\n }\n }\n\... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> sorted = nums;\n set<int> set1(nums.begin(), nums.end());\n vector<vector<int>> dp(nums.size()+1, vector<int>(set1.size()+1, 0));\n auto it = set1.begin();\n for(int i=1; i<=nums.size(); i++... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n set<int> st;\n vector<int> v;\n int n=nums.size();\n for(auto i: nums){\n st.insert(i);\n }\n for(auto i: st){\n v.push_back(i);\n }\n vector<vector<int>> dp... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\nint lcs(vector<int> x, vector<int> y)\n{\n int n =x.size();\n int m =y.size();\n vector<vector<int>> dp(n+1,vector<int>(m+1));\n for(int i =0;i<n+1;i++)\n {\n for(int j =0;j<m+1;j++)\n {\n if(i==0 || j==0)\n {\n dp... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int solve(vector<int>& nums, vector<int>& v, vector<vector<int>> &dp, int i, int j){\n if(i ==0 || j ==0){\n return 0;\n }\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n \n if(nums[i-1] == v[j-1]){\n r... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\nvector<int> uniqueSortedArray(vector<int>& arr) {\n \n set<int> uniqueElements(arr.begin(), arr.end());\n \n \n vector<int> result(uniqueElements.begin(), uniqueElements.end());\n \n return result;\n}\nint f(int n, int m, vector<int>&s1, vector<int> &s2, vector<... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\nvector<int> uniqueSortedArray(vector<int>& arr) {\n \n std::set<int> uniqueElements(arr.begin(), arr.end());\n \n \n std::vector<int> result(uniqueElements.begin(), uniqueElements.end());\n \n return result;\n}\nint f(int n, int m, vector<int>&s1, vector<int> &s... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\nvector<int> uniqueSortedArray(vector<int>& arr) {\n \n std::set<int> uniqueElements(arr.begin(), arr.end());\n \n \n std::vector<int> result(uniqueElements.begin(), uniqueElements.end());\n \n return result;\n}\nint f(int n, int m, vector<int>&s1, vector<int> &s... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int count2(int n, int m, vector<int>& str1, vector<int>& str2, vector<vector<int>>& dp) {\n if(dp[n][m]!=-1)return dp[n][m];\n if(n==0||m==0)return 0;\n if(str1[n-1]==str2[m-1]){\n dp[n][m] = 1+count2(n-1,m-1,str1,str2,dp);\n }else{\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int solution(vector<int>& nums, int n, vector<int>& incNums, int m, vector<vector<int>>& t )\n {\n if(n==0 || m==0)\n {\n t[n][m] = 0;\n return t[n][m];\n }\n if(t[n][m] != -1)\n {\n return t[n][m];\n }\n\n if(... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int count2(int n, int m, vector<int>& str1, vector<int>& str2, vector<vector<int>>& dp) {\n if(dp[n][m]!=-1)return dp[n][m];\n if(n==0||m==0)return 0;\n if(str1[n-1]==str2[m-1]){\n dp[n][m] = 1+count2(n-1,m-1,str1,str2,dp);\n }else{\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n unordered_set<int> s(nums.begin(), nums.end());\n vector<int> arr(s.begin(), s.end());\n sort(arr.begin(), arr.end());\n vector<vector<int>> dp(nums.size()+1, vector<int> (arr.size()+1, 0));\n for(int i... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n unordered_set<int>s(nums.begin(),nums.end());\n vector<int> arr2(s.begin(),s.end());\n sort(arr2.begin(),arr2.end());\n int n=nums.size();\n int m=arr2.size();\n vector<vector<int>>dp(n+1,vector<... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int> arr1) {\n unordered_set<int> s(arr1.begin(),arr1.end());\n vector<int> arr2(s.begin(),s.end());\n sort(arr2.begin(),arr2.end());\n int n=arr1.size();\n int m=arr2.size();\n vector<vector<int>> dp(n+1,vector... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n=nums.size(),ans=1;\n vector<vector<int>> a(n);\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++){\n if(nums[j]>nums[i]){ \n a[i].push_back(j);\n //... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "int m[2501][20003];\nclass Solution {\npublic:\n int n;\n vector<int> x;\n //int m[2501][3];\n int f(int i,int j){\n if(i==n) return 0;\n //cout<<i<<' '<<j<<endl;\n if(m[i][j+10002]!=-10002) return m[i][j+10002];\n if(x[i]>j){\n return m[i][j+10002]=max(1+... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int search(vector<int> dp, int st, int en, int tar) {\n while(st<=en) {\n int mid = (en+st)/2;\n if(dp[mid] >= tar) {\n en = mid-1;\n }\n else st = mid+1;\n }\n return st;\n }\n int lengthOf... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int n;\n int t[2501][2501];\n int LCS(vector<int> & nums1, vector<int>& nums2){\n int m = nums1.size();\n int n = nums2.size();\n vector<vector<int>> t(m+1, vector<int>(n+1));\n for(int j=0; j<n; j++){\n t[0][j]=0;\n }\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n void display(vector<int>v){\n for(auto x:v){\n cout<<x<<\" \";\n }\n cout<<\"\\n\";\n return;\n }\n int binarySearch(vector<int>v,int a,int i,int j){\n if(i>j){\n // cout<<i<<\" \";\n return i;\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n void display(vector<int>v){\n for(auto x:v){\n cout<<x<<\" \";\n }\n cout<<\"\\n\";\n return;\n }\n int binarySearch(vector<int>v,int a,int i,int j){\n if(i>j){\n return i;\n }\n int m = (i+j)/2;\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n\n void lowerBound(vector<int> ans, int s, int e, int val, int &lb)\n {\n if(s>e)\n return;\n\n int mid = (s+e)/2;\n if(ans[mid]>=val)\n {\n lb = mid;\n lowerBound(ans, s, mid-1, val, lb);\n return;\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int ceilInd(vector<int>tail,int l ,int r ,int k)\n {\n \n while(l<r)\n {\n int m = l+(r-l)/2;\n if(tail[m]>=k)\n r = m;\n else\n l = m+1;\n }\n return r;\n }\n int lengthOfLIS(v... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n void getVec(vector<vector<int>>& stack, int num) {\n int l = 0;\n int r = stack.size();\n while (l < r) {\n int mid = (l + r) / 2;\n vector<int> curr = stack[mid];\n if (curr.back() >= num) {\n r = mid;\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int max(int a, int b){\n return a > b ? a : b;\n }\n int maxinVec(vector<int> vec){\n int maxi = vec[0];\n for(int i : vec){\n if(i > maxi){\n maxi = i;\n }\n\n }\n return maxi;\n }\n int leng... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n map<int,vector<int>> mp;\n int dp[2505];\n int length(int i, vector<int> &nums)\n {\n int a = 1;\n if(dp[i]!=-1)\n return dp[i];\n for(int c: mp[i])\n {\n a = max(a,1+length(c,nums));\n }\n return dp[i] ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n class comp{\n public:\n bool operator()(pair<int,int>& a,pair<int,int>& b){\n if(a.first!=b.first) return a.first>b.first;\n return a.second<b.second;\n }\n };\n int largest(vector<int>& nums,int x,int save){\n // \n priority_queue <pair<int,in... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& arr) {\n int n =arr.size();\n vector<int> prev;\n for(int i=0;i<n;i++)\n {\n vector<int> curr(i+1);\n for(int j = 0;j<i;j++)\n {\n if(arr[j]<arr[i])\n curr[i] = max(curr[i],prev[j] + 1);\n... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n\n int find_max(int curind, int num, vector<int> &dp, vector<int> nums){\n int req = -1;\n int maxi = INT_MIN;\n for(int i=0; i<curind; i++){\n if(nums[i]<nums[curind]){\n \n maxi = max(maxi,dp[i]);\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int recFun(vector<int>nums,vector<int>&dp,int ind){\n if(ind == 0)\n return dp[ind]=1;\n if(dp[ind]!=-1)\n return dp[ind];\n int res=1;\n for(int i=0;i<ind;i++){\n if(dp[i]==-1)\n recFun(nums,dp,i);\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n = nums.size();\n // vector<vector<int>> dp(n, vector<int>(n,-1));\n // dp[n-1][n-1] = 1;\n vector<int> dp(n,-1);\n dp[n-1] = 1;\n int ret=1;\n for(int i= n-2; i>=0; i--){\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n // int func(vector<int>&nums,int id,int prev,vector<vector<int>>&dp){\n // if(id>=nums.size())return 0;\n // if(dp[id][prev+1]!=-1)return dp[id][prev+1];\n // int len = func(nums,id+1,prev,dp);\n // if(prev==-1 || nums[id]>nums[prev])\n // l... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n\n void func(int ind,vector<int>&dp,vector<int>nums){\n if(ind==nums.size()){\n return;\n }\n\n for(int i=0; i<ind; i++){\n if(nums[ind]>nums[i]){\n dp[ind] = max(dp[ind],dp[i]+1);\n }\n }\n fun... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) \n {\n if (nums.size() == 1)\n {\n return 1;\n }\n\n int** memo = new int*[nums.size() + 1];\n\n for (int i = 0; i < nums.size() + 1; ++i)\n {\n memo[i] = new int[nums.size()... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n\n int helper(const vector<int>& nums, int currIndex, int prevIndex, int n) {\n if (currIndex >= n) return 0;\n int notTake = helper(nums, currIndex + 1, prevIndex, n);\n\n int take = 0;\n if (prevIndex == -1 || nums[currIndex] > nums[prevIndex]) {\n take = ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int solveUsingRecursion(vector<int>& nums, int curr, int prev) {\n if (curr >= nums.size()) {\n return 0;\n }\n // include\n\n int include = 0;\n\n if (prev == -1 || nums[curr] > nums[prev]) {\n include = 1 + solveUsing... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int solve(int ind, vector<int>& nums, vector<vector<int>>& dp, int prev) {\n if (ind == nums.size()) {\n return 0;\n }\n if (dp[ind][prev + 1] != -1)\n return dp[ind][prev + 1];\n int take = 0;\n int ntake = solve(ind +... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int maxi = 0;\n int solve(vector<int>& nums,int index,int prev,vector<vector<int>>& dp){\n if(index >= nums.size()){\n return 0;\n }\n\n if(prev != -1 && dp[index][prev] != -1) return dp[index][prev];\n\n // exclude\n int ex = ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\nint helper(vector<int>&nums,int index,int prev, vector<vector<int>>&dp){\n\nif(index==nums.size()){\n return 0;\n}\nif(dp[index][prev+1]!=-1){\n return dp[index][prev+1];\n}\n //not pick\n int notpick=helper(nums,index+1,prev,dp);\n int pick=INT_MIN;\n if(prev==... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lcs( int n , int prev , vector<vector<int>> &dp , vector<int>& nums){\n if(n>=nums.size() ) return 0;\n\n if(dp[n][prev+1]!=-1) return dp[n][prev+1];\n\n if(prev==-1 || nums[n]>nums[prev]){\n return dp[n][prev+1]= max(1 + lcs(n+1 , n , dp, ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int helper(vector<int>& nums,int x, int ind,vector<vector<int>>&dp){\n if(ind==nums.size()){\n return 0;\n }\n if(x!=-1&&dp[ind][x]!=-1)return dp[ind][x];\n if(x==-1)return max(1+helper(nums,ind, ind+1,dp), helper(nums,x, ind+1,dp));\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& arr) {\n vector<int>nums;\n nums.push_back(INT_MIN);\n int n=arr.size();\n int i=0;\n while(i<n){\n nums.push_back(arr[i]);\n i++;\n }\nint n1=nums.size();\n vector<int>dp(n1,0);\n\n int index=n1-1;\n ... |
300 | <p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [10... | 2 | {
"code": "class Solution \n{\npublic:\n int lengthOfLIS(vector<int>& nums) \n {\n int size = nums.size();\n int** memo = new int*[size];\n\n for (int i = 0 ; i < size; ++i)\n {\n memo[i] = new int[size];\n memset(memo[i], -1, sizeof(int) * size);\n }\n\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nstatic const int __ = [](){... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "\nauto _ = []() { // NOLINT(bugprone-reserved-identifier, cppcoreguidelines*)\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\n#define setmatrix(m, iter) \\\n do { /* NOLINT(cppcoreguidelines-avoi... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "auto speedUP = [](){\n ios::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\n\nclass Solution {\nprivate:\n static constexpr array<pair<int, int>, 4> dirs = {make_pair(0, 1), make_pair(1, 0), make_pair(0, -1), make_pair(-1, 0)};\n\npublic:\n vector<vector<int>> sp... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nunion FastPoint {\n stru... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n \n #pragma GCC optimize (\... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": " /**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n \n #pragma GCC optimize (\... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,411 | <p>You are given two integers <code>m</code> and <code>n</code>, which represent the dimensions of a matrix.</p>
<p>You are also given the <code>head</code> of a linked list of integers.</p>
<p>Generate an <code>m x n</code> matrix that contains the integers in the linked list presented in <strong>spiral</strong> ord... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n... |
2,409 | <p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>
<p>Return <em>the number of <strong>strictly</strong> <strong>increasing</strong> paths in the grid such that you can start from <strong>any</strong> cell a... | 0 | {
"code": "int MOD = 1000000007;\nclass Solution {\n private:\n int iPs_[100000];\n int toIndex(int row, int col, int cols){\n return row * cols + col;\n }\n int incPaths(int begin_id, const vector<vector<int>>& grid){\n if(iPs_[begin_id] != -1){\n r... |
2,409 | <p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>
<p>Return <em>the number of <strong>strictly</strong> <strong>increasing</strong> paths in the grid such that you can start from <strong>any</strong> cell a... | 0 | {
"code": "class Solution {\npublic:\n int countPaths(vector<vector<int>>& grid) {\n const int mod = 1e9 + 7;\n int m = grid.size(), n = grid[0].size();\n int f[m][n];\n memset(f, 0, sizeof(f));\n function<int(int, int)> dfs = [&](int i, int j) -> int {\n if (f[i][j]) ... |
2,409 | <p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>
<p>Return <em>the number of <strong>strictly</strong> <strong>increasing</strong> paths in the grid such that you can start from <strong>any</strong> cell a... | 0 | {
"code": "int dir[][2] = {{0,1},{1,0},{-1,0}, {0,-1}};\n\nint mod = 1e9 +7;\nvector<vector<int>> dp;\nint n, m;\nclass Solution {\n\npublic:\n int solve(int i, int j, vector<vector<int>>& matrix) {\n if(dp[i][j] != -1) return dp[i][j];\n int &ans = dp[i][j];\n ans = 0;\n for(int d = 0 ; d < ... |
2,409 | <p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>
<p>Return <em>the number of <strong>strictly</strong> <strong>increasing</strong> paths in the grid such that you can start from <strong>any</strong> cell a... | 0 | {
"code": "const int MOD = 1e9 + 7;\nconst int MAXM = 1001;\nconst int MAXN = 1001;\nint f[MAXM][MAXN];\n\nint count(const int i, const int j, const int M, const int N, const vector<vector<int>>& grid) {\n if (f[i][j] > 0) {\n return f[i][j];\n }\n const int x = grid[i][j];\n int ret = 1;\n if (... |
2,409 | <p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>
<p>Return <em>the number of <strong>strictly</strong> <strong>increasing</strong> paths in the grid such that you can start from <strong>any</strong> cell a... | 0 | {
"code": "class Solution {\npublic:\n int m;\n int n; \n int dp[1001][1001];\n long long MOD = 1e9 + 7;\n\n vector<vector<int>> directions = {\n {-1, 0}, // Top\n {1, 0}, // Bottom\n {0, -1}, // Left\n {0, 1}, // Right\n };\n bool isValidIndex(int i ... |
2,409 | <p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>
<p>Return <em>the number of <strong>strictly</strong> <strong>increasing</strong> paths in the grid such that you can start from <strong>any</strong> cell a... | 0 | {
"code": "class Solution {\npublic:\n\n// BFS gave TLE\n int mod = 1000000007;\n int dp[1001][1001];\n int n,m;\n int dfs(int i, int j, vector<vector<int>>& grid, int pre){\n if(i<0 || i>=n || j<0 || j>=m || pre >= grid[i][j]) return 0;\n if(dp[i][j] !=-1) return dp[i][j];\n\n long long... |
2,409 | <p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>
<p>Return <em>the number of <strong>strictly</strong> <strong>increasing</strong> paths in the grid such that you can start from <strong>any</strong> cell a... | 2 | {
"code": "#define MOD 1000000007\nunsigned long long dp[1001][1001];\n\nclass Solution {\npublic:\n unsigned long long helper(vector<vector<int>>& arr, int i, int j, int prevVal) {\n // Base case: if out of bounds or value is not increasing\n if (i < 0 || j < 0 || i >= arr.size() || j >= arr[0].size(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.