Populating Next Right Pointers in Each Node II | Leetcode 117 | Cakewalk BFS | Live coding session

preview_player
Показать описание
Here is the solution to "Populating Next Right Pointers in Each Node II" leetcode question. Hope you have a great time going through it.

🎉 Chapters
0:00 Introduction
1:00 Links
3:30 Algorithm walkthrough
3:30 Coding it up

🔥🔥🔥🔥👇👇👇 For discussion/feedback/humour/doubts/new openings

👉 Solutions

🔥🔥🔥🔥👇👇👇 For discussion/feedback/humour/doubts/new openings

🔴 Checkout the series: 🔥🔥🔥

🔥🔥🔥 Leetcode Monthly Contest Playlist

PS : Please increase the speed to 1.25X
Рекомендации по теме
Комментарии
Автор

Space complexity will not be O(N) with the above solution Sir

anupriyagola
Автор

follow up question - constant extra space ?

alphadrones
Автор

class Solution {
public:
Node* connect(Node* root) {
if (root ==NULL) {
return NULL;
}

queue<Node*> q;
q.push(root);

while (!q.empty()) {
int levelSize = q.size();
Node* prev = NULL;

for (int i = 0; i < levelSize; i++) {
Node* current = q.front();
q.pop();

current->next=prev;

prev = current;



if (current->right) {
q.push(current->right);
q.push(current->left);
}
}
}

return root;
}
};
why its giving runtime error

anonymousanonymous
Автор

Bhaiya can you solve 2035 from leetcode . And explain is the dp solution or the bs is more optimal

abhijitroy
join shbcf.ru