Current streak:
0 days
Longest streak:
35 days
Less
More
College monthly badge
3 Times topper
#include<bits/stdc++.h>
using namespace std;
string amazingStrings(string first, string second,string third) {
// Write your code here.
vector<int>dp(256,0);
for(auto i :third)
dp[i]++;
for(auto i: first)
dp[i]--;
for(auto i: second)
dp[i]--;
for(int i : dp)
if(i!=0)
return "NO";
return "YES";
}
#include <bits/stdc++.h>
pair < int , int > findMinMax(int a , int b)
{
// Write Your Code here
int dif=abs(a-b);
int max=(a+b+dif)/2; // if we add dif in mimum then its alos become equal to max
int min=(a+b)-max;
return {min,max};
}
#include <bits/stdc++.h>
bool wordBreak(vector < string > & arr, int n, string & target) {
// Write your code here.
std::unordered_set<std::string> dict(arr.begin(), arr.end());
int len = target.length();
std::vector<bool> dp(len + 1, false);
dp[0] = true;
for (int i = 1; i <= len; ++i) {
for (int j = 0; j < i; ++j) {
if (dp[j] && dict.find(target.substr(j, i - j)) != dict.end()) {
dp[i] = true;
break;
}
}
}
return dp[len] ? 1 : 0;
}
if any doubt, then ask in comment box
#include <bits/stdc++.h>
int subArrayCount(vector<int> &arr, int k) {
// Write your code here.
vector<int>v(k,0);// all posible remainder if devided by k;
v[0]=1; // if sum of all point till i divisable by k then then we can start with i==0;
int n=arr.size();
int sum=0;
int ans=0;
for(int i=0;i<n;i++)
{
sum+=arr[i];
sum=sum%k;
if(sum<0)
sum+=k;
ans+=v[sum]++;// if x%k=r and (x+y)%k=r then y is devisible by k, we have to count how may poisble x
}
return ans;
}