LearnCode

LearnCode

Пікірлер

  • @basepasandhai1906
    @basepasandhai19068 күн бұрын

    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.

  • @banidhanagar6951
    @banidhanagar695120 күн бұрын

    great explanation but please show whole code one time during the video

  • @LearnCodeHS
    @LearnCodeHS20 күн бұрын

    @@banidhanagar6951Tysm and I'll post it in the comments going forwrd.

  • @tanishagupta9997
    @tanishagupta999721 күн бұрын

    great explanation!

  • @top_g755
    @top_g75521 күн бұрын

    Thanks

  • @kartiknagrale1479
    @kartiknagrale147921 күн бұрын

    Muze laga x me sirf array ka element le sakte 😢😢

  • @vaibhav9310
    @vaibhav931021 күн бұрын

    Mera pura logic sahi tha bas ye "long long" ne leli meri 🥲

  • @kky7811
    @kky781121 күн бұрын

    Thanks a lot for ur effort .

  • @LearnCodeHS
    @LearnCodeHS21 күн бұрын

    Thanks and hope it helped.

  • @kartiknagrale1479
    @kartiknagrale147921 күн бұрын

    subscribed plz keep uploading

  • @LearnCodeHS
    @LearnCodeHS21 күн бұрын

    zarur bhai

  • @user-kj9oh3dr3o
    @user-kj9oh3dr3o21 күн бұрын

    Great Explanation!

  • @anshumaan1024
    @anshumaan102423 күн бұрын

    nice explanation

  • @Dream_Drive89
    @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?

  • @Ronakrewar
    @Ronakrewar28 күн бұрын

    bhai yaar break the string wala batao hashing se

  • @LearnCodeHS
    @LearnCodeHS28 күн бұрын

    I couldn't make it.. Will try to upload soon

  • @user-ur7ff9fe4o
    @user-ur7ff9fe4o28 күн бұрын

    Bro, what's your rating in codechef.

  • @LearnCodeHS
    @LearnCodeHS28 күн бұрын

    1656

  • @user-ur7ff9fe4o
    @user-ur7ff9fe4o28 күн бұрын

    @@LearnCodeHS 🙌🙌👍

  • @Ronakrewar
    @Ronakrewar28 күн бұрын

    int,int ka unordered map lene pe wrong as bata raha tha vahi long long lene pe submit ho gya why?

  • @LearnCodeHS
    @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

  • @NEF7354
    @NEF735428 күн бұрын

    Good approach

  • @youtubebiotin4582
    @youtubebiotin458228 күн бұрын

    just a suggestion it will be better if you provide question link in description 😊😊. By the way nice content helped me a lot

  • @LearnCodeHS
    @LearnCodeHS28 күн бұрын

    Sure bro. Thanks a lot

  • @harshdhochak8361
    @harshdhochak836128 күн бұрын

    har week daalna video bro, great !

  • @LearnCodeHS
    @LearnCodeHS28 күн бұрын

    Uske lie Subscribe zarur krna :P. But thanks bro

  • @srijanverma1782
    @srijanverma1782Ай бұрын

    You have gained a subscriber.Your explanation is very good Sir

  • @LearnCodeHS
    @LearnCodeHSАй бұрын

    Thanks bro. Thanks for the support!

  • @ishaansharma6553
    @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
    @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
    @ishaansharma6553Ай бұрын

    @@LearnCodeHS yeah but do we need i/p array , i mean we can do it withkut ip array right

  • @LearnCodeHS
    @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
    @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
    @LearnCodeHSАй бұрын

    @@ishaansharma6553 That's even nice bro. I couldn't think of it during contest

  • @rishi2820
    @rishi2820Ай бұрын

    nice video, to the point and crisp solutions, thank you

  • @amankumargupta8365
    @amankumargupta8365Ай бұрын

    searching for this type of explanation and u give it . Great work , keep doing it

  • @Ronakrewar
    @RonakrewarАй бұрын

    Wo first permutations wala question kese hoga

  • @LearnCodeHS
    @LearnCodeHSАй бұрын

    Talking about Maximum distance permutations? This video is already uploaded on my channel

  • @udaykirankorada1771
    @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
    @LearnCodeHSАй бұрын

    TC is correct but are you pre-computing the prefixSumOfNPrimes?

  • @AnuragKumar-vw8gh
    @AnuragKumar-vw8ghАй бұрын

    How should I practice to solve these type of questions during the time control. If you can suggest me.

  • @LearnCodeHS
    @LearnCodeHSАй бұрын

    Keep grinding. Practice is the only key . Solve questions above your rating like 200-300+

  • @AnuragKumar-vw8gh
    @AnuragKumar-vw8ghАй бұрын

    Thank You Sir, you have explained this question in very simple way. It really helps to understand easily & quickly.

  • @LearnCodeHS
    @LearnCodeHSАй бұрын

    Glad it helped. Happy learning!

  • @LearnCodeHS
    @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
    @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(); } }

  • @LearnCodeHS
    @LearnCodeHSАй бұрын

    #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(); } }

  • @notladinesh-iiitk7469
    @notladinesh-iiitk7469Ай бұрын

    Where is the code link?

  • @notladinesh-iiitk7469
    @notladinesh-iiitk7469Ай бұрын

    0 audio

  • @LearnCodeHS
    @LearnCodeHSАй бұрын

    My bad. Will try to fix it from now onwards

  • @21pranavsingh
    @21pranavsinghАй бұрын

    Thanks:)

  • @dyno2337
    @dyno23372 ай бұрын

    Good explanation bro.....Keep it up

  • @harshmishra9008
    @harshmishra90082 ай бұрын

    Good job

  • @anirudhsinghshekhawat9938
    @anirudhsinghshekhawat99382 ай бұрын

    Great video! Thank you

  • @ShaikShajahan-ur5qg
    @ShaikShajahan-ur5qg2 ай бұрын

    Bro very well explained ! keep going... looking forward for more videos

  • @LearnCodeHS
    @LearnCodeHS2 ай бұрын

    Thanks a ton

  • @HodakoMorishima
    @HodakoMorishima2 ай бұрын

    Brother explain the code properly

  • @LearnCodeHS
    @LearnCodeHS2 ай бұрын

    Sure. We'll fix it going forward to

  • @youtubebiotin4582
    @youtubebiotin45822 ай бұрын

    bro optimise your mic volume its too low

  • @LearnCodeHS
    @LearnCodeHS2 ай бұрын

    Thanks for feedback. Will fix it going forward

  • @dhruvrawatt9
    @dhruvrawatt92 ай бұрын

    kya ye optimised solution hai?

  • @LearnCodeHS
    @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

  • @dhruvrawatt9
    @dhruvrawatt92 ай бұрын

    @@LearnCodeHS but that solution is giving WA on some cases and people are discussing that it passed in contest due to weak tc.

  • @LearnCodeHS
    @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

  • @LearnCodeHS
    @LearnCodeHS2 ай бұрын

    #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(); } }

  • @mihs05
    @mihs052 ай бұрын

    provide your codeforces handle please;

  • @arkaroy-oh2lf
    @arkaroy-oh2lf2 ай бұрын

    Thank You bhai.

  • @LearnCodeHS
    @LearnCodeHS2 ай бұрын

    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; } };

  • @LearnCodeHS
    @LearnCodeHS2 ай бұрын

    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; } };

  • @RiteshPatil0403
    @RiteshPatil04033 ай бұрын

    esse faltu question nee dekhaa bhai , galti ho gayi codechef pe aake bc

  • @LearnCodeHS
    @LearnCodeHS3 ай бұрын

    #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(); } }

  • @LearnCodeHS
    @LearnCodeHS3 ай бұрын

    #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(); } }

  • @LearnCodeHS
    @LearnCodeHS3 ай бұрын

    #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(); } }

  • @LearnCodeHS
    @LearnCodeHS3 ай бұрын

    #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(); } }

  • @LearnCodeHS
    @LearnCodeHS3 ай бұрын

    #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(); } }

  • @yashwairagade3677
    @yashwairagade36773 ай бұрын

    bro phle question smzaya kro phir solution batao

  • @LearnCodeHS
    @LearnCodeHS3 ай бұрын

    dhyan rakhunga