id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 0 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) {\n\n int n = nums.size();\n vector<bool> dp(n, false); // valid arr: is nums arr valid from start to curr i\n\n dp[0]=false; // single num must be invalid\n\n for(int i=1; i<n; i++){\n\n //case1: \... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) {\n int n = nums.size();\n int dp[n];\n if(n==1)return 0;\n dp[0] = 0;\n dp[1] = (nums[0]==nums[1])?1:0;\n if(n==2)return dp[1];\n if(dp[1]==1 and nums[0]==nums[2]){\n dp[2] = 1... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) \n {\n int n=nums.size();\n vector<bool> dp1(n,false); \n vector<bool> dp2(n,false); \n vector<bool> dp3(n,false);\n for(int i=0;i<n;i++)\n {\n if(i>=2)\n {\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool solve(vector<int>& nums,int i){\n if(i <= -1){\n return true;\n }\n if(i >=2 && nums[i] == nums[i-1] && nums[i-1] == nums[i-2]){\n if(solve(nums,i-3)){\n return true;\n }\n }\n if(i >=1 &&... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\nint t[100005];\nbool isValid1(vector<int>& nums, int idx){\n\n if(idx+1 < nums.size() && nums[idx] == nums[idx+1]){\n return true;\n }\n\n return false;\n\n}\n\nbool isValid2(vector<int>& nums, int idx){\n\n if(idx+1 < nums.size() && idx+2 < nums.size() && nums... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int x[100010];\n bool dp(int i,vector<int> &nums){\n int n=nums.size();\n if(i==n) return true;\n if(n-i<2) return false;\n if(x[i]!=-1) return x[i];\n bool s1=false,s2=false;\n if(n-i>2){\n s1=(nums[i]==nums[i+1] && num... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001];\n bool two_con(int i, vector<int> &nums) {\n if (i+1 >= nums.size()) return false;\n if (nums[i] == nums[i+1]) return true;\n return false;\n }\n bool three_con(int i, vector<int> &nums) {\n if (i+2 >= nums.size()) return f... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n // int rec(int i, int &n, vector<int>& nums, vector<int> &dp)\n // {\n // if(i==n) return 1;\n\n // if(dp[i] != -1) return dp[i];\n\n // if(i < n-1)\n // {\n // if(nums[i] == nums[i+1])\n // {\n // if(rec(... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\nprivate:\n bool solve(int ind, int n, vector<int>&nums, vector<int>&dp){\n // base case\n if(ind==n){\n return true;\n }\n\n if(dp[ind]!=-1) return dp[ind];\n\n // nums[i] == nums[i+1]\n if(ind+1<n && nums[ind]==nums[ind+1]){\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& arr) {\n int n=arr.size();\n if(n<2)\n return false;\n vector<int> dp(n,0);\n if(arr[0]==arr[1])\n dp[1]=1;\n if(n>2){\n if(arr[0]==arr[1] && arr[1]==arr[2]){\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) {\n int n = nums.size();\n vector<int>dp(n, 0);\n int curlen = 1;\n int consecutive = 1;\n int i = 1;\n while(i < n){\n if(nums[i] == nums[i - 1]){\n curlen++;\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) {\n int n=nums.size();\n vector<int>dp(n,0);\n int len=1, consecutive=1;\n for(int i=1; i<n; i++){\n if(nums[i]==nums[i-1]) len++;\n else len=1;\n if(nums[i]-nums[i-1]==1) cons... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) {\n int n=nums.size();\n vector<int> dp(n+3,0);\n dp[n]=1;\n dp[n+1]=1;\n dp[n+2]=2;\n for(int i=n-1;i>=0;i--)\n {\n if(i+1<n && nums[i]==nums[i+1]) dp[i] |= dp[i+2];\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n vector<int>dp;\n bool Valid(vector<int>& nums, int start, int end){\n int len = end - start + 1;\n if(len > 3) return false;\n if(len == 2) return nums[start] == nums[end];\n if (len == 3) return (nums[start] == nums[start+1] && nums[start+1] ==... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n vector<int>dp;\n bool Valid(vector<int>& nums, int start, int end){\n int len = end - start + 1;\n if(len > 3) return false;\n if(len == 2) return nums[start] == nums[end];\n if (len == 3) return (nums[start] == nums[start+1] && nums[start+1] ==... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100005];\n int solve(int i, vector<int>&arr){\n if(i>=arr.size()){\n return true;\n }\n if(dp[i]!=-1) return dp[i];\n \n bool op1 = (i+1<arr.size()) and (arr[i]==arr[i+1]);\n bool op2 = (i+2<arr.size()) and (arr[i... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100005];\n int solve(int i, vector<int>&arr){\n if(i>=arr.size()){\n return true;\n }\n if(dp[i]!=-1) return dp[i];\n \n bool op1 = (i+1<arr.size()) and (arr[i]==arr[i+1]);\n bool op2 = (i+2<arr.size()) and (arr[i... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001];\n bool valid(int i, int k, vector<int>& nums){\n if(k-i + 1 == 2){\n return (nums[i] == nums[k]);\n }else{\n return (nums[i] == nums[i+1] && nums[i+1] == nums[k] || (nums[i+1] - nums[i] == 1 && nums[k]-nums[i+1] == 1));\n... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool check(vector<int>& nums, int idx) {\n if (idx < 0) return true;\n\n if (idx > 0 && nums[idx] == nums[idx-1]) {\n if (check(nums, idx-2)) return true;\n }\n\n if (idx > 1 && nums[idx] == nums[idx-1] && nums[idx-1] == nums[idx-2]) {\n... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) {\n int n = nums.size();\n return solve(n - 1, nums);\n }\n\n // checks if there is a valid partition ending with an index\n bool solve(int index, vector<int>& nums) {\n if (index <= 0) {\n return... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums) {\n int n = nums.size();\n return partition(nums, n - 1);\n }\n\n bool partition(vector<int>& nums, int index) \n {\n if (index < 0) {\n return true;\n }\n\n // if 2 are same\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001];\n bool sol(int i, int n, vector<int>&nums)\n {\n if(i >= n) return true;\n if(dp[i] != -1) return dp[i];\n bool ans = false;\n\n if(i + 2 < n){\n if(nums[i] == nums[i + 1] && nums[i + 1] == nums[i + 2]){\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool dp[100002];\n bool vis[100002];\n bool solve(int i, vector<int>& nums) {\n int n = nums.size();\n if (i == n) return true; // Base case: all elements are partitioned\n\n if(vis[i]) return dp[i];\n\n // Option 1: Check for pair\n if (i + 1 < n && nums... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001];\n bool solve(vector<int>& nums, int idx){\n int n = nums.size();\n if(idx >= n){\n return true;\n }\n if(dp[idx] != -1){\n return dp[idx];\n }\n bool result = false;\n if(idx+1 < n && nu... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100010];\n int n;\n int rec(int level,vector<int>& nums){\n if(level>=n)return true;\n if(dp[level]!=-1)return dp[level];\n \n if(level<n-1 and nums[level+1]==nums[level]){\n dp[level]=rec(level+2,nums);\n if(dp[level])return true;\... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001];\n bool solve(vector<int>& nums, int idx){\n int n = nums.size();\n if(idx >= n){\n return true;\n }\n if(dp[idx] != -1){\n return dp[idx];\n }\n bool result = false;\n if(idx+1 < n && nu... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\nint dp[100005];\n bool f(vector<int>& nums, int i){\n if(i>=nums.size()) return true;\n if(dp[i]!=-1) return dp[i];\n int n = nums.size();\n bool res=false;\n if(i+1<n && nums[i] == nums[i+1]){\n res = res | f(nums, i+2);\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "\n\n\n\nclass Solution {\npublic:\n\n int dp[100001];\n\n int helper(int ind, vector<int>& nums, int n){\n if(ind == n){\n return 1;\n }\n if(dp[ind] != -1){\n return dp[ind];\n }\n int ans = 0;\n if(ind <= (n-2) && nums[ind] == nums[ind... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001];\n bool solve(int ind , vector<int>& nums){\n int n = nums.size();\n if(ind == n ){\n return true ;\n }\n if(dp[ind] != -1)return dp[ind];\n\n if(ind + 1 < n && nums[ind] == nums[ind+1]){\n if(solve(in... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n int dp[100005];\n int func(int indx, vector<int>& nums){\n if (indx == nums.size()) return 1;\n if (dp[indx]!=-1) return dp[indx];\n int ch1 = 0, ch2 = 0, ch3 = 0;\n if (indx+1 < nums.size()){\n if (nums[indx] == nums[indx+1]) ch1 = f... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n\n bool ans(vector<int>& nums,int size,int i,vector<int>& memo){\n\n if(i >= size){\n return true;\n }\n\n if(memo[i] != -1){\n return memo[i];\n }\n\n if(i < (size-2) && nums[i] == nums[i+1] && nums[i] == nums[i+2])... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 1 | {
"code": "class Solution {\npublic:\n bool solve(int i, std::vector<int>& nums, int n,vector<int>&dp) {\n if (i == n) {\n return true;\n }\n\n if (dp[i] != -1) {\n return dp[i];\n }\n\n bool t = false, nt = false;\n if (i + 2 < n) {\n if (... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n int n;\n bool recsol(vector<int>&nums,int i,vector<int>&dp)\n {\n if(i>=n) return true;\n if(dp[i]!=-1) return dp[i];\n\n // Rule 1\n if(i+1<n && nums[i]==nums[i+1])\n {if(recsol(nums,i+2,dp)) return dp[i]=true;}\n // Rule 2\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n int n;\n bool recsol(vector<int>&nums,int i,vector<int>&dp)\n {\n if(i>=n) return true;\n if(dp[i]!=-1) return dp[i];\n\n // Rule 1\n if(i+1<n && nums[i]==nums[i+1])\n {if(recsol(nums,i+2,dp)) return dp[i]=true;}\n // Rule 2\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\n bool isValid(int index, vector<int>&nums,vector<int> &dp)\n {\n if(index>=nums.size())\n return false;\n bool p1=false,p3= false;\n int n =nums.size()-1;\n if(index == n-2)\n {\n if(nums[index]==nums[index+1] && nums[index+1]... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\n vector<optional<bool>> dp; \n bool validPartitionUtility(vector<int>& nums, vector<optional<bool>>& dp, int idx)\n {\n if(idx < 0)\n return true;\n\n if(dp[idx] != nullopt)\n return (dp[idx] == true);\n\n bool a = false;\n bool b = f... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n bool isValid(vector<int>& nums, vector<int> &vec, int pos){\n if(pos >= nums.size()){\n return 1;\n }else if(vec[pos] != -1){\n return vec[pos];\n }else if(nums.size()-pos < 2){\n return vec[pos] = 0;\n }else if(num... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n vector<int>dp;\n int n;\n bool memo(vector<int>&nums,int ind){\n if(ind == n)return dp[ind] = true;\n if(dp[ind] != -1)return dp[ind];\n\n bool two_same = false, three_same = false, three_consecutive = false;\n\n if(ind+1 < n && nums[ind] == ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n\nbool recursion(int ind,vector<int> &nums,vector<int> &dp){\n\n if(ind>=nums.size()) return true;\n if(dp[ind] != -1) return dp[ind];\n\n bool ans1=false,ans2=false,ans3=false;\n\n if(ind+2 < nums.size()){\n\n if(nums[ind]==nums[ind+1] && nums[ind+1]==nums[ind... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n int n;\n int dp[1000001];\n bool solve(vector<int>& nums, int i) {\n if (i >= n) {\n return true;\n }\n if(dp[i] != -1){\n return dp[i];\n }\n bool result = false;\n if (i < n - 1 && nums[i] == nums[i + 1])... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n \n bool solve(vector<int>& nums, int i, int n, vector<int> &dp){\n \n if(i == n){\n return true;\n }\n \n if(dp[i] != -1){\n return dp[i];\n }\n \n if(i + 1 < n and (nums[i] == nums[i+1])){\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\n int n;\n bool solve(int i,vector<int>&nums,vector<int>&dp){\n if(i>=n) return true;\n if(dp[i]!=-1) return dp[i];\n\n bool res=false;\n //Rule1:\n if(i+1<n && nums[i]==nums[i+1]){\n res=solve(i+2,nums,dp);\n if(res==true) ret... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n// [1,1,1,2,3,4,1]\n// 1 1 1 , 2 3 4 , 1 ->false -> 1 bach gaya\n bool check(int ind, vector<int>&nums, vector<int>&dp){\n // base case \n if(ind<0) return true; // empty array is always valid\n if(ind == 0) return false; // a single element is not valid;... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n int n;\n vector<int> a;\n int memo[100005];\n\n bool solve(int index) {\n if (index == n) return true;\n\n if (memo[index] != -1) return memo[index];\n\n if (index + 1 < n && a[index] == a[index + 1]) {\n if (solve(index + 2)) return m... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n vector<int> arr;\n int dp[100100];\n bool solve(int idx){\n int n = arr.size();\n\n if(idx==n)return true;\n if(idx>n)return false;\n if(dp[idx]!=-1)return dp[idx];\n // 1st\n bool ans = false;\n bool dd = false;\... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n bool rec(vector<int>& nums,int index,vector<int>& dp){\n //base case\n if(index >= nums.size() ) return 1;\n if(dp[index] != -1) return dp[index];\n\n int size=nums.size();\n int a=0;\n if(size-index >= 2 && (nums[index]==nums[index+1... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n//using Front partition technique\n//recursion + memoization\n//TC-O(n), SC-O(n)\nint f(int ind, vector<int> &nums, vector<int> &dp)\n{\n int n=nums.size();\n if(ind==n) return true;//base case, means array has been traversed\n if(dp[ind]!=-1) return dp[ind];\n\n bool... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\nprivate:\n bool solve(int ind, int n, vector<int>&nums, vector<int>&dp){\n // base case\n if(ind==n){\n return true;\n }\n\n if(dp[ind]!=-1) return dp[ind];\n\n // nums[i] == nums[i+1]\n if(ind+1<n && nums[ind]==nums[ind+1]){\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\n vector<int> dp;\n bool check(vector<int> &nums, int ind){\n if(ind>=nums.size()) return true;\n if(dp[ind]!=-1) return dp[ind];\n bool result=false;\n if(ind+1<nums.size() && nums[ind+1]==nums[ind]){\n result=result|check(nums, ind+2);\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 2 | {
"code": "class Solution {\npublic:\n int dp(vector<int>& nums, int n, int i, vector<int>& isValid){\n if(i>n) return 1;\n if(i==n) return 2;\n if(isValid[i]) return isValid[i];\n int ans = 1;\n if(n-i>=2 && nums[i]==nums[i+1]) ans = max(ans, dp(nums,n,i+2, isValid));\n i... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n vector<int> v;\n int dp[100005];\n int solve(int pos) {\n if(pos == v.size()) {\n return true;\n }\n if(dp[pos]!=-1) {\n return dp[pos];\n }\n if(pos +2 > v.size()) {\n dp[pos] = 0;\n return ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& nums, int ind, vector<int>& dp) {\n if (ind == nums.size())\n return true;\n if (dp[ind] != -1)\n return dp[ind];\n if (ind + 1 < nums.size() && nums[ind] == nums[ind + 1]) \n {\n if (helper... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n\n bool f(int i,vector<int> &nums,vector<int> &dp){\n\n if (i==nums.size()) return true;\n if (dp[i]!=-1) return dp[i];\n bool a=false,b=false,c=false;\n if (i+1<nums.size() && nums[i]==nums[i+1]) a=f(i+2,nums,dp);\n if (i+2<nums.size() && nu... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n\n bool isValidPartition(vector<int>& nums, vector<int>& dp, int i) {\n if(i >= nums.size()) return true;\n if(dp[i] != -1) return dp[i];\n\n if(i+1 < nums.size() && nums[i] == nums[i+1]){\n dp[i] = isValidPartition(nums, dp, i+2);\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n bool validPartition(vector<int>& nums, vector<bool>& visited, int i)\n {\n if(i == nums.size())\n return true;\n\n if(visited[i])\n return false;\n\n visited[i] = true;\n bool valid = false;\n\n if(i < nums.size() - ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\n \npublic:\n int dp[1000002];\n bool solve(vector<int>& nums,int i,int j){\n if(i==j){\n return true;\n }\n if(dp[i]!=-1){\n return dp[i];\n }\n bool res = false;\n if(i+1<j && nums[i]==nums[i+1]){\n res |... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n int solve(int i,vector<int> &nums,int n,vector<int> &dp){\n if(i==n){\n return 1;\n }\n if(dp[i]!=-1){\n return dp[i];\n }\n int a=0,b=0,c=0,d=0;\n int val=nums[i];\n\n if(i+1<n && nums[i+1]==val){\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\nint N;\nvector<int>NUMS;\nbool naive_recurse(int i) {\n if (i == N)\n return true;\n if (i + 1 < N and NUMS[i] == NUMS[i + 1] and naive_recurse(i + 2))\n return true;\n if (i + 2 < N and NUMS[i] == NUMS[i + 1] == NUMS[i + 2] and\n naive_recurse(i + 3))\n return t... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n \n vector<int> nums;\n vector<int> dp;\n bool solve(int index) {\n if (index == nums.size()) return true;\n\n if (dp[index] != -1) return dp[index];\n bool ans = false;\n\n if (index+1 < nums.size() && nums[index] == nums[index+1]) {\n ... |
2,443 | <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditi... | 3 | {
"code": "class Solution {\npublic:\n\n vector<int> dp;\n\n bool validPartition(vector<int>& nums) {\n for(int i = 0;i<nums.size();i++) dp.push_back(-1);\n return find(nums,0);\n }\n\n bool find(vector<int>& nums,int index){\n int n = nums.size();\n if(index==n) return true;\n... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 0 | {
"code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nclass Solution {\npublic:\n int longestIdealString(string& s, int k) {\n int seq[26]={0};// max len of seq ending at char(i+'a')\n int ans=0;\n for(char c: s){\n int i=c-'a';\n int j0=max(0, i-k), j1=min(i+k, 25)... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 0 | {
"code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nclass Solution {\npublic:\n int longestIdealString(string& s, int k) {\n int seq[26]={0};// max len of seq ending at char(i+'a')\n int ans=0;\n for(char c: s){\n int i=c-'a';\n int j0=max(0, i-k), j1=min(i+k, 25)... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n/*\ndp[n] length of the longest ideal string ending at index k\ndp[n] = dp[l] + 1, where l is the nearest index to n such that diff(t[l], t[n]) <= k\ndp[0] = 1;\n e d u k t d b k=2\ni 0 1 2 3 4 5 6\ndp 1 2 1 2 3 4 \n */\n int longestIdealString(string s, int k) {\n v... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n int n = s.size();\n vector<int> longest(26);\n vector<int> dp(n);\n\n for (int i = 0; i < n; ++i) {\n int curr = s[i] - 'a';\n int max_len = 0;\n\n for (int j = max(0, cur... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n\n long long n=s.size();\n vector<long long> dp(n+1,0);\n \n map<long long,long long> mp;\n\n long long ans=-1;\n for(int i=1;i<=n;i++){\n for(int j=(-k);j<=k;j++){\n if(mp[... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n\n long long n=s.size();\n vector<long long> dp(n+1,0);\n \n map<long long,long long> mp;\n\n long long ans=-1;\n for(int i=1;i<=n;i++){\n for(int j=(-k);j<=k;j++){\n if(mp[... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "// class Solution{\n// public:\n// vector<vector<int>>dp;\n// int helper(string& s,int ind,int k,int last){\n// if(ind>=s.length())return 0;\n// int l=0,r=0;\n// if(last!=-1 && dp[ind][last]!=-1)return dp[ind][last];\n// l=helper(s,ind+1,k,last);\n// if(last=... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int dp[100005][26];\n int solve(string &s, int &k, int i = 0, int prev = -1) {\n if(i >= size(s)) return 0;\n if(prev >= 0 && dp[i][prev] != -1) return dp[i][prev];\n\n int op1 = solve(s, k, i+1, prev), op2 = 0;\n if(prev == -1 || abs(s[i]-'a'-p... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:int dp[100000][27];\nint solve(int i,string &s,int &k,int prev)\n{\n if(i==s.size())\n {\n return 0;\n }\n if(dp[i][prev+1]!=-1)\n return dp[i][prev+1];\n\n int u=s[i]-'a'; int take=0;\n if(prev==-1 || abs(u-prev)<=k )\n {\n take=1+solve(i+1,s,... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\nint dp[100001][28];\n int longestIdealString(string s, int k) {\n memset(dp, -1, sizeof(dp));\n return solve(s, k, '{', 0);\n }\n\n int solve(string& s, int& k, char prev, int index){\n if(index >= s.length())return 0;\n if(dp[index][prev-'a']... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n string s;\n int k;\n vector<int> cache;\n\n int longestIdealString(string s, int k) {\n this->s = s;\n this->k = k;\n \n cache = vector<int>(s.size(), -1e9);\n int ans = 0;\n for (int i = 0; i < s.size(); i++) {\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n string s;\n int k;\n vector<int> cache;\n\n int longestIdealString(string s, int k) {\n this->s = s;\n this->k = k;\n \n cache = vector<int>(s.size(), -1e9);\n int ans = 0;\n for (int i = 0; i < s.size(); i++) {\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n string s;\n int k;\n vector<int> cache;\n\n int longestIdealString(string s, int k) {\n this->s = s;\n this->k = k;\n \n cache = vector<int>(s.size(), -1e9);\n int ans = 0;\n for (int i = 0; i < s.size(); i++) {\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n string s;\n int k;\n vector<int> cache;\n\n int longestIdealString(string s, int k) {\n this->s = s;\n this->k = k;\n \n cache = vector<int>(s.size(), -1e9);\n int ans = 0;\n for (int i = 0; i < s.size(); i++) {\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n string s;\n int k;\n vector<int> cache;\n\n int longestIdealString(string s, int k) {\n this->s = s;\n this->k = k;\n \n cache = vector<int>(s.size(), -1e9);\n int ans = 0;\n for (int i = 0; i < s.size(); i++) {\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "int fn (int node , vector<int>&dp, vector<vector<int> > &m, int k , string &s )\n{\n if (node>=s.size()) return 0;\n\n if (dp[node]!=-1) return dp[node];\n int res = 0;\n\n for (int i = 0; i<=k; i++){\n if (s[node] + i <= 'z'){\n int ch = s[node] + i - 'a';\n int id... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "int fn (int node , vector<int>&dp, unordered_map<char , vector<int> > &m, int k , string &s )\n{\n if (node>=s.size()) return 0;\n\n if (dp[node]!=-1) return dp[node];\n int res = 0;\n\n for (int i = 0; i<=k; i++){\n if (s[node] + i <= 'z'){\n char ch = s[node] + i;\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n unordered_map<char, int> cm;\n unordered_map<int, int> m;\n int res = 0;\n for(int i = 0; i<s.size(); i++){\n char c = s[i];\n m[i] = 1;\n for(char j = 'a'; j<='z'; j++){\... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int N,K;\n int dp[100001][123];\n int solve(string &s, int i, char last_char){\n\n if(i>=N) return 0;\n if(dp[i][last_char] != -1) return dp[i][last_char];\n\n int take=0,skip=0;\n\n if(last_char=='0' || abs(last_char-s[i])<=K) {\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n\n int dp[100005][150];\n\n int find(int index,string &s,int &k,char prevChar){\n \n if(index == s.size()) return 0;\n\n if(dp[index][prevChar] != -1) return dp[index][prevChar];\n\n int option1 = 0;\n int option2 = 0;\n\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n vector<int>dp(26, 0);\n int i, n;\n n = s.size();\n int j;\n for(i=0;i<n;i++){\n vector<int>next = dp;\n for(j=0;j<26;j++){\n if(abs(j-(s[i]-'a'))>k)continue;\n... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n int n=s.size();\n int i,j;\n vector<int> dp(26,0);\n for(i=0;i<n;i++) {\n vector<int> temp=dp;\n for(j=0;j<=25;j++) {\n if(abs(s[i]-j-'a')<=k) {\n t... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n// int solve(int i, string s, int k, int prev, vector<vector<int>>&mem){\n// if(i>=s.length()){\n// return mem[i][prev+1]=0;\n// }\n// if(mem[i][prev+1] != -1){\n// return mem[i][prev+1];\n// }\n// int ans = -1e8;\n// if(prev ==-1 || abs(s... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string_view s, int k) {\n vector<vector<int>> dp(s.size()+1, vector(26, 0));\n\n for (int i = 1; i <= s.size(); ++i) {\n for (int j = 0; j < 26; ++j) {\n if (abs(s[i-1] - (j+'a')) > k) dp[i][j] = dp[i-1][j];\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string_view s, int k) {\n vector<vector<int>> dp(s.size()+1, vector(26, 0));\n\n for (int i = 1; i <= s.size(); ++i) {\n for (int j = 0; j < 26; ++j) {\n if (abs(s[i-1] - (j+'a')) > k) dp[i][j] = dp[i-1][j];\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n int n = s.length();\n vector<vector<int>> dp(n + 1, vector<int>(27, 0));\n\n for (int idx = 1; idx <= n; ++idx) {\n int curCharIndex = s[idx - 1] - 'a';\n\n for (char prev = 'a'; prev <= 'z... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n int solve(string &s,int &k,char prev_ch,int curr,vector<vector<int>>&dp){\n\n if(curr>=s.size()){\n\n return 0;\n }\n\n if(dp[prev_ch-'a'][curr]!=-1){\n\n return dp[prev_ch-'a'][curr];\n }\n int include=0;\n if(p... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n // int f(int i, string& s, char prev, int& k, vector<vector<int>>& dp) {\n // if (i < 0) return 0;\n\n // int prevIdx = (prev == '{') ? 0 : (prev - 'a' + 1);\n // if (dp[i][prevIdx] != -1) return dp[i][prevIdx];\n\n // int take = 0, nottake = 0;\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 2 | {
"code": "class Solution {\npublic:\n\n // int solve(int i, char prev , string s, int k, vector<vector<int> > &dp)\n // {\n // if(i==s.size())\n // {\n // return 0;\n // }\n\n // if(dp[i][prev-'a']!=-1) return dp[i][prev-'a'];\n\n // int nontake = solve(i+1,prev,s,... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\n\n int func(int prev, int i , string s, int k, int n )\n {\n if(i>=n){\n return 0;\n }\n int l1= func(prev,i+1,s,k,n);\n int l2=0;\n if(prev==0|| abs(int(s[i]-96-prev)) <=k)\n {\n l2= 1+func(int(s[i])-96,i+1,s,k,n);\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n int longestIdealStringRec(string &s,int k,int i,int prev){\n if(i>=s.size()){\n return 0;\n }\n int include = 0;\n int exclude = 0;\n if(prev==-1 or abs(s[i]-s[prev])<=k){\n include = 1 + longestIdealStringRec(s,k,i+1,i... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n int n = s.size();\n vector<vector<int>>dp(n,vector<int>(26,0));\n dp[0][s[0]-'a']=1;\n int ans = 1;\n for(int i=1;i<n;i++){\n for(int j=0;j<26;j++){\n dp[i][j] = dp[i-1][j... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n int f(int index, string& s, int k, char prev, vector<vector<int>>& dp) {\n if (index < 0) return 0; // Base case: no characters to consider, length is 0\n \n if (dp[index][prev - 'a'] != -1) return dp[index][prev - 'a'];\n \n int take = 0;\... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n // int solve(string s, int k , int index,char prev,vector<vector<int>> &dp ){\n // if(index == s.size()) return 0;\n // int take = INT_MIN;\n // if(dp[index][prev-'a']!=-1) return dp[index][prev-'a'];\n\n // if(prev == 'z' +1 || abs(s[index] - prev) ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n int longestIdealString(string s, int k) {\n unordered_map<char, int> ump;\n for (char c = 'a'; c <= 'z'; ++c)\n ump[c] = c - 'a';\n \n int n = s.length();\n vector<vector<int>> dp(n + 1, vector<int>(27, 0));\n\n for (int in... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n int solve(int index, const string& s, int k, int lastChar, vector<vector<int>>& dp) {\n if (index >= s.length()) {\n return 0;\n }\n\n if (lastChar != -1 && dp[index][lastChar] != -1) {\n return dp[index][lastChar];\n }\n\n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(string& s,int idx,char prev,int k,vector<vector<int>>&dp){\n if(idx==s.size())\n return 0;\n if(prev!='{' && dp[idx][prev-'a']!=-1)\n return dp[idx][prev-'a'];\n int dontTake= solve(s,idx+1,prev,k,dp);\n \n ... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n #define vi vector<int>\n #define vvi vector<vi>\n vvi dp;\n int n;\n\n int f(int i, char c, string &s, int k) {\n if (i == n) return 0;\n if (c != '#' && dp[i][c - 'a'] != -1) return dp[i][c - 'a'];\n int nt = f(i + 1, c, s, k);\n int t... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\npublic:\n #define vi vector<int>\n #define vvi vector<vi>\n vvi dp;\n int n;\n\n int f(int i, char c, string &s, int k) {\n if (i == n) return 0;\n if (c != '#' && dp[i][c - 'a'] != -1) return dp[i][c - 'a'];\n int nt = f(i + 1, c, s, k);\n int t... |
2,444 | <p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
<ul>
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
<li>The absolute d... | 3 | {
"code": "class Solution {\nprivate:\n vector<vector<int>> dp;\n\n int helper(int ind, char prev, string& s, int k) {\n if (ind == s.size()) {\n return 0;\n }\n \n int prevIndex = (prev == -1) ? 0 : prev - 'a' + 1;\n if (dp[ind][prevIndex] != -1) {\n return ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.