id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int d=truckSize;\n vector<pair<int,int>>s;\n for(int i=0;i<boxTypes.size();i++)\n {\n s.push_back({boxTypes[i][1],boxTypes[i][0]});\n\n }\n\n sort(s.rbe...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int t) {\n vector< pair<int,int> > v;\n for(int i = 0; i < boxTypes.size(); i ++){\n\n v.push_back({boxTypes[i][1], boxTypes[i][0]});\n\n }\n sort(v.rbegin(), v.rend());\n int ans = ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<pair<int, int>> v;\n for (int i = 0; i < boxTypes.size(); i++) {\n v.push_back({boxTypes[i][1], boxTypes[i][0]});\n }\n sort(v.rbegin(), v.rend());\n int an...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int d=truckSize;\n vector<pair<int,int>>s;\n for(int i=0;i<boxTypes.size();i++)\n {\n s.push_back({boxTypes[i][1],boxTypes[i][0]});\n\n }\n\n sort(s.rbe...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<vector<int>> sortedBoxes;\n int boxTypes_size = boxTypes.size();\n int truckTemp = truckSize;\n int maxUnits = 0;\n\n for (int i = 0; i < boxTypes_size; i++) {\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<pair<long long,long long>>vec;\n int n = boxTypes.size();\n for(int i=0 ; i<n ; i++){\n vec.push_back({boxTypes[i][1] , boxTypes[i][0]});\n }\n sort(vec.rbe...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector <vector<int>>boxTypesCopy;\n for (int i = 0;i<boxTypes.size();i++) {\n vector <int> temp = {boxTypes[i][1],boxTypes[i][0]};\n boxTypesCopy.push_back(temp);\n }...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(std::vector<std::vector<int>>& boxTypes, int truckSize) {\n\n // create inventory <numberOfUnitsPerBox, numberOfBoxes>\n std::unordered_map<int, int> inventory;\n for (std::vector<int> boxType : boxTypes)\n inventory[boxType[1]...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& b, int t) \n {\n vector<vector<int>> v;\n for (int i = 0; i < b.size(); i++)\n {\n v.push_back({b[i][1], b[i][0]});\n }\n sort(v.rbegin(), v.rend());\n \n int ans = 0;\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n\n // maximum units : greedy put boxes with more units first\n // priority Queue: number of units : num of boxes\n priority_queue<vector<int>> my_heap; // max Heap\n\n int ans = 0; \...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n \n vector<vector<int>> temp;\n for(int i=0;i<boxTypes.size();i++)\n {\n vector<int> v;\n v.push_back(boxTypes[i][1]);\n v.push_back(boxTypes[i][0]);\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<vector<int>> sortedUnitsPerbox(boxTypes.size(),vector<int>(2));\n for(auto i : boxTypes){\n int numBoxes = i[0];\n int unitsPerBox = i[1];\n sortedUnitsPer...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<vector<int>> sortedUnitsPerbox(boxTypes.size(),vector<int>(2));\n for(auto i : boxTypes){\n int numBoxes = i[0];\n int unitsPerBox = i[1];\n sortedUnitsPer...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n\n static bool compareUnitSize(vector<int> & a, vector<int> b){\n return a[1] > b[1];\n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(), boxTypes.end(), compareUnitSize);\n\n int sumVal = 0;\n for(i...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n static bool sortcol(const vector<int>& v1,const vector<int> v2)\n {\n return v1[1]>v2[1];\n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n \n sort(boxTypes.begin(),boxTypes.end(),sortcol);\n int ans=0;\n...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n static bool sortcol(const vector<int>& v1,const vector<int> v2)\n {\n return v1[1]>v2[1];\n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n \n sort(boxTypes.begin(),boxTypes.end(),sortcol);\n int ans=0;\n...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int boxes = 0, count = 0, sumBox = 0;;\n sort(boxTypes.begin(), boxTypes.end(), [](const vector<int>& a, const vector<int>b){\n return a[1] > b[1]; \n });\n int totalUnits = 0;\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Compare {\npublic:\n bool operator()(vector<int> below, vector<int> above)\n {\n return below[1] < above[1] ;\n }\n};\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n priority_queue<vector<int>,vector<vector<int>>,Compare>pq;\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n static bool custom(vector<int>a ,vector<int>b){\n return b[1]<a[1];\n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int units=0; \n sort(boxTypes.begin(),boxTypes.end(),custom);\n\n int i=0;\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(), boxTypes.end(), [](vector<int> a, vector<int> b) {\n return a[1] > b[1];\n });\n\n int left = truckSize;\n int units = 0;\n int boxes = 0;\n...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n static bool comp(vector<int> a, vector<int> b) { return a[1] > b[1]; }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(), boxTypes.end(), comp);\n\n int totalUnits = 0;\n int index = 0;\n\n while (truckSi...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\nint maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n // disable sync of C++ i/o stream with C i/o stream\n ios::sync_with_stdio(false);\n cin.tie(0); // break the sync of cin & cout flusing so when cin is used cout is not flushed\n // ignore the ifrst tw...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n // Comparator function for sorting the array w.r.t to no. of units\n static bool comparator(vector<int> a,vector<int> b)\n {\n return(a[1]>b[1]);\n }\n \n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n // Sort the array\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(), boxTypes.end(), [&](auto b1, auto b2) {\n return b1[1] > b2[1];\n });\n int res = 0;\n for(auto &it : boxTypes) {\n int boxTaken = min(truckSize, it[0]);\n res +...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n static bool custom(vector<int>a ,vector<int>b){\n return b[1]<a[1];\n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int units=0; \n sort(boxTypes.begin(),boxTypes.end(),custom);\n\n int i=0;\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n static bool custom(vector<int>a ,vector<int>b){\n return b[1]<a[1];\n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int units=0; \n sort(boxTypes.begin(),boxTypes.end(),custom);\n\n int i=0;\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n static bool comp(vector<int> a,vector<int> b){\n return a[1] > b[1];\n }\n\n int maximumUnits(vector<vector<int>>& arr, int truckSize){\n int store = 0;\n sort(arr.begin(),arr.end(),comp);\n for(int i=0;i<arr.size();i++){\n if(arr[...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n bool static customcomp(vector<int> i, vector<int> j){\n return i[1] == j[1] ? i[0] >= j[0] : i[1] > j[1];\n }\n\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(),boxTypes.end(), customcomp);\n int count = 0, ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(), boxTypes.end(), [](vector<int> a, vector<int> b){\n return a[1]>b[1];\n });\n int ans=0;\n for(auto x:boxTypes){\n if(x[0]<=truckSize)...
1,817
<p>Hercy wants to save money for his first car. He puts money in the Leetcode&nbsp;bank <strong>every day</strong>.</p> <p>He starts by putting in <code>$1</code> on Monday, the first day. Every day from Tuesday to Sunday, he will put in <code>$1</code> more than the day before. On every subsequent Monday, he will put...
0
{ "code": "class Solution {\npublic:\n int totalMoney(int n) {\n if(n <= 7){\n return n * (n+1) / 2;\n }\n return 28 + (n-7) + totalMoney(n-7);\n }\n};", "memory": "7100" }
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string& s, int x, int y) {\n if (x < y){\n swap(x, y);\n reverse(s.begin(), s.end());\n }\n int aCount = 0;\n int bCount = 0;\n int totalPoints = 0;\n\n for (int i = 0; i < s.size(); ++i){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maximumGain(string& s, int x, int y) {\n string priority = (x > y) ? \"ab\" : \"ba\";\n int A_count = 0;\n int B_count = 0;\n\n int result = 0;\n for (char c : s) {\n if (c =...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(const string& s, int x, int y) {\n ios::sync_with_stdio(false);\n int i = 0;\n int ans = 0;\n int begin = 0;\n bool is_section = false;\n while(i < s.size()){\n if(is_section){\n if(s[i] != 'a...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(const string& s, int x, int y) {\n ios::sync_with_stdio(false);\n int i = 0;\n int ans = 0;\n int begin = 0;\n bool is_section = false;\n while(i < s.size()){\n if(is_section){\n if(s[i] != 'a...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(const string& s, int x, int y) {\n ios::sync_with_stdio(false);\n int i = 0;\n int ans = 0;\n int begin = 0;\n bool is_section = false;\n while(i < s.size()){\n if(is_section){\n if(s[i] != 'a...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int bCount = 0;\n int aCount = 0;\n int lesser = min(x, y);\n int ans = 0;\n \n for (auto &ch : s){\n if (ch == 'a'){\n if (y > x && bCount > 0){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int a = 0, b = 0, ans = 0;\n if(x>y){\n for(int i=0;i<s.length();i++){\n if(s[i]=='a')a++;\n else if(s[i]=='b'){\n if(a>0)\n ans+=x,a--;\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int aCount = 0;\n int bCount = 0;\n int lesser = min(x, y);\n int result = 0;\n\n for (char c : s) {\n if (c > 'b') {\n result += min(aCount, bCount) * lesser;\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int a = 0, b = 0;\n int score = 0;\n for(char &c : s){\n if(c == 'a'){\n if(x < y && b > 0){\n b--;\n score += y;\n }\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n if(x>y){\n swap(x, y);\n reverse(s.begin(), s.end());\n }\n\n int n = s.size();\n int res = 0;\n int a = 0;\n int b = 0;\n for(int i=0; i<n; i++){\n i...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n stack<char>st;\n int c=0,d=0;\n for(auto &i:s){\n d++;\n if(i=='a'||i=='b'){\n if(x>=y){\n if(i=='b'){\n if(!st.empty()&&st.top()=='...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int ans=0;\n int p=0;//ab->0 ba->1\n if(y>x) p=1;\n stack<char> st;\n int i=0;\n while(i<s.size()){\n if(st.size()==0 && (s[i]=='a' || s[i]=='b')){\n st.push(s[i]);...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\n int abFirst(const string &s, int x, int y){\n int a = 0, b = 0, point = 0;\n for(int i=0;i<s.length();i++){\n if(s[i] == 'a'){\n a++;\n }else if(s[i] == 'b'){\n if(a == 0){\n b++;\n }el...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int solve(string &s, int n, int i, int j, int cntA[], int cntB[], int x, int y) {\n if(j<=i) return 0;\n int used=0, ans=0, cnt=min(cntA[i]-cntA[j+1], cntB[i]-cntB[j+1]);\n int ca = cntA[i]-cntA[j+1];\n int cb = cntB[i]-cntB[j+1];\n if(x > y...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n // greedy\n // time: O(n)\n // space: O(1)\n // b(ab)a: Assume score(ab) > score(ba) but removing ba first is optimal.\n // But after removing ab we can remove one ba, so we get score(ab) + score(ba) which is greater than score(ba) * 2.\n int maximumGain(string...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n ios::sync_with_stdio(false);\n int i = 0;\n int ans = 0;\n int begin = 0;\n bool is_section = false;\n while(i < s.size()){\n if(is_section){\n if(s[i] != 'a' && s[...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int i = 0;\n int ans = 0;\n int begin = 0;\n bool is_section = false;\n while(i < s.size()){\n if(is_section){\n if(s[i] != 'a' && s[i] != 'b'){\n is_se...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int points1 = 0, points2 = 0;\n stack<char> st;\n for (char i : s) {\n if (i == 'b')\n st.push(i);\n else if (i == 'a') {\n if (!st.empty() && st.top() == 'b')...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
0
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int points1 = 0, points2 = 0;\n stack<char> st;\n for (char i : s) {\n if (i == 'b')\n st.push(i);\n else if (i == 'a') {\n if (!st.empty() && st.top() == 'b')...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int solve(string &s,string p,int point){\n stack<char>st;\n int total=0;\n for(int i=0;i<s.size();i++){\n if(st.empty()){\n st.push(s[i]);\n }\n else{\n if(s[i]==p[1]&&st.top()==p[0]){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int ans = 0;\n if( x > y)\n {\n stack<char>st;\n for(int i=0;i<s.size();i++)\n {\n if(st.empty() == 1 || (s[i] != 'a' && s[i] != 'b'))\n st.push(s[i...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\n void getCount(string str, string sub, int& cnt1, int& cnt2) {\n \n char first = sub[0], second = sub[1];\n int i = 1;\n while(i < str.length()) {\n if(i > 0 && str[i-1] == first && str[i] == second) {\n cnt1++;\n str.era...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\n void getCount(string str, string sub, int& cnt1, int& cnt2) {\n \n char first = sub[0], second = sub[1];\n int i = 1;\n while(i < str.length()) {\n if(i > 0 && str[i-1] == first && str[i] == second) {\n cnt1++;\n str.era...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int ans = 0;\n stack<char> stk;\n string firstPat=\"ba\",secondPat=\"ab\";\n if(x>y){\n firstPat=\"ab\";\n secondPat=\"ba\";\n }\n\n int n = s.size();\n int i=0;...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int res = 0;\n string cur;\n if (x >= y){\n for (auto&l: s){\n cur.push_back(l);\n if (cur.length() >= 2 && cur.substr(cur.length()-2) == \"ab\"){\n cu...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n if (x < y) {\n reverse(s.begin(), s.end());\n return maximumGain(s, y, x);\n }\n int ans = 0;\n stack<char> stk1;\n stack<char> stk2;\n for (char c : s) {\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n // Function to calculate the maximum gain by removing \"ab\" or \"ba\" substrings\n int maximumGain(string s, int x, int y) {\n // If x is less than y, reverse the string and swap values of x and y to \n // prioritize removing \"ba\" before \"ab\" since we wa...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n stack<char> st1, st2;\n int ans = 0;\n \n // First pass: remove \"ab\" or \"ba\" based on the higher value\n if (x >= y) {\n for (char c : s) {\n if (!st1.empty() && st1.t...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string &s, int &x, int &y) {\n int n = s.size();\n stack<char>st;\n\n bool flag = y>x;\n string targetPair = flag ? \"ba\" : \"ab\";\n int sum =0;\n for(int i =0; i<s.size();i++){\n if(!st.empty() && targetP...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int score =0;\n string temp=s;\n if(x>y){\n int i=-1;\n int j=0;\n string temp=s;\n while(j<s.size()){\n if(i>=0 && temp[i] == 'a' && s[j] == 'b'){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "\n\n\nclass Solution {\npublic:\n int solvey(stack<char>& st, int points) {\n int cnt = 0;\n stack<char> tempStack;\n \n \n while (!st.empty()) {\n tempStack.push(st.top());\n st.pop();\n }\n \n \n stack<char> reverseStack...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "\nclass Solution {\npublic:\n int solve(string s, int y, string k, int z) {\n int points = 0;\n string x =\"\";\n\n for (int i = 0; i < s.size(); i++) {\n if (x.size() && s[i] == k[1] && x[x.size()-1]== k[0]) {\n points += y;\n x.pop_back();\n...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n if (y > x) {\n swap(x, y);\n reverse(s.begin(), s.end());\n }\n int n = s.size();\n int ans = 0;\n string st;\n for (int i=0; i<n; ++i) {\n if (s[i] == 'b') ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int removeAB(string& s, int add) {\n int sum = 0;\n stack<char> st;\n for(auto ch: s) {\n st.push(ch);\n if(st.top() == 'b') {\n st.pop();\n if(!st.empty() && st.top() == 'a') {\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\n\npublic:\n int maximumGain(string s, int x, int y) {\n int points=0;;\n\n auto removePairs = [&](char first, char second, int point){\n string newString;\n int tempPoints=0;\n for(char ch : s){\n if(!newString.empty() && ne...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int ans=0;\n // getba(s,y);\n if(x>y){\n ans+=getab(s,x)+getba(s,y);\n }else{\n ans+=getba(s,y)+getab(s,x);\n }\n return ans;\n }\n int getba(string &s,int y){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n string s1=\"\" , s2=\"\";\n int ans=0;\n if(x>=y) {\n s1=\"ab\";\n s2=\"ba\";\n }\n else {\n s2=\"ab\";\n s1=\"ba\";\n }\n int top1=0;\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int res = 0;\n string top, bot;\n int top_score, bot_score;\n\n if (y > x) {\n top = \"ba\";\n top_score = y;\n bot = \"ab\";\n bot_score = x;\n } else {...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
1
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n \n vector<char>st;\n string check = \"\";\n string next_check = \"\";\n\n int add = 0;\n int next_add = 0;\n if(x>y){\n \n check = \"ab\";\n next_check = \"ba\";\...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n \n if (x < y) {\n swap(x, y);\n for (auto& c : s) {\n if (c == 'a') c = 'b';\n else if (c == 'b') c = 'a';\n }\n }\n\n int maxPoints = 0;\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution{\npublic:\n int maximumGain(string s, int x, int y) {\n if (x < y) { \n swap(x, y);\n for (char& c : s) {\n if (c == 'a'){\n c = 'b';\n }\n \n else if (c == 'b'){\n c = 'a';\n }\n }...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n vector<char> tmp;\n if (x > y) {\n for (char c: s) {\n if (c == 'a') c = 'b';\n else if (c == 'b') c = 'a';\n tmp.push_back(c);\n }\n swap(x...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n std::string expensive, cheap;\n\n if(x >= y){\n expensive = \"ab\";\n cheap = \"ba\";\n }\n else{\n expensive = \"ba\";\n cheap = \"ab\";\n swap(x,y)...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n vector<char> vec;\n int top_score = 0, bottom_score = 0, ans = 0;\n string firstRem, secondRem;\n\n if (x > y) {\n firstRem = \"ab\";\n secondRem = \"ba\";\n top_score = x...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "static const int _ = [] {\n std::cin.tie(0);\n std::ios::sync_with_stdio(0);\n return 0;\n}();\n\n\nclass Solution {\npublic:\n int maximumGain(string &s, int x, int y) {\n int totalScore = 0;\n string highPriorityPair = x > y ? \"ab\" : \"ba\";\n string lowPriorityPair = x...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "#include <iostream>\n#include <string>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n if (y > x) {\n return helper(s, y, x, 'b', 'a');\n } else {\n return helper(s, x, y, 'a', 'b');\n }\n }\n\n int helpe...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "#include <iostream>\n#include <string>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n if (y > x) {\n return helper(s, y, x, 'b', 'a');\n } else {\n return helper(s, x, y, 'a', 'b');\n }\n }\n\n int helpe...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int ans = 0;\n vector < char > c;\n for (int i = 0; i < s.size(); i++) {\n string cur = \"\";\n cur += s[i];\n if (c.size() > 0) {\n cur += c.back();\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n // int helper(string s, int x, int y, int i, int n, vector<char> &v){\n // if(i>=n) return 0;\n // int temp1=0, temp2=0, temp3=0, temp4=0, temp5=0;\n \n // if(v.size()>0 && s[i]=='b' && v.back()=='a'){\n // char c = v.back();\n // ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int score = 0;\n vector<char>v(s.begin(), s.end());\n\n function<void(string,int)> f = [&] (string p, int s) -> void {\n if(v.empty())return;\n vector<char>temp;\n temp.push_back...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n if(s.length()<2) return 0;\n int score=0;\n char first,second;\n int add1,add2;\n if(x>y) {\n add1=x;\n add2=y;\n second='b';\n first='a';\n }\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int helper(string s,string s1,int max,int min){\n cout<<s1<<\" \";\n int n=s.length();\n stack<char>st;\n int ans=0;\n st.push(s[0]);\n int i=1;\n while(i<n){\n if( !st.empty() && s[i]==s1[1] && st.top()=...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
2
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int n=s.size() ;\n if(n==1) return 0 ;\n else if(n==2){\n if(s==\"ab\") return x ;\n else if(s==\"ba\") return y ;\n else return 0 ;\n }\n int maxi=0 ;\n if(...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int points = 0;\n\n // Determine which pattern gives more points\n char first = 'a', second = 'b';\n if (x < y) {\n swap(first, second);\n swap(x, y);\n }\n\n points +=...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int totalScore = 0;\n string highPriorityPair = x > y ? \"ab\" : \"ba\";\n string lowPriorityPair = highPriorityPair == \"ab\" ? \"ba\" : \"ab\";\n\n // First pass: remove high priority pair\n stri...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n int totalScore = 0;\n string highPriorityPair = x > y ? \"ab\" : \"ba\";\n string lowPriorityPair = highPriorityPair == \"ab\" ? \"ba\" : \"ab\";\n\n // First pass: remove high priority pair\n stri...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int points=0;\n string addval(char first , char second , int p , string s){\n string ns;\n int poi=0;\n for(char c : s){\n if(!ns.empty() && ns.back()==first && c==second){\n poi+=p;\n ns.pop_back();\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maxG(string s,int x,int y,string xs,string ys){\n if(y>x){\n return maxG(s,y,x,ys,xs);\n }\n stack<char>st;\n int ans=0;\n for(int i=0;i<s.length();i++){\n if(!st.empty() && s[i]==xs[1] && st.top()==xs[0]){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n string d;\n if(x>y) {\n d=\"ab\";\n }\n else {\n d=\"ba\";\n }\n vector<char>st;\n\n for(int i=0;i<s.length();i++) {\n if(st.size()==0) {\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n string convert(stack<char> &s){\n string ans;\n while(!s.empty()){\n ans.push_back(s.top());\n s.pop();\n }\n reverse(ans.begin(),ans.end());\n return ans;\n }\n int solve(string str,char ch1,char ch2,int c,stack<...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\nint maximumGain(string x,int first,int second)\n{\n if(first>second)\n return solve (x,first,second,\"ab\",\"ba\")+solve (x,second,first,\"ba\",\"ab\");\n else \n return solve (x,second,first,\"ba\",\"ab\")+solve (x,first,second,\"ab\",\"ba\");\n}\n int solve (stri...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\n int maximumGainPass1(string s, string subs,int gain, stack<char>& stk) {\n char first = subs[0];\n char second = subs[1];\n int totalGain = 0;\n for (auto c : s) {\n if (c == second) {\n if (!stk.empty() && stk.top() == first) {\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int getScore(int len, int x, int y){\n return max(x + (len-2)/2 * y, len/2 * x);\n }\n\n int resolveString(string s, char c1, char c2, int x, int y){\n int n = s.size();\n int ans = 0;\n\n string res;\n for(int i = 0;i<n;i++){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int getScore(int len, int x, int y){\n return max(x + (len-2)/2 * y, len/2 * x);\n }\n\n int resolveString(string s, char c1, char c2, int x, int y){\n int n = s.size();\n int ans = 0;\n\n string res;\n for(int i = 0;i<n;i++){\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\n long long ans=0;\n\n string absolve(string s,int val){\n string st=\"\";\n for(auto x:s){\n if(x=='b'){\n if(st.size() && st.back()=='a'){\n ans+=val;\n st.pop_back();\n }\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int maximumGain(string s, int x, int y) {\n return solve(s, x, y);\n }\n\nprivate:\n int solve(string s, int x, int y) {\n string maxstr = (x > y) ? \"ab\" : \"ba\";\n string minstr = (x > y) ? \"ba\" : \"ab\";\n int score = 0;\n strin...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n int scoree(string& pair, int score,string& s){\n stack<char> st;\n\n int res=0;\n for(auto x: s){\n if(x==pair[1] &&!st.empty() && st.top()==pair[0] ){\n \n res+=score;\n st.pop();\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n\n std::pair<int, std::string> remove_substring(std::string s, char c1, char c2) {\n std::string remaining;\n int res = 0;\n\n for (auto ch : s) {\n if (ch == c2) {\n if (!remaining.empty() && remaining.back() == c1) {\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n\n std::pair<int, std::string> remove_substring(std::string s, char c1, char c2) {\n std::string remaining;\n int res = 0;\n\n for (auto ch : s) {\n if (ch == c2) {\n if (!remaining.empty() && remaining.back() == c1) {\n ...
1,818
<p>You are given a string <code>s</code> and two integers <code>x</code> and <code>y</code>. You can perform two types of operations any number of times.</p> <ul> <li>Remove substring <code>&quot;ab&quot;</code> and gain <code>x</code> points. <ul> <li>For example, when removing <code>&quot;ab&quot;</code> from <...
3
{ "code": "class Solution {\npublic:\n string remove(string s,string t)\n {\n stack<char> st;\n for(int i=0;i<s.length();i++)\n {\n if(st.size()>0 && s[i]==t[1] && st.top()==t[0]) st.pop();\n else st.push(s[i]);\n }\n\n string new_string;\n while(s...