test case-> 20 6 18. The above formula returns b = 6, when a = 8. So, we can make 6 pairs with dif B. where A = 8, but we can actually make only five pairs (8,5) to (8,1). correct this pls.
@banidhanagar695120 күн бұрын
great explanation but please show whole code one time during the video
@LearnCodeHS20 күн бұрын
@@banidhanagar6951Tysm and I'll post it in the comments going forwrd.
@tanishagupta999721 күн бұрын
great explanation!
@top_g75521 күн бұрын
Thanks
@kartiknagrale147921 күн бұрын
Muze laga x me sirf array ka element le sakte 😢😢
@vaibhav931021 күн бұрын
Mera pura logic sahi tha bas ye "long long" ne leli meri 🥲
@kky781121 күн бұрын
Thanks a lot for ur effort .
@LearnCodeHS21 күн бұрын
Thanks and hope it helped.
@kartiknagrale147921 күн бұрын
subscribed plz keep uploading
@LearnCodeHS21 күн бұрын
zarur bhai
@user-kj9oh3dr3o21 күн бұрын
Great Explanation!
@anshumaan102423 күн бұрын
nice explanation
@Dream_Drive8926 күн бұрын
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int choc[n], cand[n]; for (int i = 0; i < n; i++) { cin >> choc[i] >> cand[i]; } int cnt = 0; unordered_map<int,int>mp; for (int i = 0; i < n; i++) { mp[choc[i]%m]++; } for(int i=0;i<n;i++){ int c=cand[i]%m; if(c==0){ cnt+=mp[0]; } else{ cnt+=mp[m-c]; } } cout<<cnt<<endl;} return 0; } this is according to your code but not running for all test cases.Can u tell me why?
@Ronakrewar28 күн бұрын
bhai yaar break the string wala batao hashing se
@LearnCodeHS28 күн бұрын
I couldn't make it.. Will try to upload soon
@user-ur7ff9fe4o28 күн бұрын
Bro, what's your rating in codechef.
@LearnCodeHS28 күн бұрын
1656
@user-ur7ff9fe4o28 күн бұрын
@@LearnCodeHS 🙌🙌👍
@Ronakrewar28 күн бұрын
int,int ka unordered map lene pe wrong as bata raha tha vahi long long lene pe submit ho gya why?
@LearnCodeHS28 күн бұрын
Look at the constraints. N may go upto 10^5. Ek case aisa bhi ho skta jisme array A ka har element array B k har element k sath pair bna le.. In that case.. Vo int range ko cross kr jayega.. Isliye need long long
@NEF735428 күн бұрын
Good approach
@youtubebiotin458228 күн бұрын
just a suggestion it will be better if you provide question link in description 😊😊. By the way nice content helped me a lot
@LearnCodeHS28 күн бұрын
Sure bro. Thanks a lot
@harshdhochak836128 күн бұрын
har week daalna video bro, great !
@LearnCodeHS28 күн бұрын
Uske lie Subscribe zarur krna :P. But thanks bro
@srijanverma1782Ай бұрын
You have gained a subscriber.Your explanation is very good Sir
@LearnCodeHSАй бұрын
Thanks bro. Thanks for the support!
@ishaansharma6553Ай бұрын
do we need to create an array in manhattan circle , it only increases time complexity , we can do the que without it also . And i am an beginner in cf so can you suggest why you use signed main etc is there any boilerplate code or something to do this ?
@LearnCodeHSАй бұрын
The only array I have is the input array. Didn't get you? yes its a boilerplate code and because I am using macro #define int long long , the main function cannot have return type long long , so used 'signed' because signed and int both are same
@ishaansharma6553Ай бұрын
@@LearnCodeHS yeah but do we need i/p array , i mean we can do it withkut ip array right
@LearnCodeHSАй бұрын
@@ishaansharma6553you can but. Input array se tc pr frk nhi padga and What other operations you perform are taken into consideration TC analysis
@ishaansharma6553Ай бұрын
@@LearnCodeHS you took i/p array and traversed on it for result , i just computed answer in input itself and didnt store it like other
@LearnCodeHSАй бұрын
@@ishaansharma6553 That's even nice bro. I couldn't think of it during contest
@rishi2820Ай бұрын
nice video, to the point and crisp solutions, thank you
@amankumargupta8365Ай бұрын
searching for this type of explanation and u give it . Great work , keep doing it
@RonakrewarАй бұрын
Wo first permutations wala question kese hoga
@LearnCodeHSАй бұрын
Talking about Maximum distance permutations? This video is already uploaded on my channel
@udaykirankorada1771Ай бұрын
Can you tell me the time complexity of " Sum of N" Implementation in your code. Bcz I wrote same code almost and I also used sieve of Eratosthenes. But I got TLE. My code time is Klog log K + root(K) + atmost K for loop which won't go completely most of times.
@LearnCodeHSАй бұрын
TC is correct but are you pre-computing the prefixSumOfNPrimes?
@AnuragKumar-vw8ghАй бұрын
How should I practice to solve these type of questions during the time control. If you can suggest me.
@LearnCodeHSАй бұрын
Keep grinding. Practice is the only key . Solve questions above your rating like 200-300+
@AnuragKumar-vw8ghАй бұрын
Thank You Sir, you have explained this question in very simple way. It really helps to understand easily & quickly.
@LearnCodeHSАй бұрын
Glad it helped. Happy learning!
@LearnCodeHSАй бұрын
#include<bits/stdc++.h> using namespace std; #define int long long bool prime[1000001]; int prefixSum[1000001]={0}; void SieveOfEratosthenes() { memset(prime, true, sizeof(prime)); int e=1000001; for (int p = 2; p * p <= e; p++) { if (prime[p] == true) { for (int i = p * p; i <= e; i += p) prime[i] = false; } } } void prefixSumOfNPrimeNumbers(){ int s=0; for(int i=2;i<=1000001;i++){ if(prime[i]){ s+=i; } prefixSum[i]=s; } } void solve(){ int n; cin>>n; if(n%2==0){ cout<<n*2<<endl; } else if(prime[n]){ cout<<prefixSum[n]*n<<endl; } else{ int divisor=3; for(int i=3;i*i<=n;i+=1){ if(n%i==0){ divisor=i; break; } } cout<<prefixSum[divisor]*n<<endl; } } signed main() { int t; cin>>t; SieveOfEratosthenes(); prefixSumOfNPrimeNumbers(); while(t--){ solve(); } }
@LearnCodeHSАй бұрын
D. Manhattan Circle #include<bits/stdc++.h> using namespace std; //check you variables naming,can be repeating #define int long long int void solve(){ int n,m; cin>>n>>m; vector<vector<char>> v(n,vector<char>(m)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>v[i][j]; } } int io=0; int jo=0; int cnt=0; bool f=true; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(v[i][j]=='#'){ cnt=i; // cout<<"cnt "<<cnt<<endl; io=i; jo=j; f=false; break; } } if(!f)break; } while(true){ if(io+1<n && v[io+1][jo]=='#'){ io++; } else{ break; } } cout<<((io+cnt)/2)+1<<" "<<(jo+1)<<endl; } signed main() { int t; cin>>t; while(t--){ solve(); } }
Bro very well explained ! keep going... looking forward for more videos
@LearnCodeHS2 ай бұрын
Thanks a ton
@HodakoMorishima2 ай бұрын
Brother explain the code properly
@LearnCodeHS2 ай бұрын
Sure. We'll fix it going forward to
@youtubebiotin45822 ай бұрын
bro optimise your mic volume its too low
@LearnCodeHS2 ай бұрын
Thanks for feedback. Will fix it going forward
@dhruvrawatt92 ай бұрын
kya ye optimised solution hai?
@LearnCodeHS2 ай бұрын
ofc not, its the brute force approach that I came up with during contest , but there is a solution in O(N) TC way better than this using gcd
@dhruvrawatt92 ай бұрын
@@LearnCodeHS but that solution is giving WA on some cases and people are discussing that it passed in contest due to weak tc.
@LearnCodeHS2 ай бұрын
@@dhruvrawatt9 honestly I haven't yet went through the solution (gcd wala) , but walked through some tutorials and they too explaining the same appraoch (which I discussed here) , maybe that gcd wali approach is wrong
Пікірлер
test case-> 20 6 18. The above formula returns b = 6, when a = 8. So, we can make 6 pairs with dif B. where A = 8, but we can actually make only five pairs (8,5) to (8,1). correct this pls.
great explanation but please show whole code one time during the video
@@banidhanagar6951Tysm and I'll post it in the comments going forwrd.
great explanation!
Thanks
Muze laga x me sirf array ka element le sakte 😢😢
Mera pura logic sahi tha bas ye "long long" ne leli meri 🥲
Thanks a lot for ur effort .
Thanks and hope it helped.
subscribed plz keep uploading
zarur bhai
Great Explanation!
nice explanation
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int choc[n], cand[n]; for (int i = 0; i < n; i++) { cin >> choc[i] >> cand[i]; } int cnt = 0; unordered_map<int,int>mp; for (int i = 0; i < n; i++) { mp[choc[i]%m]++; } for(int i=0;i<n;i++){ int c=cand[i]%m; if(c==0){ cnt+=mp[0]; } else{ cnt+=mp[m-c]; } } cout<<cnt<<endl;} return 0; } this is according to your code but not running for all test cases.Can u tell me why?
bhai yaar break the string wala batao hashing se
I couldn't make it.. Will try to upload soon
Bro, what's your rating in codechef.
1656
@@LearnCodeHS 🙌🙌👍
int,int ka unordered map lene pe wrong as bata raha tha vahi long long lene pe submit ho gya why?
Look at the constraints. N may go upto 10^5. Ek case aisa bhi ho skta jisme array A ka har element array B k har element k sath pair bna le.. In that case.. Vo int range ko cross kr jayega.. Isliye need long long
Good approach
just a suggestion it will be better if you provide question link in description 😊😊. By the way nice content helped me a lot
Sure bro. Thanks a lot
har week daalna video bro, great !
Uske lie Subscribe zarur krna :P. But thanks bro
You have gained a subscriber.Your explanation is very good Sir
Thanks bro. Thanks for the support!
do we need to create an array in manhattan circle , it only increases time complexity , we can do the que without it also . And i am an beginner in cf so can you suggest why you use signed main etc is there any boilerplate code or something to do this ?
The only array I have is the input array. Didn't get you? yes its a boilerplate code and because I am using macro #define int long long , the main function cannot have return type long long , so used 'signed' because signed and int both are same
@@LearnCodeHS yeah but do we need i/p array , i mean we can do it withkut ip array right
@@ishaansharma6553you can but. Input array se tc pr frk nhi padga and What other operations you perform are taken into consideration TC analysis
@@LearnCodeHS you took i/p array and traversed on it for result , i just computed answer in input itself and didnt store it like other
@@ishaansharma6553 That's even nice bro. I couldn't think of it during contest
nice video, to the point and crisp solutions, thank you
searching for this type of explanation and u give it . Great work , keep doing it
Wo first permutations wala question kese hoga
Talking about Maximum distance permutations? This video is already uploaded on my channel
Can you tell me the time complexity of " Sum of N" Implementation in your code. Bcz I wrote same code almost and I also used sieve of Eratosthenes. But I got TLE. My code time is Klog log K + root(K) + atmost K for loop which won't go completely most of times.
TC is correct but are you pre-computing the prefixSumOfNPrimes?
How should I practice to solve these type of questions during the time control. If you can suggest me.
Keep grinding. Practice is the only key . Solve questions above your rating like 200-300+
Thank You Sir, you have explained this question in very simple way. It really helps to understand easily & quickly.
Glad it helped. Happy learning!
#include<bits/stdc++.h> using namespace std; #define int long long bool prime[1000001]; int prefixSum[1000001]={0}; void SieveOfEratosthenes() { memset(prime, true, sizeof(prime)); int e=1000001; for (int p = 2; p * p <= e; p++) { if (prime[p] == true) { for (int i = p * p; i <= e; i += p) prime[i] = false; } } } void prefixSumOfNPrimeNumbers(){ int s=0; for(int i=2;i<=1000001;i++){ if(prime[i]){ s+=i; } prefixSum[i]=s; } } void solve(){ int n; cin>>n; if(n%2==0){ cout<<n*2<<endl; } else if(prime[n]){ cout<<prefixSum[n]*n<<endl; } else{ int divisor=3; for(int i=3;i*i<=n;i+=1){ if(n%i==0){ divisor=i; break; } } cout<<prefixSum[divisor]*n<<endl; } } signed main() { int t; cin>>t; SieveOfEratosthenes(); prefixSumOfNPrimeNumbers(); while(t--){ solve(); } }
D. Manhattan Circle #include<bits/stdc++.h> using namespace std; //check you variables naming,can be repeating #define int long long int void solve(){ int n,m; cin>>n>>m; vector<vector<char>> v(n,vector<char>(m)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>v[i][j]; } } int io=0; int jo=0; int cnt=0; bool f=true; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(v[i][j]=='#'){ cnt=i; // cout<<"cnt "<<cnt<<endl; io=i; jo=j; f=false; break; } } if(!f)break; } while(true){ if(io+1<n && v[io+1][jo]=='#'){ io++; } else{ break; } } cout<<((io+cnt)/2)+1<<" "<<(jo+1)<<endl; } signed main() { int t; cin>>t; while(t--){ solve(); } }
#include<bits/stdc++.h> using namespace std; void solve(){ int n,k; cin>>n>>k; vector<int> v; for(int i=0;i<n;i++){ int e; cin>>e; v.push_back(e); } int sum=0; for(int i=0;i<n-1;i++){ sum+=abs(v[i]-v[i+1]); } int maxi=sum; // bool f=true; for(int i=0;i<n;i++){ // v[i]=j; int o=sum; if(i==0){ o-=abs(v[i]-v[i+1]); o+=abs(1-v[i+1]); } else if(i==n-1){ o-=abs(v[i-1]-v[i]); o+=abs(v[i-1]-1); } else{ o-=abs(v[i]-v[i-1]); o-=abs(v[i]-v[i+1]); o+=abs(1-v[i-1]); o+=abs(1-v[i+1]); } maxi=max(maxi,o); o=sum; if(i==0){ o-=abs(v[i]-v[i+1]); o+=abs(k-v[i+1]); } else if(i==n-1){ o-=abs(v[i-1]-v[i]); o+=abs(v[i-1]-k); } else{ o-=abs(v[i]-v[i-1]); o-=abs(v[i]-v[i+1]); o+=abs(k-v[i-1]); o+=abs(k-v[i+1]); } maxi=max(maxi,o); } cout<<maxi<<endl; } int main() { int t; cin>>t; while(t--){ solve(); } }
Where is the code link?
0 audio
My bad. Will try to fix it from now onwards
Thanks:)
Good explanation bro.....Keep it up
Good job
Great video! Thank you
Bro very well explained ! keep going... looking forward for more videos
Thanks a ton
Brother explain the code properly
Sure. We'll fix it going forward to
bro optimise your mic volume its too low
Thanks for feedback. Will fix it going forward
kya ye optimised solution hai?
ofc not, its the brute force approach that I came up with during contest , but there is a solution in O(N) TC way better than this using gcd
@@LearnCodeHS but that solution is giving WA on some cases and people are discussing that it passed in contest due to weak tc.
@@dhruvrawatt9 honestly I haven't yet went through the solution (gcd wala) , but walked through some tutorials and they too explaining the same appraoch (which I discussed here) , maybe that gcd wali approach is wrong
#include<bits/stdc++.h> using namespace std; void solve(){ int n,k; cin>>n>>k; vector<string> v; for(int i=0;i<n;i++){ string e; cin>>e; v.push_back(e); } set<string> st; for(string s:v)st.insert(s); string temp=""; for(int i=0;i<k;i++){ temp.push_back('0'); } // k==4 // 0000 // for(int i=k-1;i>=0;i--){ temp[i]='1'; if(st.find(temp)==st.end()){ cout<<"NO"<<endl; return ; } temp[i]='0'; } cout<<"YES"<<endl; } int main() { int t; cin>>t; while(t--){ solve(); } }
provide your codeforces handle please;
Thank You bhai.
class Solution { public: bool check(vector<int> &v1,vector<int> &v2){ for(int i=0;i<v1.size()-1;i++){ if(v1[i]-v2[i]!=v1[i+1]-v2[i+1]){ return false; } } return true; } int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) { sort(nums1.begin(),nums1.end()); sort(nums2.begin(),nums2.end()); int mini=INT_MAX; for(int i=0;i<nums1.size()-1;i++){ for(int j=i+1;j<nums1.size();j++){ vector<int> v; for(int a=0;a<nums1.size();a++){ if(a!=i && a!=j){ v.push_back(nums1[a]); } } if(check(v,nums2)){ mini=min(mini,nums2[0]-v[0]); } } } return mini; } };
class Solution { public: long long numberOfRightTriangles(vector<vector<int>>& grid) { long long ans=0; vector<int> row(grid.size()); vector<int> col(grid[0].size()); for(int i=0;i<grid.size();i++){ int cnt=0; for(int j=0;j<grid[i].size();j++){ cnt+=grid[i][j]; } row[i]=cnt; } for(int j=0;j<grid[0].size();j++){ int cnt=0; for(int i=0;i<grid.size();i++){ cnt+=grid[i][j]; } col[j]=cnt; } for(int i=0;i<grid.size();i++){ for(int j=0;j<grid[0].size();j++){ if(grid[i][j]==1){ if(row[i]>1 && col[j]>1){ ans+=(row[i]-1)*(col[j]-1); } } } } return ans; } };
esse faltu question nee dekhaa bhai , galti ho gayi codechef pe aake bc
#include<bits/stdc++.h> using namespace std; const int MOD=1000000007; #define int long long void solve(){ int n; cin>>n; vector<int>v(n); for(int i=0;i<n;i++){ cin>>v[i]; } sort(v.begin(),v.end()); int s=0; for(int i=0;i<n;i++){ if(s==0 || v[i]==1 || s==1 ){ s+=(v[i]%MOD); s%=MOD; } else{ s=s*(v[i]%MOD); s%=MOD; } } cout<<s%MOD<<endl; } signed main() { int t; cin>>t; while(t--){ solve(); } }
#include<bits/stdc++.h> using namespace std; #define int long long void solve(){ int n,k; cin>>n>>k; vector<int> v; for(int i=0;i<n;i++){ int e; cin>>e; v.push_back(e); } sort(v.begin(),v.end()); int i=0; int ans=0; while(i<n && k>0){ if(v[i]<=3){ ans+=7-v[i]; k--; } else{ ans+=v[i]; } i++; } while(i<n)ans+=v[i++]; cout<<ans<<endl; } signed main() { int t; cin>>t; while(t--){ solve(); } }
#include<bits/stdc++.h> using namespace std; void solve(){ int n; cin>>n; vector<int> v; for(int i=0;i<n;i++){ int e; cin>>e; v.push_back(e); } if(v[0]!=v[n-1]){ cout<<"NO"<<endl; } else{ int mini=*min_element(v.begin(),v.end()); if(mini<v[0]){ cout<<"NO"<<endl; } else{ cout<<"YES"<<endl; } } } int main() { int t; cin>>t; while(t--){ solve(); } }
#include<bits/stdc++.h> using namespace std; void solve(){ int n; cin>>n; string v; cin>>v; vector<int> ans; for(int i=0;i<n-1;i+=2){ if(v[i]!=v[i+1]){ if(ans.empty()) { ans.push_back(i+1); } else{ if(v[ans.back()-1]=='1'){ if(v[i]=='0'){ ans.push_back(i+1); } else{ ans.push_back(i+2); } } else if(v[ans.back()-1]=='0'){ if(v[i]=='1'){ ans.push_back(i+1); } else{ ans.push_back(i+2); } } } } } cout<<ans.size()<<endl; for(auto it:ans){ cout<<it<<" "; } cout<<endl; } int main() { int t; cin>>t; while(t--){ solve(); } }
#include<bits/stdc++.h> using namespace std; void solve(){ int n; cin>>n; string s; cin>>s; string o=""; for(int i=0;i<n;i++){ if(i%2==0){ o.push_back('0'); } else{ o.push_back('1'); } } string k=""; for(int i=0;i<n;i++){ if(i%2==0){ k.push_back('1'); } else{ k.push_back('0'); } } bool f=true; int cnt1=0; for(int i=0;i<n;i++){ if(f){ if(s[i]!=o[i]){ cnt1++; f=false; } } else{ if(s[i]==o[i]){ cnt1++; f=true; } } } f=true; int cnt2=0; for(int i=0;i<n;i++){ if(f){ if(s[i]!=k[i]){ cnt2++; f=false; } } else{ if(s[i]==k[i]){ cnt2++; f=true; } } } cout<<min(cnt1,cnt2)<<endl; } int main() { int t; cin>>t; while(t--){ solve(); } }
bro phle question smzaya kro phir solution batao
dhyan rakhunga