846. Hand of Straights | 1296. Divide Array in Sets of K Consecutive Numbers | Sorting | Map
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
pride month me , hand of straights, janke likha h paaka :))
I watch your explanation videos daily. These are great. Keep helping and making these videos. Thankyou so much✨
no need tranverse frequency like while(freq--)
for(auto x:m1){
if(x.second ==0)continue;
else{
for(int i=x.first;i
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.
lee❌ AM✅
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?
thanku aryan sir 😍😍
Top Notch Content ⭐
Maja tho aaya solution dekh k
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
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.
same issue
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.
How to apply for internship ?
LinkedIn
Glassdoor
Indeed
Internshala and naukri are waste
@@Anonymous____________A721 internshala waste hai ??. Bhai kal se apply hi kiye jaara hu usme me
@@sameershah1492 no it's really time waste. Really no use. Glassdoor is 1000 times better.
@@Anonymous____________A721 ok. Main Glassdoor par try karta hu. Btw reply kitne din me aata ?
@@sameershah1492 2-3 weeks mostly