Count K-Subsequences of a String with Maximum Beauty Solution || Leetcode Bi-Weekly 112 Get link Facebook X Pinterest Email Other Apps - September 04, 2023 Count K-Subsequences of a String with Maximum Beauty Get link Facebook X Pinterest Email Other Apps
Remove Balance Solution || Codechef Starters - 37 Get link Facebook X Pinterest Email Other Apps - May 04, 2022 Remove Balance Solution Codechef Starters - 37Problem Code : REMBALProblem Link : https://www.codechef.com/START37C/problems/REMBALSolution :#include <bits/stdc++.h>#define ll long long intusing namespace std;int main(){ ll t = 1; cin >> t; while (t--) { string s; cin >> s; ll n = s.size(); stack<ll> st; for (ll i = 0; i < n; i++) { if (st.empty()) { st.push(i); } else if (s[st.top()] == '(' && s[i] == ')') { st.pop(); } else { st.push(i); } } vector<ll> v; while (!st.empty()) { ll k = st.top(); v.push_back(k); st.pop(); } ll k = v.size(); ll ans = 0; if (k != 0) { if (v[0] == n - 1) { ans = 0; for (ll i = 0; i < k - 1; i++) { if (v[i] - v[i + 1] > 1) { ans++; } } if (v[k - 1] > 0) { ans++; } } else { ans++; for (ll i = 0; i < k - 1; i++) { if (v[i] - v[i + 1] > 1) { ans++; } } if (v[k - 1] > 0) { ans++; } } } else { ans = 1; } cout << k << " " << ans << "\n"; }} Get link Facebook X Pinterest Email Other Apps Comments
Substring of a Substring Solution || Codechef March Long Challenge 2022 - I - March 11, 2022 Substring of a Substring Solution Read more
Exact Marks Solution || Codechef March Long Challenge 2022 - I - March 11, 2022 Exact Marks Solution Read more
Comments
Post a Comment