Maximum Width of Binary Tree | LeetCode 662 | C++, Python

preview_player
Показать описание

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

July LeetCoding Challenge | Problem 9 | Maximum Width of Binary Tree | 9 July,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Maximum Width of Binary Tree,
Maximum Width of Binary Tree c++,
Maximum Width of Binary Tree Java,
Maximum Width of Binary Tree python,
Maximum Width of Binary Tree solution,
662. Maximum Width of Binary Tree,

#CodingInterview #LeetCode #JulyLeetCodingChallenge #Google #Amazon #BinaryTree
Рекомендации по теме
Комментарии
Автор

loved the way you showed the error and then gave the explanation and the way of correcting it!

acxd
Автор

It pops out many times..but for longer duration I ignored it...but after watching this ...regretted that I have lost my precious 2 hours....Loved the way you explain it patiently...

kanishkraj
Автор

Superb explanation !!!!
One of the best teaching style I have seen on YouTube
Cheers man !

SugamMaheshwari
Автор

Thank you for making such helpful videos! Please keep making them!

DAN-izgi
Автор

Explanations are best part of your video sir.

AlokKumar-jhwp
Автор

Did Leetcode add more test cases?? This code is still giving int overflow at last test case.

mdrameez
Автор

I would simply say => you are really Awesome

faisalrafi
Автор

Simple we can use unsigned long long int to get AC buddy!!

lovleshbhatt
Автор

Great Explanation Sir. Can you please also try explaining solutions for Weekly and BiWeekly challenges. Already learnt a lot from you. Thanks :)

himanshushashank
Автор

Will the python code work for root = 1, leftchild = null, rightchild = 3 ?

AshaYalla
Автор

After addition of more test cases in this leetcode question, C++ Solution still gives Runtime Error

AyushRaj-pmdz
Автор

Explanation was good . I have a doubt..why to add +1 in the result i.e (end-start)+1..can u plz clarify ..

pratyushranjansahu
Автор

What tool do you use for presentation?

AdilFulara
Автор

sir how to come up with these approaches is there any book to go through?

siddharthsingh
Автор

Sir, in your videos you use inbuilt vectors, function from where we can study these. Thanks for your videos.

sscoder
Автор

I don't know if I miss it but I didn't see the solution in Java.

midasama
Автор

This may be a solution too
But its giving me a runtime error
Help me find the bug



class Solution {
public:
int widthOfBinaryTree(TreeNode* root) {
if(root==NULL)
return 0;
int res=1;
int count=1;
int level=0;
TreeNode* curr;
queue<TreeNode*> q;
q.push(root);
while(!q.empty()){
int t=0;
while(count--){
curr=q.front();
q.pop();
if(curr==NULL)
continue;
q.push(curr->left);
q.push(curr->right);
}
int first=-1;
int second=-1;
int i=0;
queue<TreeNode*> deq=q;
while(!deq.empty()){
if(deq.front()!=NULL){
if(first==-1)
first=i;
if(i>second)
second=i;
}
i++;
deq.pop();
}
t=second-first+1;
if(t>res)
res=t;
level++;
count=pow(2, level);
}
return res;
}
};

rajatnagpure
visit shbcf.ru