id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool isSubPath(ListNode* head, TreeNode* root) {\n if(!root) return false;\n\n function<bool(ListNode*, TreeNode*)> dfs = [&](ListNode* head, TreeNode* root) -> bool {\n if(!head) return true;\n if(!root || head->val != root->val) return fa... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n * Definition for a binary tree ... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool isSubPath(ListNode* head, TreeNode* root) {\n vector<TreeNode*> nums; \n inordertraversal(root, nums, head->val);\n for(auto&node:nums)\n {\n if(check(head,node))\n {\n return true;\n }\n ... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool isSubPath(ListNode* head, TreeNode* root) {\n vector<TreeNode*> nums; \n inordertraversal(root, nums, head->val);\n for(auto&node:nums)\n {\n if(check(head,node))\n {\n return true;\n }\n ... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "class Solution\n{\nprivate:\n ListNode* head;\n bool found = false;\n\npublic:\n bool isSubPath(ListNode* const head, \n TreeNode* const root)\n {\n this->head = head;\n\n ListNode* lnodes_next[101] = { };\n int l_next = 0;\n\n lnodes_next[l_next++]... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "class Solution\n{\nprivate:\n ListNode* head;\n bool found = false;\n\npublic:\n bool isSubPath(ListNode* const head, \n TreeNode* const root)\n {\n this->head = head;\n\n ListNode* lnodes_next[101] = { };\n int l_next = 0;\n\n lnodes_next[l_next++]... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 0 | {
"code": "class Solution {\npublic:\n int integerBreak(int n) {\n if (n <= 3) return n - 1;\n \n int product = 1;\n while (n > 4) {\n product *= 3;\n n -= 3;\n }\n // The remaining n is 2, 3, or 4, so we multiply it\n product *= n;\n \n... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 0 | {
"code": "class Solution {\npublic:\n int integerBreak(int n) {\n // If an optimal product contains a factor f >= 4, then we can replace it\n // with 2 and f - 2 without losing optimality. As 2(f - 2) = 2f - 4 >= f,\n // we never need a factor >= 4, meaning we only nee... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 0 | {
"code": "class Solution {\n public:\n int integerBreak(int n) {\n // If an optimal product contains a factor f >= 4, then we can replace it\n // with 2 and f - 2 without losing optimality. As 2(f - 2) = 2f - 4 >= f,\n // we never need a factor >= 4, meaning we only need factors 1, 2, and 3\n // (and 1 ... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 0 | {
"code": "class Solution {\npublic:\n int integerBreak(int n) {\n if (n == 2) return 1;\n if (n == 3) return 2;\n\n int product = 1;\n \n // Chia n thành các số 3 càng nhiều càng tốt\n while (n > 4) {\n product *= 3;\n n -= 3;\n }\n \n ... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 3 | {
"code": "class Solution {\npublic:\n int integerBreak(int n) {\n vector<int> dp(n+1,0);\n if(n == 2) return 1;\n if(n == 3) return 2;\n dp[1] = 1;\n dp[2] = 2; // not correct actually\n dp[3] = 3; // not correct actually\n\n for(int i = 4; i <= n; i++){\n ... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 3 | {
"code": "class Solution {\npublic:\n int integerBreak(int n) {\n vector<int> dp(n+1);\n dp[1] = 1;\n for(int i = 2; i <= n; i++){\n int max_brk = 0;\n for(int j = 1; j < i; j++) {\n max_brk = max(max_brk, max(dp[i-j]*j, (i-j)*j));\n }\n ... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 3 | {
"code": "class Solution {\npublic:\n void searchAndFind(vector<int>&dp,int right){\n int l = 1;\n int target = right;\n int r = right -1;\n while(l <= r){\n int total = l + r;\n if(total == target){\n dp[target] = max({dp[l]*r, dp[r]*l, dp[target],... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 3 | {
"code": "class Solution {\npublic:\n int func(int n, int cnt, vector<vector<int>>& dp){\n if(n <= 0){\n if(cnt < 2) return 0;\n return 1;\n }\n if(dp[n][cnt] != -1) return dp[n][cnt];\n int ans = 0;\n for(int i = 1; i <= n; i++){\n ans = max(ans... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 3 | {
"code": "class Solution {\npublic:\n//--------------------------------->ओम नमो भगवते वासुदेवाय<---------------------------------------------------------------\n// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡋⠉⢋⣝⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣆⣘⣿⢿⡟⡷⢶⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n// ⠀⠀... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 3 | {
"code": "class Solution {\npublic:\n\n int f(int n , int i , vector<vector<int>>&dp){\n if( n == 0 ) return 1;\n if( i == 0 ) return 0;\n\n if(dp[i][n]!=-1) return dp[i][n];\n\n long long np = f(n , i - 1 , dp);\n\n long long p = 0;\n if(i<=n){\n p = i*f(n - i... |
343 | <p>Given an integer <code>n</code>, break it into the sum of <code>k</code> <strong>positive integers</strong>, where <code>k >= 2</code>, and maximize the product of those integers.</p>
<p>Return <em>the maximum product you can get</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
... | 3 | {
"code": "#include <vector>\n#include <algorithm>\n#include <climits>\n\nclass Solution {\npublic:\n int f(int i,int sum,vector<int> &v,int n, vector<vector<int>> &dp) {\n if(i >= v.size() || sum == n) return 1;\n if(sum > n) return 0;\n\n if(dp[i][sum] != -1) return dp[i][sum];\n if(v[i... |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 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\ninline bool isdigit(char c) {\n return c >= '... |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 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\ninline bool isdigit(char c) {\n return c >= '... |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 0 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int n = s.size();\n int left = 0;\n int right = n-1;\n while(left <= right ){\n swap(s[left], s[right]);\n left++;\n right--;\n }\n }\n};",
"memory": "26900"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 0 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int j=s.size()-1;\n int i=0;\n while(i<=j){\n swap(s[i],s[j]);\n i++;\n j--;\n }\n\n }\n};",
"memory": "27000"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 0 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int j = s.size()-1;\n int i=0;\n while(i<j){\n swap(s[i],s[j]);\n j--;\n i++;\n \n }\n \n }\n};",
"memory": "27000"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 0 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int start = 0;\n int end = s.size() - 1;\n while(start<end){\n swap(s[start++],s[end--]);\n }\n }\n};",
"memory": "27100"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 0 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int start = 0;\n int end = s.size() - 1;\n while(start<end){\n swap(s[start++],s[end--]);\n }\n }\n};",
"memory": "27100"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 0 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n\t\tint start = 0;\n\t\tint end = static_cast<int> (s.size()) - 1;\n\t\tchar c;\n\n\t\tif (end <= 0) {\n\t\t\treturn;\n\t\t}\n\n\t\twhile (start < end) {\n\t\t\tc = s[end];\n\t\t\ts[end] = s[start];\n\t\t\ts[start] = c;\n\n\t\t\tstart++;... |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 0 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int left=0;\n int right=s.size()-1;\n char temp;\n while(left<right){\n temp=s[left];\n s[left]=s[right];\n s[right]=temp;\n left++;\n right--;\n ... |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 1 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n reverse(s.begin(), s.end());\n // int left=0;\n // int right=s.size()-1;\n // char temp;\n // while(left<right){\n // temp=s[left];\n // s[left]=s[right];\n // s[right]... |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 1 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int h=s.size();\n for(int i=0; i<h/2; i++){\n int temp=s[i];\n s[i]=s[h-i-1];\n s[h-i-1]=temp;\n }\n }\n};",
"memory": "27300"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 3 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n int start=0;\n int end=s.size()-1;\n while(start<=end){\n swap(s[start++],s[end--]);\n }\n }\n};",
"memory": "27400"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 3 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n long long int n=s.size();\n for(long long int i=0;i<n;i++){\n swap(s[i],s[n-1]);\n n--;\n }\n for(auto ch:s){\n cout<<ch<<\" \";\n }\n }\n};",
"memory": "27400"
} |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 3 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n stack <char> st ; \n for(int i=0 ; i<s.size() ; i++){\n st.push(s[i]) ;\n }\n s.clear() ;\n while( ! st.empty()){\n s.push_back(st.top()) ;\n st.pop() ;\n }\n ... |
344 | <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p>
<p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a> with <code>O(1)</code> extra memory.</p>
<p> </p>
<p><strong... | 3 | {
"code": "class Solution {\npublic:\n void reverseString(vector<char>& s) {\n stack <char> ns;\n for(int i=0;i<s.size();i++)\n ns.push(s[i]);\n for(int i=0;i<s.size();i++)\n {\n s[i]=ns.top();\n ns.pop();\n }\n }\n};",
"memory": "27800"
} |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 0 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n int start = 0;\n int end = s.size() - 1;\n\n while (start < end) {\n if (!isVowel(s[start])) {\n start++;\n } else if (!isVowel(s[end])) {\n end--;\n } else ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 0 | {
"code": "class Solution {\npublic:\n bool check(char ch) {\n return (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U');\n }\n\n string reverseVowels(string s) {\n int l = 0, r = s.size() - 1;\n while (l < r) ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 0 | {
"code": "class Solution {\npublic:\n bool isVowel(char i){\n if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or\n i=='A' or i=='E' or i=='I' or i=='O' or i=='U'){\n return true;\n }\n return false;\n }\n string reverseVowels(string s) {\... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 0 | {
"code": "class Solution {\n bool isVowel(char c){\n return c == 'a' || c == 'i' || c == 'e' || c == 'o' || c == 'u'\n || c == 'A' || c == 'I' || c == 'E' || c == 'O' || c == 'U';\n }\npublic:\n string reverseVowels(string s) {\n int start=0,end=s.size()-1;\n string check = \... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 0 | {
"code": "class Solution {\npublic:\n bool isVowel(char c) {\n c = tolower(c);\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {\n return true;\n }\n return false;\n }\n string reverseVowels(string s) {\n int x = 0 , y = s.length() - 1;\n\n while (x < y) {\n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int i = 0;\n int j = s.size() - 1;\n\n // Function to check if a character is a vowel\n auto isVowel = [](char c) {\n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\nbool isvowel(char c){\n c = tolower(c); \n if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') return true;\n return false;\n}\n string reverseVowels(string s) {\n string p=s;\n int i=0,j=s.length()-1;\n while(i<j){\n if(isvowel(p[i]) &&... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n vector<char> S;\n int itr=0;\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i]=='A' || s[i]=='e' || s[i]=='E' || s[i]=='i' || s[i]=='I' || s[i]=='o' || s[i]=='O' || s[i]=='u' ||s[i]=='U' ){\n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n // Convert the input string to a character array.\n string word = s;\n int start = 0;\n int end = s.length() - 1;\n string vowels = \"aeiouAEIOU\";\n \n // Loop until the start pointer is no l... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n char vowels[] = {'a','e','i','o','u','A','E','I','O','U'};\n int len = sizeof(vowels)/sizeof(vowels[0]);\n vector<char> v;\n for(int i=0;i<s.length();i++){\n for(int j=0;j<len;j++){\n if(... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n char vowels[] = {'a','e','i','o','u','A','E','I','O','U'};\n int len = sizeof(vowels)/sizeof(vowels[0]);\n vector<char> v;\n for(int i=0;i<s.length();i++){\n for(int j=0;j<len;j++){\n if(... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n bool vowel(char ch){\n return (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');\n }\n\n string reverseVowels(string s) {\n string vowels = \"\";\n for(int i=0;i<s.length();i++){\n if(vowel(s[i])){... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n int i=0;\n int n=s.size()-1;\n set<char> ch{'a','e','i','o','u','A','E','I','O','U'};\n while(i<n){\n if(ch.find(s[n])==ch.end()) n--;\n else if(ch.find(s[i])==ch.end()) i++;\n else {s... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n stack<char> sw;\n char dd;\n\n // Push vowels onto the stack\n for (int i = 0; i < s.length(); i++) {\n if (s[i] == 'I' || s[i] == 'i' || s[i] == 'a' || s[i] == 'A' || \n s[i] == 'E' || s... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n set<char>vowels={'A','E','I','O','U','a','e','i','o','u'};\n int l=0;\n int r=s.size()-1;\n while(l<r){\n while(l<r&&vowels.find(s[l])==vowels.end()){\n l++;\n }\n while (l<r&&vowels.find(s[r]) == ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n set<char>vowels={'A','E','I','O','U','a','e','i','o','u'};\n int l=0;\n int r=s.size()-1;\n while(l<r){\n while(l<r&&vowels.find(s[l])==vowels.end()){\n l++;\n }\n while(l<r&&vowels.find(s[r])... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 2 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n int len = s.size();\n string result = \"\";\n vector<int> vec;\n\n for (int i = 0; i < len; i++) {\n if (s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n vector<char>buffer;\n string ans;\n for(int i = 0; i < s.length(); i++)\n {\n if(s[i]=='a'||s[i]=='A'||s[i]=='e'||s[i]=='E'||s[i]=='i'||s[i]=='I'||s[i]=='o'||s[i]=='O'||s[i]=='u'||s[i]=='U')\n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n int len = s.size();\n string result = \"\";\n vector<int> vec;\n\n for (int i = 0; i < len; i++) {\n if (s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n vector<char> v;\n for(int i=0;i<s.length();i++){\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='A' || s[i]=='E' || s[i]=='I' || s[i]=='O'|| s[i]=='U'){\n v.push_back(s[i])... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n unordered_set<char> vowels ({'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'});\n\n for (int i = 0, j = s.size()-1; i < j; i++) {\n if ( !vowels.contains(s[i]) )\n continue;\n \n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u', \n 'A', 'E', 'I', 'O', 'U'}; // Use set for O(1) lookup\n int start = 0;\n int end = s.size() - 1;\n\n while (start < en... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n string vowel = \"\";\n unordered_set<char> vowels = {'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'};\n\n for (int i = 0; i < s.size(); i++) {\n if (vowels.count(s[i])) { \n vowel.push_back(s[... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n vector<int> ind;\n vector<char> vow;\n for(int i=0;i<s.length();i++){\n if(s[i]=='a'||s[i]=='A'||s[i]=='e'||s[i]=='E'||s[i]=='i'||s[i]=='I'||s[i]=='o'||s[i]=='O'||s[i]=='u'||s[i]=='U'){\n ind.pu... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n vector<int> v;\n vector<char> v1;\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i]=='e' ||s[i]=='i' || s[i]=='o'|| s[i]=='u' || s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'){\n \n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n vector<char> vowels;\n string all_vowel = \"aeiouAEIOU\";\n int left = 0;\n int right = s.size() - 1;\n bool left_vowel = false;\n bool right_vowel = false;\n while(left <= right){\n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "\nclass Solution {\npublic:\n string reverseVowels(string s) {\n int i = 0, j = s.size()-1;\n unordered_set<char> vovels;\n vovels.insert('a');\n vovels.insert('e');\n vovels.insert('i');\n vovels.insert('o');\n vovels.insert('u');\n vovels.insert(... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n string vs = \"\";\n unordered_set<char> vovelSet;\n vovelSet.insert('a');\n vovelSet.insert('e');\n vovelSet.insert('i');\n vovelSet.insert('o');\n vovelSet.insert('u');\n vovelSet.inse... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n vector<pair<char, int>> vowels;\n string vowelSet = \"aeiouAEIOU\";\n \n for (int i = 0; i < s.size(); ++i) {\n if (vowelSet.find(s[i]) != string::npos) {\n vowels.push_back({s[i], i});\n... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n string result = \"\";\n stack<char> strStack;\n vector<char> vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};\n\n for (char c : s) {\n if (find(vowels.begin(), vowels.end(), c) != vowels.end... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n int n = s.length(),k = 0;\n string st = s;\n vector<char> v = {'a','e','i','o','u','A','E','I','O','U'};\n vector<pair<char,int>> store;\n \n for(int i = 0; i < n;i++){\n if(find(v.begin()... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n int i=0, j=s.size()-1;\n string x = \"aeiouAEIOU\";\n map<char, bool> mp;\n for(auto &ch:x) mp[ch]=true;\n while(i<j){\n while(i<j && mp.find(s[i])==mp.end()) i++;\n while(i<j && mp.fi... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "/*\nAa - 65/97\nEe - 69/101\nIi - 73/105\nOo - 79/111\nUu - 85/117\n\non finding vowel, note which vowel & location\n*/\n\nclass Solution {\npublic:\n string reverseVowels(string s) {\n vector<char> vowels;\n vector<size_t> positions;\n\n for (auto i = 0; i < s.length(); i++) {\n ... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n \n\n int indexFromStart = 0;\n int indexFromEnd = s.length() - 1;\n\n while (indexFromStart < indexFromEnd) {\n\n // inc the Startindex until its on a wowel\n\n while (!isVowel(s[indexFromStart]... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n string reverseVowels(string s) {\n unordered_set<char> vowels{\n 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};\n vector<char> exist_vowels;\n for (char c : s) {\n if (vowels.count(c) > 0) {\n exist_vowels.push_bac... |
345 | <p>Given a string <code>s</code>, reverse only all the vowels in the string and return it.</p>
<p>The vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>, and they can appear in both lower and upper cases, more than once.</p>
... | 3 | {
"code": "class Solution {\npublic:\n bool check(char c){\n string str = \"aeiouAEIOU\";\n \n for(int i=0;i<str.length();i++)\n {\n if(str[i]==c) return true;\n }\n \n return false;\n }\n string reverseVowels(str... |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n // vector<int> alt(gain.size()+1,0);\n // for(int i=0;i<gain.size();i++){\n // alt[i+1]=gain[i]+alt[i];\n // }\n // return *max_element(alt.begin(),alt.end());\n int cur=0;\n int m... |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int current_alt = 0, max_alt = 0;\n for(int alt: gain){\n current_alt += alt;\n max_alt = max(current_alt,max_alt);\n }\n return max_alt;\n }\n};",
"memory": "9800"
} |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int currAlt = 0;\n int maxAlt = 0;\n for(int i = 0; i < gain.size(); i++){\n currAlt += gain[i];\n maxAlt = max(maxAlt, currAlt);\n }\n return maxAlt;\n }\n};",
"memory": ... |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int alt = 0;\n int maxAlt = 0;\n for(int step : gain){\n alt += step;\n maxAlt = max(maxAlt, alt);\n }\n return maxAlt;\n }\n};",
"memory": "9900"
} |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int prefixSum=0;\n int maxAltitude=0;//starts from 0 altitude\n for(int g:gain){\n prefixSum+=g;\n maxAltitude=max(maxAltitude, prefixSum);\n }\n return maxAltitude;\n }\n};... |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int height=0;\n int maxheight=0;\n\n for (int i =0;i<gain.size();i++){\n height=height+gain[i];\n if(maxheight<height){\n maxheight=height;\n\n }\n }\n ... |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int ans = 0;\n int st = 0;\n for(int i = 0;i<gain.size();i++){\n st+= gain[i];\n ans = max(ans,st);\n }\n return ans;\n }\n};",
"memory": "10000"
} |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n int currAltitude = 0;\n for (int& n : gain) {\n int nextAltitude = currAltitude + n;\n n = currAltitude;\n currAltitude = nextAltitude;\n }\n gain.push_back(currAltitude);\... |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 0 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) {\n vector <int> result;\n int size = gain.size();\n result.push_back(0);\n\n for(int i = 0 ; i<size ; i++){\n result.push_back(result[i]+gain[i]);\n }\n return *max_element(result.beg... |
1,833 | <p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>
<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the ... | 2 | {
"code": "class Solution {\npublic:\n int largestAltitude(vector<int>& gain) \n {\n int maxalt = 0;\n int currentalt = 0;\n for(int i=0;i<gain.size();i++)\n {\n currentalt = currentalt + gain[i];\n if(currentalt>maxalt)\n {\n maxalt = ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.