Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions CodeChef/MINLCS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// https://www.codechef.com/START61C/problems/MINLCS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(string s, string s1, int n)
{
map<char, ll> 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;
}
67 changes: 67 additions & 0 deletions Codeforces/EvenOddIncrements.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// https://codeforces.com/contest/1744/problem/B
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
void solve()
{
ll n, q;
cin >> n >> q;
vector<ll> even;
vector<ll> 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;
}
33 changes: 33 additions & 0 deletions LeetCode/FIND-DUPLICATE.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
// MAIN FUNCTION
int findDuplicate(vector<int> &nums)
{
int n = nums.size();
unordered_map<int, int> 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<int> v = {1, 3, 4, 2, 2};
cout << findDuplicate(v) << endl;
return 0;
}