diff --git a/CodeChef/MINLCS.cpp b/CodeChef/MINLCS.cpp new file mode 100644 index 0000000..57ecccc --- /dev/null +++ b/CodeChef/MINLCS.cpp @@ -0,0 +1,48 @@ +// https://www.codechef.com/START61C/problems/MINLCS +#include +using namespace std; +#define ll long long +void solve(string s, string s1, int n) +{ + map f, fa; + for (auto u : s) + { + f[u]++; + } + for (auto u : s1) + { + fa[u]++; + } + ll mn = 0; + for (ll i = 0; i < s.size(); i++) + { + if (f[s[i]] > 0 && fa[s[i]] > 0) + { + ll a = min(f[s[i]], fa[s[i]]); + mn = max(mn, a); + } + } + if (mn == 0) + { + cout << 0 << endl; + } + else + { + cout << mn << endl; + } +} +int main() +{ + int t; + cin >> t; + while (t--) + { + int n; + cin >> n; + string s, s1; + cin >> s >> s1; + + solve(s, s1, n); + } + return 0; +} \ No newline at end of file diff --git a/Codeforces/EvenOddIncrements.cpp b/Codeforces/EvenOddIncrements.cpp new file mode 100644 index 0000000..8afbabf --- /dev/null +++ b/Codeforces/EvenOddIncrements.cpp @@ -0,0 +1,67 @@ +// https://codeforces.com/contest/1744/problem/B +#include +using namespace std; +#define ll long long +#define endl "\n" +void solve() +{ + ll n, q; + cin >> n >> q; + vector even; + vector odd; + ll ans = 0; + for (int i = 0; i < n; i++) + { + ll inp; + cin >> inp; + if (inp % 2 == 0) + { + even.push_back(inp); + } + else + { + odd.push_back(inp); + } + ans += inp; + } + ll e = even.size(); + ll o = odd.size(); + for (ll i = 0; i < q; i++) + { + ll x, y; + cin >> x >> y; + if (x == 0 and y % 2 == 0) + { + ans += (y * e); + } + else if (x == 0 and y % 2 == 1) + { + ans += (y * e); + e = 0; + o = n; + } + else if (x == 1 and y % 2 == 0) + { + ans += (y * o); + } + else if (x == 1 and y % 2 == 1) + { + ans += (y * o); + e = n; + o = 0; + } + cout << ans << endl; + } +} +int main() +{ + ios::sync_with_stdio(false); + cin.tie(NULL), cout.tie(NULL); + ll t; + cin >> t; + while (t--) + { + solve(); + } + return 0; +} \ No newline at end of file diff --git a/LeetCode/FIND-DUPLICATE.cpp b/LeetCode/FIND-DUPLICATE.cpp new file mode 100644 index 0000000..bdb77e9 --- /dev/null +++ b/LeetCode/FIND-DUPLICATE.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; +#define ll long long +#define endl "\n" +// MAIN FUNCTION +int findDuplicate(vector &nums) +{ + int n = nums.size(); + unordered_map m; + for (int i = 0; i < n; i++) + { + m[nums[i]]++; + } + int ans; + for (auto it : m) + { + if (it.second > 1) + { + ans = it.first; + break; + } + } + return ans; +} +int main() +{ + ios::sync_with_stdio(false); + cin.tie(NULL), cout.tie(NULL); + // SAMPLE TESTCASES + vector v = {1, 3, 4, 2, 2}; + cout << findDuplicate(v) << endl; + return 0; +} \ No newline at end of file