id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "class Solution\n{\npublic:\n void check_palin(vector<int> &arr, int &ans)\n {\n int one_cnt = 0;\n\n for (auto &it : arr)\n {\n if (it % 2)\n one_cnt++;\n }\n\n if (one_cnt <= 1)\n ans++;\n\n return;\n }\n void solve... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "class Solution {\npublic:\n int cnt = 0;\n\n void solve(TreeNode* root, vector<int> histogram) {\n if (!root)\n return;\n\n ++histogram[root->val];\n if (!root->left && !root->right) {\n int remainder = 0;\n for (int i = 0; i <= 9; ++i) {\n ... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "class Solution {\npublic:\n int pseudoPalindromicPaths (TreeNode* root) {\n unordered_map<int,int>map;\n return dfs(root,map);\n }\nprivate:\n int count = 0;\n\n int dfs(TreeNode*node,unordered_map<int,int>&countmap){\n if(!node)\n return 0;\n \n co... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\ntypedef struct TreeNode NodeBT_t;\n\nclass Solution final\n{\nprivate:\n int nbVali... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\ntypedef struct TreeNode NodeBT_t;\n\nclass Solution final\n{\nprivate:\n int nbVali... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\ntypedef struct TreeNode NodeBT_t;\n\nclass Solution final\n{\nprivate:\n int nbVali... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,568 | <p>Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be <strong>pseudo-palindromic</strong> if at least one permutation of the node values in the path is a palindrome.</p>
<p><em>Return the number of <strong>pseudo-palindromic</strong> paths going from the root node to ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n if (nums1.size() < nums2.size()) swap(nums1, nums2);\n int m = nums1.size();\n int n = nums2.size();\n vector<vector<int>> dp(2, vector<int>(n, 0));\n dp[0][0] = nums1[0] * nums2[... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& A, vector<int>& B) {\n int n = A.size(), m = B.size();\n vector<int> prev(m+1, 0), curr(m+1, 0);\n for(int i = 1; i <= n; ++i)\n {\n for(int j = 1; j <= m; ++j)\n {\n curr[j] = pre... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(std::vector<int>& nums1, std::vector<int>& nums2) {\n int m = nums1.size(), n = nums2.size();\n std::vector<int> current(n + 1, INT_MIN), previous(n + 1, INT_MIN);\n\n for (int i = 1; i <= m; ++i) {\n for (int j = 1; j <= n; +... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n1=nums1.size(), n2=nums2.size();\n if (n1<n2) // for less space, interchange nums1 & nums2\n return maxDotProduct(nums2, nums1);\n vector<vector<int>> dp(2, vector<int>(n2+1, IN... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& A, vector<int>& B) {\n int n = A.size(), m = B.size();\n vector<int> prev(m+1, 0), curr(m+1, 0);\n for(int i = 1; i <= n; ++i)\n {\n for(int j = 1; j <= m; ++j)\n {\n curr[j] = pre... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n int m = nums2.size();\n vector<int>dp(m+1);\n vector<int>ma(m+1);\n for(int i = n-1;i>=0;i--){\n for(int j = m-1;j>=0;j--){\n dp[... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size(), n2 = nums2.size(),\n dp[n1 + 1][n2 + 1];\n memset(dp, -1e6, sizeof(dp));\n\n dp[0][0] = 0;\n for(int i1 = 1; i1 <= n1; ++i1)\n for(int i2 = 1... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size(), n2 = nums2.size(),\n dp[n1 + 1][n2 + 1];\n memset(dp, -1e6, sizeof(dp));\n\n dp[0][0] = 0;\n for(int i1 = 1; i1 <= n1; ++i1)\n for(int i2 = 1... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size(), n2 = nums2.size(),\n dp[n1 + 1][n2 + 1];\n \n for(int i = 0; i <= n1; ++i)\n for(int j = 0; j <= n2; ++j)\n dp[i][j] = -1e6;\n\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int m = nums1.size();\n int n = nums2.size();\n \n int dp[m+1][n+1];\n\n for(int i=0; i<=m; i++){\n for(int j=0; j<=n; j++){\n dp[i][j]=INT_MIN;\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n int m = nums2.size();\n int dp[n+1][m+1];\n for(int i= 0;i<n+1;i++)\n {\n for(int j = 0 ;j<m+1;j++)\n {\n dp[i][j]=-1... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int dp[505][505];\n int func(int i,int j,vector<int>& nums1, vector<int>& nums2){\n if(i >= nums1.size() || j >= nums2.size()) return -1e9;\n int &ans = dp[i][j];\n if(ans != -1) return ans;\n\n ans = nums1[i] * nums2[j];\n ans = max(ans,... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int helper(int i,int j,vector<int>&nums1,vector<int>&nums2,int dp[501][501])\n {\n int m=nums1.size();\n int n=nums2.size();\n\n\n if(i==m || j==n)\n return 0;\n\n if(dp[i][j]!=-1)\n return dp[i][j];\n int ans=0;\n\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int dp[501][501];\n int helper(int i, int j, vector<int>& nums1, vector<int>& nums2){\n if(i>=nums1.size() || j>=nums2.size()){\n return 0;\n }\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n int ans=-1e8;\n int ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int dp[505][505];\n int solve(int i,int j,vector<int>&num1,vector<int>&num2){\n if(i==num1.size()) return 0;\n if(j==num2.size()) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int ans=-1e9;\n int val=num1[i]*num2[j];\n ans=max({a... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int dp[501][501];\n vector<int> nums1;\n vector<int> nums2;\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n this->nums1 = nums1;\n this->nums2 = nums2;\n memset(dp, -1, sizeof(dp));\n return solve(0, 0);\n }\n\n int s... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "const int MAXN = 505;\nconst int INF = 1e9 + 5;\nint n, m;\nint dp[MAXN][MAXN][2];\n\nclass Solution {\npublic:\n int maxDotProduct(vector<int>& a, vector<int>& b) {\n n = a.size();\n m = b.size();\n memset(dp, 0, sizeof(dp));\n dp[0][0][1] = a[0] * b[0]; \n for(int i ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int dp[501][501][2];\n int help(int i, int j, vector<int>& v1, vector<int>& v2 , int l){\n if(i==v1.size() || j==v2.size()){\n if(l==1)return 0;\n else return -1;\n }\n if(dp[i][j][l]!= INT_MIN) return dp[i][j][l];\n else{\... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\n int dp[500][500];\npublic:\n int product(int indexi, int indexj, vector<int> &nums1, vector<int> &nums2)\n {\n if(indexi>=nums1.size() || indexj>=nums2.size())\n {\n return 0 ; \n }\n if(dp[indexi][indexj]!=-1)\n return dp[indexi][ind... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int dp[501][501][2];\n int solve(vector<int>& nums1, vector<int>& nums2,int i,int j,int z)\n {\n int n=nums1.size();\n int m=nums2.size();\n if(i==n||j==m)\n {\n if(z==1)\n return 0;\n return INT_MIN;\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\n int dp[501][501];\npublic:\n int solve(vector<int>& nums1,vector<int>& nums2,int i,int j){\n if(i>=nums1.size() or j>=nums2.size())\n return INT_MIN;\n if(dp[i][j]!=INT_MIN)\n return dp[i][j];\n int ansi=solve(nums1,nums2,i,j+1);\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int temp[501][501];\nint solve(vector<int>& nums1, vector<int>& nums2,int i,int j){\n int n = nums1.size();\n int m = nums2.size();\n if(i == n || j == m) {\n return -1e9;\n }\n if(temp[i][j] != -1e9){\n return temp[i][j];\n }\n\n int dat... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\nint t[501][501];\n int solve(int i, int j,vector<int>&nums1,vector<int>&nums2){\n if(i<0 || j<0) return -1e9;\n if(t[i][j]!=-1) return t[i][j];\n int pick1=nums1[i]*nums2[j];\n int notpick1=solve(i-1,j,nums1,nums2);\n int notpick3=solve(i,j-1,nums1,nums2);\n i... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\n vector<int>a,b;\n int n,m;\n int dp[501][501][2];\n int rec(int i,int j,int length){\n if(i==n || j==m) {\n if(length==0) return -1e9;\n else return 0;\n }\n int &dpp=dp[i][j][length];\n if(dpp!=-1) return dpp;\n return... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 0 | {
"code": "class Solution {\npublic:\n int dp[501][501][3];\n int rec(int i,int j,int t,vector<int>&nums1,vector<int>&nums2,int n,int m){\n if(i>=n||j>=m){\n if(t==0)return -1e9;\n else return 0;\n }\n if(dp[i][j][t]!=0)return dp[i][j][t];\n int maxi=-1e9;\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 1 | {
"code": "class Solution {\n int dp[501][501][2];\n int solve(int i,int j,bool flag,vector<int>& nums1,vector<int>& nums2){\n int n = nums1.size();\n int m = nums2.size();\n if(i>=n || j>=m)return (flag?0:-1e9);\n if(dp[i][j][flag] != -1)return dp[i][j][flag];\n int v1 = nums1[i]*nums2... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 1 | {
"code": "class Solution {\n int dp[501][501][2];\n int solve(int i,int j,bool flag,vector<int>& nums1,vector<int>& nums2){\n int n = nums1.size();\n int m = nums2.size();\n if(i>=n || j>=m)return (flag?0:-1e9);\n if(dp[i][j][flag] != -1)return dp[i][j][flag];\n int v1 = nums1[i]*nums2... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 1 | {
"code": "class Solution {\npublic:\n int dp[501][501][2];\n int rec(int i,int j,int n,int m,int pair,vector<int>& nums1, vector<int>& nums2){\n if(i>=n||j>=m){\n if(pair!=0)\n return 0;\n return INT_MIN;\n }\n if(dp[i][j][pair]!=INT_MIN)\n r... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 1 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n int m = nums2.size();\n \n // Initialize dp array with INT_MIN to represent uninitialized values\n vector<vector<int>> dp(n + 1, vector<int>(m + 1, INT_MIN... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 1 | {
"code": "class Solution {\npublic:\n int solve(int i,int j,vector<int>& nums1, vector<int>& nums2,vector<vector<int>>& dp)\n {\n if(i>=nums1.size()||j>=nums2.size())\n return 0;\n if(dp[i][j]!=-1)\n return dp[i][j];\n int op1=0,op2=0,op3=0,op4=0;\n op1=0+solve(i+1,j,n... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 2 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n const int MINV = -1e9;\n int n = nums1.size(), m = nums2.size();\n vector<vector<int>> f(n + 1, vector<int>(m + 1, MINV));\n\n for(int i = 1; i <= n; ++i) {\n for(int j = 1; j... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 2 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n vector<vector<int>>dp(n+1,vector<int>(m+1));\n\n for(int i=1;i<=n;i++){\n for(int j=1;j<=m;j++){\n dp[i][j]=max({dp[i-1][... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(int m, int n, vector<int>& nums1, vector<int>& nums2, vector<vector<int>> &dp){\n\n if(m >= nums1.size() || n >= nums2.size()){\n return INT_MIN;\n }\n if(dp[m][n]!=-1) return dp[m][n];\n int take;\n take = nums1[m]*nu... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(int m, int n, vector<int>& nums1, vector<int>& nums2, vector<vector<int>> &dp){\n\n if(m >= nums1.size() || n >= nums2.size()){\n return INT_MIN;\n }\n if(dp[m][n]!=-1) return dp[m][n];\n int take;\n take = nums1[m]*nu... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n int func(int i, int j, vector<int>& nums1, vector<int>& nums2) {\n if(i == nums1.size() or j == nums2.size()){\n return -2e9;\n }\n if(dp[i][j] != -1) return dp[i][j];\n int ans = -2e9;\n ans = max(ans, nu... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\n static constexpr int solve(std::vector<int>& dp, const std::vector<int>& nums1, const std::vector<int>& nums2, const int i, const int j) {\n const int N = nums1.size();\n const int M = nums2.size();\n\n if (N <= i || M <= j)\n return std::numeric_limits... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int n,m;\n int solve(vector<int>& nums1, vector<int>& nums2,int i,int j,vector<vector<int>> &dp){\n if(i == n || j == m)\n return -1e8;\n \n if(dp[i][j] != -1e9)\n return dp[i][j];\n \n int val = nums1[i] * nums2[j];... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n \n int f(int i, int j, int m, int n, vector<int> &a, vector<int> &b, vector<vector<int>> &dp){\n if (i == m || j == n) return INT_MIN;\n\n if (dp[i][j] != INT_MIN) return dp[i][j];\n\n int val = a[i] * b[j] + max(0, f(i + 1, j + 1, m, n, a, b, dp));\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int maxDotProductHelper(vector<int>& nums1, vector<int>& nums2,int i,int j,vector<vector<int>>& dp){\n // base case\n if(i==nums1.size() || j==nums2.size()) return -1e9;\n\n if(dp[i][j]!=-1) return dp[i][j];\n int val=nums1[i]*nums2[j];\n in... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int f(int i, int j, vector<int> &nums1, vector<int> &nums2, int n, int m,vector<vector<int>> &dp){\n if(i==n || j == m){\n return -1e9;\n }\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n int op1 = nums1[i]*nums2[j];\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& arr1, vector<int>& arr2) {\n int n = arr1.size() , m = arr2.size();\n vector<vector<int>> dp(n,vector<int> (m,-1));\n function<int(int,int)> rec = [&](int i,int j){\n if(i<0 || j<0)return (int)-1e6;\n i... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\nint n,m;\npublic:\n int helper(vector <int> &nums1,vector<int> &nums2,int i,int j,vector<vector<int>> &dp){\n if(i >= n || j >= m){\n return INT_MIN;\n }\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n int ans = 0;\n ans +=... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\nint n,m;\npublic:\n int helper(vector <int> &nums1,vector<int> &nums2,int i,int j,vector<vector<int>> &dp){\n if(i >= n || j >= m){\n return INT_MIN;\n }\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n int ans = 0;\n ans +=... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "// Recursion + Memoization\nclass Solution {\npublic:\n \n // Very Simple Recursive Approach : Done\n int solve(vector<int>&nums1, vector<int>&nums2, int i, int j, vector<vector<int>>&dp)\n {\n if(i>=nums1.size() or j>=nums2.size()) \n return 0; \n \n if(dp[i][j... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\n vector<vector<int>> dp;\n vector<int> nums1;\n vector<int> nums2;\n\n int helper(int i, int j) {\n int n = nums1.size();\n int m = nums2.size();\n if(i >= n || j >= m) {\n return -1e9;\n }\n if(dp[i][j] != -1e9) {\n ret... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n const int inf = -1e8;\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n const int n = nums1.size(), m = nums2.size();\n \n int case1 = specialCase(nums1, nums2);\n if(case1 != -inf) return case1;\n \n int case2 = spec... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\nint dp[1000][1000];\nint f(int i,int j,vector<int>&nums1,vector<int>&nums2){\n int n=nums1.size();\n int m=nums2.size();\n if(i>=n||j>=m){\n return -1e9;\n }\n if(dp[i][j]!=-1e9){\n return dp[i][j];\n }\n int a,b;\n a=f(i+1,j,nums1,nums2);\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\n long long solve(vector<int>& nums1, vector<int>& nums2, int i, int j, vector<vector<long long>> &dp){\n if(i>=nums1.size() || j>=nums2.size()) return INT_MIN;\n if(dp[i][j]!=INT_MIN) return dp[i][j];\n\n long long ans=-1e7;\n long long product=nums1[i]*num... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "typedef long long ll;\n\nclass Solution {\n int helper(int ind1,int ind2,vector<int> &v1,vector<int> &v2,ll **dp)\n {\n if(ind1 >= v1.size() || ind2 >= v2.size())\n return INT_MIN;\n\n if(dp[ind1][ind2] != LONG_MIN)\n return dp[ind1][ind2];\n\n int tt = help... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n long infi=-1e9;\n int n=nums1.size();\n int m=nums2.size();\n vector<vector<long>> dp(n+1,vector<long>(m+1,0));\n for(int i=1;i<=n;i++){\n for(int j=1;j<=m;j++){\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<long>> dp(nums1.size() + 1, vector<long>(nums2.size() + 1));\n long ans = INT_MIN;\n for (int i = 0; i <= nums1.size(); ++i) {\n dp[i][0] = INT_MIN;\n }\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int maxDotProduct(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<long>> dp(nums1.size() + 1, vector<long>(nums2.size() + 1));\n long ans = INT_MIN;\n for (int i = 0; i <= nums1.size(); ++i) {\n dp[i][0] = INT_MIN;\n }\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<vector<long long>>& dp, int n, int m, vector<int>& nums1,\n vector<int>& nums2, int i, int j) {\n if (i < 0 || j < 0) {\n return INT_MIN;\n }\n if (dp[i][j] != -1) {\n return dp[i][j];\n }\n ... |
1,569 | <p>Given two arrays <code>nums1</code> and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
<p>Return the maximum dot product between <strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
<p>A subsequence of a array is a new array which ... | 3 | {
"code": "class Solution {\npublic:\n int Solve(int i, int j, bool taken, const vector<int>& nums1, const vector<int>& nums2, vector<vector<vector<int>>>& dp) {\n if (i == nums1.size()) return taken ? 0 :-1000000;\n if (j == nums2.size()) return taken ? 0 :-1000000;\n if (dp[i][j][taken] > -1... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvector<int> countSort(vector<int>& inputArray) {... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvector<int> countSort(vector<int>& inputArray) {... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n int cnt[1005];\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n for (int c : target) cnt[c]++;\n for (int c : arr) cnt[c]--;\n for (int i = 0; i <= 1000; i++)\n if (cnt[i]) return false;\n return true;\n }\n};"... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n if(target.size() != arr.size()){\n return false;\n }\n for(int i = 0; i < arr.size(); i++){\n auto it = find(target.begin(), target.end(), arr[i]);\n if(it == targ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int i = 0, flag1 = 1, flag2 = 1 ;\n int size = arr.size();\n\n while(flag1 != 0 || flag2 != 0){\n flag1 = 0;\n flag2 = 0;\n while (i < size - 1) {\n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n for(int i=0;i<target.size();i++){\n int j=i;\n bool flag=0;\n while(j<arr.size()){\n if(arr[j]==target[i]){\n reverse(arr.begin()+i,arr.begin()... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n sort(target.begin() , target.end());\n sort(arr.begin(), arr.end());\n for(int i = 0 ; i< arr.size() ; i++)\n {\n if(target[i]!=arr[i])\n {\n return f... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n for(int i = 0; i < target.size(); i++) {\n if(target[i] != arr[i]) {\n int j = i;\n while(j < arr.size() && arr[j] != target[i]) {\n j++;\n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n sort(arr.begin(), arr.end());\n sort(target.begin(), target.end());\n return target==arr;\n }\n};",
"memory": "17400"
} |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 0 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n sort(target.begin(),target.end());\n sort(arr.begin(),arr.end())\n;\nreturn target==arr; }\n};",
"memory": "17500"
} |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 1 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n vector<int> mem(1001,0);\n for(int i=0;i<target.size();i++){\n mem[target[i]]++;\n }\n for(int i=0;i<arr.size();i++){\n if(mem[arr[i]]==0)return false;\n me... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) \n {\n vector<int> m1(1001);\n \n for (int i = 0; i < arr.size(); i++)\n {\n m1[arr[i]]++;\n m1[target[i]]--;\n }\n \n for (int i = 1; i < 1001; i+... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) \n {\n vector<int> m1(1001);\n \n for (int i = 0; i < arr.size(); i++)\n {\n m1[arr[i]]++;\n m1[target[i]]--;\n }\n \n for (int i = 1; i < 1001; i+... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "//Approach: Keep an freq array, then just substreack when we face in element in the target array. In the end if there is any zero val, then print false;\n\nclass Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n\n int size = target.size();\n\n int targetArr[1... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int tFreq[1001] = {}, aFreq[1001] = {};\n for(int i = 0; i < target.size(); ++i) {\n ++tFreq[target[i]];\n ++aFreq[arr[i]];\n }\n\n for(int i = 0; i < 1001; ++i) {\n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int tFreq[1001] = {}, aFreq[1001] = {};\n for(int i = 0; i < target.size(); ++i) {\n ++tFreq[target[i]];\n ++aFreq[arr[i]];\n }\n\n for(int i = 0; i < 1001; ++i) {\n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int m[1001] = {0};\n for(auto x : target){\n m[x] += 1;\n }\n for(auto x : arr){\n m[x] -= 1;\n }\n for(auto x : m){\n if(x != 0){\n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int m[1001] = {0};\n for(int i = 0; i < target.size(); i++){\n m[target[i]]++;\n m[arr[i]]--;\n }\n for(auto x : m){\n if(x != 0){\n return f... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n array<int, 1001> m = {0};\n for(int i = 0; i < target.size(); i++){\n m[target[i]]++;\n m[arr[i]]--;\n }\n return all_of(m.cbegin(), m.cend(), [](auto v){ return v == ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) \n {\n vector<int> m1(1001);\n vector<int> m2(1001);\n \n for (int i = 0; i < arr.size(); i++)\n {\n m1[arr[i]]++;\n m2[target[i]]++;\n }\n \n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "\nclass Solution {\n public:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n vector<int> cnt1(1001);\n vector<int> cnt2(1001);\n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int m = target.size(), n = arr.size();\n\n vector<int> arr1(1001, 0);\n vector<int> arr2(1001, 0);\n\n for(int i = 0; i < m; i++){\n arr1[target[i]]++;\n arr2[arr[i]]+... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n int m = target.size(), n = arr.size(), maxTar = -1, maxArr = -1;\n\n vector<int> arr1(1001, 0);\n vector<int> arr2(1001, 0);\n\n for(int i = 0; i < m; i++){\n arr1[target[i]]++;\... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n // sort(target.begin() , target.end());\n // sort(arr.begin() , arr.end());\n priority_queue<int> q;\n \n for(auto i:target) q.push(i);\n int j = 0;\n while(!q.empty())... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n list<int> lst(arr.begin(), arr.end());\n int n = target.size();\n \n for (int i = 0; i < n; i++) {\n auto it = find(lst.begin(), lst.end(), target[i]);\n if (it != lst... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n map<int,bool> mp;\n for(int i=0;i<arr.size();i++)\n {\n bool flag = false;\n for(int j=0;j<arr.size();j++)\n {\n if(target[i]==arr[j] && !mp[j])\n ... |
1,556 | <p>You are given two integer arrays of equal length <code>target</code> and <code>arr</code>. In one step, you can select any <strong>non-empty subarray</strong> of <code>arr</code> and reverse it. You are allowed to make any number of steps.</p>
<p>Return <code>true</code> <em>if you can make </em><code>arr</code><em... | 2 | {
"code": "class Solution {\npublic:\n bool canBeEqual(vector<int>& target, vector<int>& arr) {\n multiset<int> st;\n int m = target.size() , n = arr.size();\n for(int i = 0; i<n ; i++)\n {\n st.insert(target[i]);\n }\n for(int i = 0 ; i<n ; i++)\n {\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.