id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "// #include <ext/pb_ds/assoc_container.hpp> // Common file\n// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update\n// #include <ext/pb_ds/detail/standard_policies.hpp>\n// using namespace __gnu_pbds;\n\n// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_orde... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n vector<pair<int,int>> index; // vector of pairs (value, index)\n vector<int> lesser, greater; // lesser[i] = number of values in the left of i that are less than i\n // greater[i] = number of values in the right of i ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n vector<pair<int,int>> index; // vector of pairs (value, index)\n vector<int> lesser, greater; // lesser[i] = number of values in the left of i that are less than i\n // greater[i] = number of values in the right of i ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n vector<pair<int,int>> index; \n vector<int> lesser, greater; \n void merge(int left, int mid, int right) {\n for(int i = mid + 1, j = left, k = left; i <= right; i++) {\n while(j <= mid and index[j].first ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "class Solution {\npublic:\n void merge(vector<pair<int,int>>&a,vector<int>&small,vector<int>&large,int i,int mid,int j){\n vector<pair<int,int>>temp(j-i+1);\n int ptr=i,i1=i,j1=mid+1;\n for(int x=mid+1;x<=j;x++){\n while(ptr<=mid and a[ptr].first<a[x].first)ptr++;\n ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "const int N=1e5+10;\nint smaller[N],larger[N];\nconst int M=1e9+7;\nclass Solution {\npublic:\n void merge(vector<pair<int,int>>&arr,int l,int m,int r){\n for(int i = m + 1, j = l, k = l; i <= r; i++) {\n while(j <= m and arr[j].first < arr[i].first) j++;\n while(k <= m and ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n #define ll long long\n void merge(vector<pair<ll,ll>> &arr, vector<ll> &less, vector<ll> &big, ll l, ll r) {\n ll i = l;\n ll one = 1;\n ll mid = l + (r-l)/2;\n ll j = mid + one;\n \n ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "class Solution {\npublic:\n void merge(int left,int mid,int right,vector<pair<int,int>>& v,vector<int>&lesser,vector<int>&greater)\n {\n for(int i = mid + 1, j = left, k = left; i <= right; i++) {\n while(j <= mid and v[j].first < v[i].first) j++;\n while(k <= mid and v[k].first ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(const string_view& sv) {\n int a = 0;\n for (const char c : sv) {\n a += (c == 'a');\n }\n \n int res = min(a, static_cast<int>(sv.size()) - a);\n int d = 0;\n for (const char c : sv) {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "#include <ranges>\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2,tune=native\")\n\nbool init() {\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n return true;\n}\n\nclass Solution {\npublic:\n int minimumDeletions(const std::string& s) const noexcept {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(const string &s) const {\n static int acount[100001];\n\n const int n = s.size();\n acount[n] = 0;\n for(int i = n - 1; i >= 0; i--) {\n acount[i] = acount[i + 1] + (s[i] == 'a');\n }\n\n int acnt = 0, ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(const string& s) {\n stack<char> stk;\n int min_del = 0;\n for (auto&& c: s) {\n if (c == 'a' && !stk.empty() && stk.top() == 'b')\n stk.pop(), min_del++;\n else if (c == 'b')\n stk.... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string &str) {\n int n = str.size();\n int cnt[n+1][2]; // pos will go from 1 to last + 1\n cnt[0][0] = 0;\n cnt[0][1] = 0;\n\n for(int i = 0; i < n; i++){\n cnt[i + 1][0] = cnt[i][0] + (str[i] == 'a');\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "const char optimize = []() {std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); return 'c';}();\n\nclass Solution {\npublic:\n int minimumDeletions(const std::string& s) const noexcept {\n int end = s.size() - 1, start = 0;\n while(start < s.size() && s[start] == 'a') ++start;... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\nstatic const auto _ = []() -> int {\n std::ios::sync_with_stdio(false);\n std::cin.sync_with_stdio(false);\n std::cout.sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\n int impl(const string& s, int a_count, int i = 0, int numb = 0)\n {\n if(i >= s.size()) return 0;\n if((i+1) < s.size() && s[i] == 'b' && s[i+1] == 'a')\n {\n return std::min(\n 1 + numb + impl(s, a_count, i + 1, 0) \n ,... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "const char optimize = []() {std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); return 'c';}();\n\nclass Solution {\npublic:\n int minimumDeletions(const std::string& s) const noexcept {\n int end = s.size() - 1, start = 0;\n while(start < s.size() && s[start] == 'a') ++start;... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "const char optimize = []() {std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); return 'c';}();\n\nclass Solution {\npublic:\n int minimumDeletions(const std::string& s) const noexcept {\n int end = s.size() - 1, start = 0;\n while(start < s.size() && s[start] == 'a') ++start;... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "namespace constants {\nconstexpr auto max_len = 100'000;\nconstexpr auto valid_chars = \"ab\";\n} // namespace constants\n\nclass Solution {\npublic:\n auto minimumDeletions(string const &s) const -> int {\n auto const n = ssize(s);\n assert(1 <= n && n <= constants::max_len);\n ass... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int not_flip = 0, flip = 0;\n for(char c : s) {\n int temp = not_flip + (c == 'b');\n flip = min(flip, not_flip) + (c == 'a');\n not_flip = temp;\n }\n\n return min(not_flip, flip)... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int res = 0, count = 0;\n for (char c : s){\n if (c == 'b')\n count++;\n else if (count){\n res++;\n count--;\n }\n }\n return res;\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int count = 0;\n int ans = 0;\n for(char& c : s)\n {\n if(c == 'b')\n count++;\n else\n ans = min(ans + 1, count);\n }\n return ans;\n }\n};",
... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) \n {\n int ans = 0, countB = 0;\n for(auto ch:s)\n {\n if(ch == 'a') ans = min(ans+1, countB);\n else countB++;\n }\n return ans;\n }\n};",
"memory": "23170"
} |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) \n {\n int ans = 0, countB = 0;\n for(auto ch:s)\n {\n if(ch == 'a') ans = min(ans+1, countB);\n else countB++;\n }\n return ans;\n }\n};",
"memory": "23170"
} |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int total = 0;\n for(auto a : s) total += a == 'a';\n int ans = total;\n int sum = 0;\n for(int i = 0 ; i< s.size() ; ++i) {\n sum += s[i] == 'a';\n total -= s[i] == 'a';\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 0 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int n = s.size();\n \n int a = 0;\n int b = 0;\n\n int c,d;\n\n for(int i = 1; i <= n; ++i) {\n if (s[i-1] == 'a') {\n c = a;\n d = b + 1;\n } else... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 1 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int n = s.size();\n int f[n + 1];\n memset(f, 0, sizeof(f));\n int b = 0;\n for (int i = 1; i <= n; ++i) {\n if (s[i - 1] == 'b') {\n f[i] = f[i - 1];\n ++b;\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 1 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<char> st; // Stack to store 'b' characters\n int deletions = 0; // Track the number of deletions\n //ab in stack this ba so if b then we push in stack if a we check top is b ? then we \n //inc del cnt and ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<char>st;\n int del=0;\n for(int i=0;i<s.size();i++){\n if(st.empty()){\n st.push(s[i]);\n }\n else{\n if(st.top()=='a'&&s[i]=='b'){... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "/*Approach 4: Using stack (one pass)\nIntuition\nWhat if we focus on removing \"ba\" pairs? These pairs unbalance the string because an 'a' character is to the right of a 'b' character. \nBy leveraging a stack, we can efficiently count and remove these pairs in a single traversal of the string.\n\nTo imple... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int func(int left, int right, string &s, int &a, int &b) {\n if (left >= right) return 0;\n\n // Remove leading 'a's and trailing 'b's\n while (left <= right && s[left] == 'a') {\n a--;\n left++;\n }\n while (left <= ri... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n\n int usingDP(string s) {\n int n = s.size();\n // int *dp = new int[n];\n int prev = 0;\n int bsSoFar = 0;\n if(s[0] == 'b') {\n // dp[0] = 0;\n prev = 0;\n bsSoFar++;\n }\n else {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n string s1=s;\n reverse(s1.begin(),s1.end());\n\n int t1=0,t2=0;\n\n for(int i=0;i<s1.size();i++)\n {\n if(s1[i]=='a')\n {\n t1++;\n }\n else if(s1[... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\nprivate:\n int minDel(string s){\n stack<char> st;\n\n int ans = 0;\n\n for(auto it: s){\n if(it=='b')st.push(it);\n\n if(it=='a'){\n if(!st.empty()){ st.pop();ans++;}\n }\n }\n\n return ans;\n }\npubl... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n\n int points(string s, string maqsad) {\n int j = 0, n = s.size();\n int count = 0;\n for (int i = 0; i < n; i++) {\n s[j++] = s[i];\nif (j > 1 and s[j - 1] == maqsad[1] and s[j - 2] == maqsad[0]) {\n j -= 2;\n cou... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int a=0, b=0, ans = INT_MAX;\n for(char c : s){\n if(c-'a' == 0) a++;\n else b++;\n }\n if(a==0 || b==0) return 0;\n b = 0;\n s += \"b\";\n for(char c : s){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int a=0, b=0, ans=1e9;\n for(char c: s) if (c=='a') a++;\n s+='b';\n for(char c: s){\n if (c=='a') { \n a--;\n }\n else{\n ans=min(ans, b+a);\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<char> st;\n for(char it: s){\n st.push(it);\n }\n int cnt =0;\n int acount = 0, bcount =0;\n while(!st.empty()){\n char front = st.top();\n st.pop();\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int dp[2][100001];\n\n int solve(string& s, int flag, int pos){\n if(pos == s.size())\n return 0;\n \n auto& ans = dp[flag][pos];\n if(ans != -1)\n return ans;\n \n if(flag)\n return ans = (s[pos] =... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n // using LIS of dp to solve\n int minimumDeletions(string s) {\n vector<char> temp={};\n temp.push_back(s[0]);\n int n=s.size();\n\n for(int i=1;i<n;i++){\n int x=s[i]-'a';\n int y=temp.back()-'a';\n if(x>=y){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n\n int popA(string s, stack<char> stk)\n {\n int count = 0;\n int n = s.size();\n for(int i=0; i<n; i++)\n {\n if( stk.empty() )\n {\n stk.push(s[i]);\n }\n else if( !stk.empty() && s[i] ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int n = s.size();\n stack<int>st;\n int count=0;\n for(int i=0;i<n;++i){\n if(s[i]=='a'){\n if(!st.empty() && s[st.top()]=='b'){\n count++;\n st.pop(... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<int> st;\n int count = 0;\n for(int i = 0; i < s.size(); ++i){\n if(!st.empty() and s[i] == 'a' and s[st.top()] == 'b') st.pop(), count++;\n if(s[i] == 'b') st.push(i);\n }\n ret... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<char>st,st2;\n for(int i=0;i<s.size();i++)\n st.push(s[i]);\n int ans=0;\n while(!st.empty()){\n if(st.top()=='a')\n st2.push('a');\n else if(!st2.empty()){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<int> st;\n int del = 0;\n for (int i=s.size()-1;i>=0;i--)\n {\n if(st.empty())\n {\n st.push(s[i]);\n }\n else\n {\n if(s[... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n // int count=INT_MAX;\n int n=s.length();\n \n stack<int>countB;\n int count=0;\n for(int i=0;i<n;i++){\n if(s[i]=='a'){\n if(countB.size()>0){\n countB.pop(... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<int> st; int res = 0; \n for(int i=0;i<s.size();i++){\n if(s[i]=='b') st.push(s[i]);\n else{\n if(!st.empty()){\n res++;\n st.pop();\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int dp[100001][2];\n int solve(int i, string &s, char prev){\n if(i>=s.size()) return 0;\n\n //curr delete when prev b and curr a delete mendetory\n int del = INT_MAX;\n int keep = INT_MAX; \n char curr = s[i];\n\n if(dp[i][prev-'a... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int dp[100001][2];\n int fun(string&s,int cur,int i){\n if(i==s.length()) return 0;\n int ans=0;\n if(dp[i][cur]!=-1) return dp[i][cur];\n if(cur==0){\n if(s[i]=='a') ans=fun(s,cur,i+1);\n else{\n ans=min(1+f... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int dp[100005][3];\n int solve(int ind, int mode, string &s){\n // base case \n if(ind == s.size()) return 0;\n // rec case \n int ans = INT_MAX;\n\n if(dp[ind][mode] != -1) return dp[ind][mode];\n\n if(mode == 0){\n if(... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int dp[100005][2];\n int n;\n string s;\n\n int solve(int idx, bool deletedAllB) {\n if (idx >= n)\n return 0;\n\n int& ret = dp[idx][deletedAllB];\n if (~ret)\n return ret;\n\n if (s[idx] == 'a') {\n int i... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n void clean(string& s, int& countA, int& countB){\n if(s.length() == 0){\n return;\n }\n int start = 0;\n while(s.length() > 0 && s.front() == 'a'){\n countA--;\n s.erase(s.begin());\n }\n while(s.lengt... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n void clean(string& s, int& countA, int& countB){\n if(s.length() == 0){\n return;\n }\n int start = 0;\n while(s.length() > 0 && s.front() == 'a'){\n countA--;\n s.erase(s.begin());\n }\n while(s.lengt... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n \n \n int dp[100001][2];\n string s=\"\";\n int n;\n int solve(int i, int t) \n {\n if(i==n) return 0;\n \n if(dp[i][t]!=-1) return dp[i][t];\n int ans=0;\n if(t)// their is a previous b present \n {\n if... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution \n{\npublic:\n int minimumDeletions(string s) \n {\n int n=s.size(),nb,na,del_b=0,del_a=0;\n stack<pair<int,int>> stack;\n for(int i=0;i<n;)\n {\n na=0;\n nb=0;\n while(i<n && s[i]=='b')\n {\n nb++;\... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n stack<int>st;\n int n = s.size();\n int c1 = 0;\n for(int i=0;i<n;i++){\n if(s[i]=='b'){\n st.push(i);\n }\n else{\n if(!st.empty()){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\nint pre[1303207], suf[1303207];\n\npublic:\n int minimumDeletions(string s) {\n int ans = 1e9 + 7;\n\n int ca =0, cb = 0;\n\n\n for (int i = 0; i < s.size(); i++){\n pre[i] = cb;\n if(s[i] == 'b') cb++;\n }\n\n\n for (int i = s.s... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int solve(string &s,int &n,int i,bool flag,int dp[][2]){\n if(i==n) return 0;\n if(dp[i][flag]!=-1) return dp[i][flag];\n int skip=1+solve(s,n,i+1,flag,dp),take=n;\n if(s[i]=='a' && flag) take=solve(s,n,i+1,true,dp);\n else if(s[i]=='b') tak... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n static const int N = 2e5+7, inf = 1e9+7;\nint dp[N][2];\nstring s;\nint f(int i,int ok){\n if(i == s.size()) return 0;\n if(dp[i][ok] != -1) return dp[i][ok];\n int ans = inf;\n if(s[i] == 'a'){\n if(!ok) ans = min(ans,f(i+1,ok));\n else ans = min(ans,... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n /*int print0(string &b,int c,int e,char temp0){\n if(c==e){\n return 0;\n }\n int temp2=0;\n if(temp0=='a'){\n if(b[c]=='a'){\n temp2=temp2+print0(b,c+1,e,'a');\n }\n else if(b[c]=='b'){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n\n int approach_1(string s){\n\n int n = s.size(); int count = 0;\n\n stack<int> st;\n for(int i = 0; i<n; i++){\n if(!st.empty() && s[i] == 'a' && st.top() == 'b'){\n st.pop();\n count++;\n }\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n // int getA(string s, int index) {\n // int count = 0;\n // for (int i = index; i < s.length(); i++) {\n // if (s[i] == 'a') {\n // count++;\n // }\n // }\n // return count;\n // }\n // int solve(string& s... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n // int getA(string s, int index) {\n // int count = 0;\n // for (int i = index; i < s.length(); i++) {\n // if (s[i] == 'a') {\n // count++;\n // }\n // }\n // return count;\n // }\n // int solve(string& s... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "#define ll long long\n#define sz(x) (ll)x.size()\n#define INF 1e9\n\nclass Solution {\n string s;\n ll dp[100005][2];\npublic:\n\n int minimumDeletions(string ss) {\n s = ss;\n memset(dp, -1, sizeof(dp));\n return rec(0, 0);\n }\nprivate:\n\nll rec(ll idx, bool f){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "#define ll long long\n#define sz(x) (ll)x.size()\n#define INF 1e9\n\nclass Solution {\n string s;\n ll dp[100005][2];\npublic:\n\n int minimumDeletions(string ss) {\n s = ss;\n memset(dp, -1, sizeof(dp));\n return rec(0, 0);\n }\nprivate:\n\nll rec(ll idx, bool f){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n // 3 passes method time complexity O(n)\n // int n = s.length();\n // vector<int>countA(n, 0);\n // vector<int>countB(n, 0);\n // int b = 0;\n // // Count the number of B on the left of the current e... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int n = s.size();\n vector<int> dp(n + 1, 0);\n int bCount =\n 0; // To keep track of the number of 'b's encountered so far\n\n for (int i = 1; i <= n; i++) {\n if (s[i - 1] == 'b') {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n // a a b a b b a b\n // \n int n = s.length();\n vector<int> rightA(n, 0);\n int countA = 0;\n int minFlip = INT_MAX;\n for(int i = s.length() - 1; i >= 0; i--)\n {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 2 | {
"code": "class Solution {\npublic:\n// int minimumDeletions(string s) {\n// int bCount = 0;\n// int result = 0;\n// char* arr = s.c_str();\n\n// for(char ch:arr) {\n// if (ch == 'b') bCount++;\n// else if (bCount == 0) continue;\n// else {\n// ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "static auto _ = []() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n int minimumDeletions(string s) {\n int n = s.length();\n vector<int> dp(n + 1, 0);\n int b_count = 0;\n for (int i = 0; i < n; i++) {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) \n {\n int n = s.size();\n int suffAs[100001] = {0};\n\n for(int i=n-1;i>=0;i--)\n {\n suffAs[i] += suffAs[i+1];\n if(s[i] == 'a')\n suffAs[i]++;\n }\n\n vector<in... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n\n int result = 1e9;\n\n void getMin(vector <int> &prefixSum, string &s, int i, int ctB, int currSum) {\n if(i == s.length()) {\n result = min(result, currSum);\n return;\n }\n if(s[i] == 'b') {\n ctB++;\n get... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int n;\n vector<int> dp;\n \n int f(int i, int &cntA, string& s) {\n if(i==n) return 0;\n //if (dp[i] != -1) return dp[i];\n int ans=f(i+1, cntA, s);\n \n if (s[i]=='a') cntA++;\n else ans=min(ans+1, cntA);\n \n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\nprivate:\n int minDeletions;\n string s;\n void updateChar(vector<int>& charCount,int start, int end, int increment, char ch, bool secondPass){\n int currCount = 0;\n for(int i = start; i != end; i += increment){\n if(s[i - increment] == ch) currCount++;\... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\nprivate:\n int minDeletions;\n string s;\n void updateChar(vector<int>& charCount,int start, int end, int increment, char ch, bool secondPass){\n int currCount = 0;\n for(int i = start; i != end; i += increment){\n if(s[i - increment] == ch) currCount++;\... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int n=s.size();\n vector<int>dp(n+1,0);\n s='#'+s;\n int cnt1=0;\n for(int i=1;i<=n;i++){\n if(s[i]=='a'){\n dp[i]=max(1+cnt1,dp[i-1]);\n cnt1++;\n }\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int tab(string s)\n {\n vector<int> dp(s.size()+1, 0);\n int b = 0;\n\n for (int i = 0; i < s.size(); i++) \n {\n if (s[i] == 'a') \n {\n dp[i + 1] = min(dp[i] + 1, b);\n } \n else \n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n ios::sync_with_stdio(false);\n s += 'b';\n int n = s.size();\n vector <int> suf(n);\n suf[n - 1] = (s[n - 1] == 'a');\n for(int i = n - 2; i >= 0; i--){\n suf[i] = suf[i + 1] + (s[i] == 'a... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) \n {\n int n=s.length(),mini=INT_MAX;\n vector<int> A(n+1,0); \n s+='b';\n\n for(int i=n-1;i>=0;--i)\n {\n A[i]=A[i+1];\n if(s[i]=='a')\n A[i]++;\n }\n \n\n... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int dp[27][100001];\n int helpme(string &s ,int n ,char prv , int index ){\n if(index>=n)return 0;\n if(dp[prv-'a'][index]!=-1)return dp[prv-'a'][index];\n int len = 0;\n if(s[index] >= prv){\n len = max(len,1+helpme(s,n,s[index] , i... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int dp[100005];\n int func(int indx, vector<int>& suff, string& s){\n if (indx == s.size()) return 0;\n if (dp[indx]!=-1) return dp[indx];\n if (s[indx] == 'a') return dp[indx] = func(indx+1,suff,s);\n else{\n return dp[indx] = min(su... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int count = INT_MAX;\n int a_count = 0;\n int b_count = 0;\n vector<int> curr_a;\n\n for (char c : s) {\n if (c == 'a') {\n a_count++;\n } else if (c == 'b') {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int count = INT_MAX;\n int a_count = 0;\n int b_count = 0;\n vector<int> curr_a;\n\n for (char c : s) {\n if (c == 'a') {\n a_count++;\n } else if (c == 'b') {\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) \n {\n int n=s.size();\n // unordered_map<int,unordered_map<int,int>>m;\n // return n-f(0,-1,s,m);\n vector<int>dp;\n int idx=0;\n for(int i=0;i<n;i++)\n {\n int x=((s[i]=='a')?1:2);... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int count_a=0;\n int count_b=0;\n int count=0;\n vector<int>arr1;\n vector<int>arr2;\n int min=0;\n int i=0;\n int j=s.size()-1;\n while(i<s.size()&&s[i]=='a')i++;\n while... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int n = s.length(), i = 0, j = n-1;\n while(i<n && s[i] == 'a') i++;\n while(j>=0 && s[j] == 'b') j--;\n vector<vector<int>> arr(2);\n int count = 0, prev = '.', counta = 0;\n for(int k = i; k<=j; k+... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string s) {\n int count_a=0;\n int count_b=0;\n int count=0;\n vector<int>arr1;\n vector<int>arr2;\n int min=0;\n int i=0;\n int j=s.size()-1;\n while(i<s.size()&&s[i]=='a')i++;\n while... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int n;\n vector<int> dp;\n\n int f(int i,int &cntA,string& s){\n if(i==n) return 0;\n if(dp[i]!=-1) return dp[i];\n int ans=f(i+1,cntA,s);\n\n if(s[i]=='a') cntA++;\n else ans=min(ans+1,cntA);\n\n return dp[i]=ans;\n }\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\n vector<int> cnt;\n int dp[100000];\n int rec(int ind,string &s){\n if(ind==s.size()) return 0;\n if(dp[ind]!=-1) return dp[ind];\n if(s[ind]=='a')\n return dp[ind]=rec(ind+1,s);\n return dp[ind]=min(1+rec(ind+1,s),cnt[ind]);\n }\npublic:... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\nprivate:\n int minDeletions;\n \n void updateChar(string s, vector<int>& charCount,int start, int end, int increment, char ch, bool secondPass){\n int currCount = 0;\n for(int i = start; i != end; i += increment){\n if(s[i - increment] == ch) currCount++;... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\nprivate:\n int minDeletions;\n \n void updateChar(string s, vector<int>& charCount,int start, int end, int increment, char ch, bool secondPass){\n int currCount = 0;\n for(int i = start; i != end; i += increment){\n if(s[i - increment] == ch) currCount++;... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\nprivate:\n int minDeletions;\n void updateChar(string s, vector<int>& charCount,int start, int end, int increment, char ch, bool secondPass){\n int currCount = 0;\n for(int i = start; i != end; i += increment){\n if(s[i - increment] == ch) currCount++;\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\nprivate:\n int minDeletions;\n \n void updateChar(string s, vector<int>& charCount,int start, int end, int increment, char ch, bool secondPass){\n int currCount = 0;\n for(int i = start; i != end; i += increment){\n if(s[i - increment] == ch) currCount++;... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n Solution() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n }\n\n static int minimumDeletions(const string &s) {\n const int n = s.size();\n struct val {\n int end_a = 0, end_b = 0;\n };\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\nint minimumDeletions(const string &s) {\n int last_a = -1;\n int first_b = s.size();\n vector<pair<int, int>> vp(s.size());\n\n for (int i = 0; i < s.size(); i++)\n if (s[i] == 'a')\n last_a = i;\n else {\n first_b = min(first_b, i)... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int dfs(int ind,vector<pair<int,int>> &nums,vector<int> &dp)\n {\n if(ind==nums.size())\n return 0;\n if(dp[ind]!=-1)\n return dp[ind];\n return dp[ind] = min(nums[ind].second,nums[ind].first+dfs(ind+1,nums,dp));\n }\n int m... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string& s) {\n const int n=s.size();\n vector<int> B_pre(n), A_suf(n);//0-based prefix sums & suffix sums\n B_pre[0]=s[0]=='b';\n A_suf[0]=count(s.begin(), s.end(), 'a');// Count 'a' in s\n for(int i=1; i<n; i++){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int minimumDeletions(string& s) {\n const int n=s.size();\n vector<int> B_pre(n), A_suf(n);//0-based prefix sums & suffix sums\n B_pre[0]=s[0]=='b';\n A_suf[0]=count(s.begin(), s.end(), 'a');// Count 'a' in s\n for(int i=1; i<n; i++){\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int other(string s,stack<int>&st){\n int count=0;\n for(int i=0;i<s.length();i++){\n if(st.empty()){\n st.push(s[i]);\n }\n else if(st.top()=='a' && (s[i]=='b' || s[i]=='a')){\n st.push(s[i]);\n ... |
1,756 | <p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>ββββ.</p>
<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices... | 3 | {
"code": "class Solution {\npublic:\n int other(string s,stack<int>&st){\n int count=0;\n for(int i=0;i<s.length();i++){\n if(st.empty()){\n st.push(s[i]);\n }\n else if(st.top()=='a' && (s[i]=='b' || s[i]=='a')){\n st.push(s[i]);\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.