846. Hand of Straights | 1296. Divide Array in Sets of K Consecutive Numbers | Sorting | Map

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • In this video, I'll talk about how to solve Leetcode 846. Hand of Straights | 1296. Divide Array in Sets of K Consecutive Numbers | Sorting | Map
    Let's Connect:
    📱Discord (Join Community) : / discord
    📝Linkedin: / aryan-mittal-0077
    📸 Instagram: / codewitharyanbhai
    💻 Twitter - / aryan_mittal007
    🤖 Github: github.com/ary...
    About Me:
    I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
    ✨ Timelines✨
    ✨ Hashtags ✨
    #programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Komentáře • 22

  • @devanshmanchanda8439
    @devanshmanchanda8439 Před 3 měsíci +6

    pride month me , hand of straights, janke likha h paaka :))

  • @nandinigattani6348
    @nandinigattani6348 Před 3 měsíci

    I watch your explanation videos daily. These are great. Keep helping and making these videos. Thankyou so much✨

  • @JIGARSINGTHAKOR-yy6qp
    @JIGARSINGTHAKOR-yy6qp Před 3 měsíci +1

    no need tranverse frequency like while(freq--)
    for(auto x:m1){
    if(x.second ==0)continue;
    else{
    for(int i=x.first;i

  • @ARYANMITTAL
    @ARYANMITTAL  Před 3 měsíci +6

    Btw that if(freq == 0) is not required, as while(freq--) starts with while(0--) => while(0), so this will handle that continue case also ❤
    When are you ready for FAANG - czcams.com/video/h71X1VMo5J0/video.html
    .
    Don't rely on leetcode or any other hard approaches, leetcode has incorrect time Complexity in Editorial, Lee's solution also has incorrect Time Complexities.

    • @harshal8781
      @harshal8781 Před 3 měsíci +2

      lee❌ AM✅

    • @jaypatel-rm8sc
      @jaypatel-rm8sc Před 3 měsíci

      class Solution {
      public:
      bool isNStraightHand(vector& hand, int groupSize) {
      if(hand.size()%groupSize!=0)return false;
      mapmp;
      for(auto it:hand){
      mp[it]++;
      }
      for(auto it=mp.begin();it!=mp.end();it++){
      int n=it->first;
      int t=0;
      while(t!=groupSize){
      if(mp.find(n+t)==mp.end())return false;
      else{
      mp[n+t]--;
      if(mp[n+t]==0){
      mp.erase(n+t);
      }
      t++;
      }
      }

      }
      return true;
      }
      }; can u say whats the error here?

  • @raghavmanish24
    @raghavmanish24 Před 3 měsíci

    thanku aryan sir 😍😍

  • @nani17290
    @nani17290 Před 3 měsíci

    Top Notch Content ⭐

  • @kgjr.6224
    @kgjr.6224 Před 3 měsíci

    Maja tho aaya solution dekh k

  • @aniketbhura6131
    @aniketbhura6131 Před 3 měsíci +1

    Aryan I did the same thing .. but I traversed on the vector itself but I am having one issue of heap buffer overflow
    class Solution {
    public:
    bool isNStraightHand(vector& hand, int groupSize) {
    if(groupSize == 1) return true;
    if(hand.size() % groupSize != 0) return false;
    mapmp;
    sort(hand.begin() , hand.end());
    for(auto it : hand)
    {
    mp[it]++;
    }
    for(int i=0 ; i

    • @coderunner743
      @coderunner743 Před 3 měsíci

      class Solution {
      public:
      bool isPossibleDivide(vector& nums, int k) {
      int n = nums.size();
      if (n % k != 0)
      return false;
      unordered_map freq;
      for (int num: nums)
      freq[num]++;

      sort(nums.begin(), nums.end());
      int start = nums[0];
      for (int group = 0; group < n / k; group++) {
      if (start == -1)
      start = nums[group * k];
      int nextStart = -1;
      for (int groupEle = start; groupEle < start + k; groupEle++) {
      if (freq[groupEle] == 0)
      return false;
      if (freq[groupEle] > 1 && nextStart == -1)
      nextStart = groupEle;
      freq[groupEle]--;
      }

      start = nextStart;
      }
      return true;
      }
      };
      this is my solution as same as your logic. i hope its help you.

    • @jaypatel-rm8sc
      @jaypatel-rm8sc Před 3 měsíci

      same issue

    • @vadapallyvarshitha5013
      @vadapallyvarshitha5013 Před 3 měsíci

      Hi, if(mp[x] == 0) return false; will also make an unnecessary entry in your map and x can go to range of 10^9 . so that would create memory limitation . better use vector in this kind of situations where you have full control over entries.

  • @sameershah1492
    @sameershah1492 Před 3 měsíci

    How to apply for internship ?

    • @Anonymous____________A721
      @Anonymous____________A721 Před 3 měsíci +3

      LinkedIn
      Glassdoor
      Indeed
      Internshala and naukri are waste

    • @sameershah1492
      @sameershah1492 Před 3 měsíci

      @@Anonymous____________A721 internshala waste hai ??. Bhai kal se apply hi kiye jaara hu usme me

    • @Anonymous____________A721
      @Anonymous____________A721 Před 3 měsíci +1

      @@sameershah1492 no it's really time waste. Really no use. Glassdoor is 1000 times better.

    • @sameershah1492
      @sameershah1492 Před 3 měsíci

      @@Anonymous____________A721 ok. Main Glassdoor par try karta hu. Btw reply kitne din me aata ?

    • @Anonymous____________A721
      @Anonymous____________A721 Před 3 měsíci +1

      @@sameershah1492 2-3 weeks mostly