This video explains how to solve the LeetCode BiWeekly Contest 181 Problem 3: Count Connected Subgraphs with Even Node Sum. The problem requires counting non-empty subsets of nodes in an undirected graph where the induced subgraph is connected and the sum of node values (0 or 1) is even. The solution uses backtracking with DFS to explore all possible subsets, maintaining a visited array and current sum. For each subset, the algorithm checks connectivity using BFS/DFS and verifies if the sum is even before incrementing the count. The approach involves generating all subsets, checking connectivity by traversing only nodes within the subset, and validating the even sum condition.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
LeetCode BiWeekly Contest 181 Live ExplanationAdded:
Yes. Okay. Uh I think we can start with the explanation of this bio contest. So first let me know how many of you got the error.
So when I was registering for this contest, I couldn't able to register for this contest, right?
I couldn't able to uh register for this contest.
It asked me for verifying the mobile number, but it couldn't uh the lead couldn't give me the mail, send me the mail.
And after uh after not being available uh I I got the mail but it has expired.
It has been expired.
So I think we are good to go.
Provide a better Okay.
Okay. So we are uh I think we can start with the first problem in today's bi-weekly contest 181. Right. Let us see what is given in the problem. Valid digit number. You are given an integer n and a digit x. A number is considered a valid if you know I haven't solved this yet because I couldn't register for this contest.
uh it g me an error. So now let us see what uh how we can solve this further. A number is considered valid if it contains at least one occurrence of digit x and it does not start with digit x. All right? So it should have at least one occurrence and it should not be it should not be having that digit uh the digit should not be at the first place of the uh given integer n return true if n is valid otherwise return false. This is a simple problem 101.
Only if you know the uh standard template library you can you can solve this in 1 minute. N is equal to 1 minute.
N is equal to 1 and the digit x we are given with is 0. Now the first one the first character is not equal to zero. I have two character. I have the other two characters or the digit digits. Now from this even if I have even if I have one a digit which is equal to x which is equal to x then return true then return true. I'm saying this as a character. Why? Because I want to change this I want to change this to a string, right?
So if I change that to a string, then it would be easier. Then I'll be searching for digit x from from the uh index one. All right. So let us see what are the constants. I have uh seen the example first example and also I have seen the description. Let us look at the constants. So the constants are n can be till 1 e5 right and the x can be I know 0 to 9 inclusive. So what I'm thinking here is convert the convert the just a minute. Hello bro, just came here. Couldn't do the last two questions. Yeah, bro. Uh, how many of you got it uh to register for the contest? Even I couldn't register for the contest, right?
I I saw the problems. I saw the problems from my friend's uh laptop, but I couldn't register for this contest. How many of you have registered and gave this contest?
So while I was registering for this contest uh it asked me to verify my uh mobile number. So it said it will be giving me a mail which has a confirmation code to verify my email ID but you know I didn't get the verification code. So that's why it couldn't register for this contest even did you register for this contest?
Please let me know. So the convert the integer n integer n to a string or without even converting you can also get the remainder by with a for loop but but I but I prefer to convert it to a string so that with only one for loop it could be easier right we'll also look at that approach but let us see can we solve this using you know converting uh converting it into a string. So convert the integer n to a string. Then I start for both today and tomorrow. But for tomorrow I had to verify through but I opted for. Okay. WhatsApp. Okay.
Good bro.
Uh you made a good decision by registering for today and tomorrow's contest. All the best for the tomorrow's contest. And let me know what is your uh rank today in the ranking. So let us go to the problem. Okay. Right. So I'm just uh this is an easy problem. If you if you are a a speed typer, if you can type speedly, you can just solve this in 1 minute. If you have solved more than like if you knew DSA from one year, you can solve this in one minute. Right? So this was quite easy. Convert the integer n to a string. Then check from index one from index one if there is a digit equal to x equal to x. Let me tell you for i = 1 i is less than n. What is n here? No, I cannot use a n here. Why? Because we are given with the function with n and x. So let me say that as s dot size.
We are converting the integer n to a string s. Right? So I'll just take it as I equal 1 i is less than s dot size i ++.
Now if this character or the number is equal to the uh the digit is equal to x. So s of i if it is equal to no. If you see here s of i is still a character. I need to make it into a number. Then only I can make sure I would compare it with the digit x. Right? So s of 5 minus 0 will give me a number which I'll compare it with the x. Then if it is true. So if it is true then we got it like the the two things which they have mentioned right here.
X should be should be present at least once.
At least once.
And X should not be should not be at the starting position at the first position or index zero.
First position or index zero.
index 0 right so if s of i minus 0 is equal to x then return true if not I'll check everything and and I would return false there itself so let us code this firstly let's take a string string s is equal to two string two string end now around 7900. My current rating character is like uh this total sun contest given 15 is okay, 1500, 1400 14 15 but now I think it will decrease. Yeah.
So many of the people have solved I guess many of the people was uh were easy and was able to solve the first two problems. So if you have even solved it, you have to solve it. Uh might be under like like it's not possible but uh you need to be a good at typing not typing actually you need to be good at logic first. typing it uh it doesn't matter right if you got the logic in just one minute and if it takes you to uh uh give the whole code for 2 minutes then it would be three or at least like in 15 minutes you need to be have solved the first two problems right so I think then it would be a good one but there are many people uh this is competition Right? There are many people who got solve this in less than you know in less than uh less minutes. Right? So I think I think uh it I think we also have to be more into third and fourth, right? It it won't be it would be greedy would be DT or it would be graphs but but these are the these all are the hardest uh things right okay in second question Kumar Rahak Krishna okay bro yeah yeah that's a good recommendation you are recommending for the YouTube live stream or you are recommening ing for the for the people who are attending the college. In second question, I use uh I use binary search for finding the finding the peak element. Okay, that's good to unbroke. Sepumar, Tari, but four are not able to solve.
Okay, let us see what uh let us see let us discuss about the third but second didn't read me and I got the penalty because I forgot data type for us saying okay to be long long instead of in I made this instead hello Kumar bro thank you thank you for thank you sir uh attending the live session so we'll be solving the first and second problems in uh you firstly so I got this string for int i = 1 i is less than s dot size i ++ so if s of i - z if it is equal to x then return true if not we'll return false let me know why for the second problem you have used a binary search someone said that they have used a binary search okay we got a wrong Answer 23 2x = 2 i is less than s dot size. I = 1 i is less than s dot size. Okay. S of i -0. Let me put this in brackets.
No, we got around uh again false. But it uh expected was false.
The number starts with two which okay?
Okay. Okay.
If uh if s of 0 is equal to uh s of 0 my s0 is equal to x then we will return false.
So there is a subtail error which I have done. So the first character should not be should not be x right. So the first uh first number or the first digit should not be x. So let's go with this one. Compare sums of bonic parts. All right. So let okay you are given a bonic uh array nums of length n split the array into two parts ascending part from index zero to the peak element inclusive descending part from the peak element to index n minus one inclusive in second no need to do bs because it was strictly increasing and then strictly decreasing just use simple yeah I also thought about the same I think uh I think your name is Akash right just a winner I know uh uh sorry if I made a mistake if I forgot but I uh I remember your name as Akash so descending part from the peak element to index n minus one okay the peak element belongs to both parts okay return so peak element will be on the both the parts zero if the sum of ascending part is related One if sum of descending participator minus one if both sums are equal. Note a botonic array is an array is uh that is strictly increasing up to a single peak element and then strictly decreasing. Okay. An array is set to be strictly increasing if each element is strictly greater than its previous one.
Um, did you create a hashmap of mine in your brain or what? How did you remember? That's a good great great comment. A cash bro no hash right so okay I remember names clearly okay right and array is said to be strictly decreasing if each element is strictly small. I think you already knew what is strictly increasing and strictly decreasing, right? Okay. Now let us see with 1 3 2 1 1 and 3 these are strictly increasing and then 3 to 1 these are strictly decreasing. Right? 1 and 3 are strictly increasing. 3 to 1 are strictly decreasing. Right? So I think we have uh we can we can look at the second example. 2 4 5 and 5 2 right 1 2 4 and then a three and we can write these conditions when we need to return 0 1 or m. So the first thing in the second problem is this.
So there is a peak element there will be a peak element and there is this array.
I need to find the peak element. Then I'll find this sum and I'll find this sum. Then as Akashbra as you said there will be ascending sum and also descending sum and thank you for saying me there is a a runtime error for not using long long right so it it will be helpful for me I didn't this is the first time I'm giving this there are no submissions of this problem I'm seeing this problem right okay I'm solving this for the first time so I need a peak so how do I get this as the peak So 1 3 5 7 10 then I would be having like 3 2 and then 1. So when I got at three, excuse me, when I got at three from seven and then 10 from 7 and then 10 array sorry nums of I is greater than nums of I minus one the nums of I the current element is greater than the previous element. Right? Now when I come to here three and then 10 nums of I here nums of I here is lesser than nums of I minus one there will be only one element like this one element uh from this uh left side right so when I got that that's where my peak element is so to find peak PE to find peak L peak index let us take it as index right so for I equ=0 I is less than N I ++ if nums of I if it is lesser than nums of I -1 then I'll make the peak as I minus one right the peak element as I minus one.
But if you see I'm checking I minus one when I is equal to Z. It's not possible.
Uh so let's say I is equal to 1. Now I got the peak element then I will break there itself. Why? Because why? Because if I say nums of I is lesser than nums of I mean the current element is lesser than the previous element then I would get this element as the peak. In fourth one, I could have used uh brute force but I then stopped you doing it cuz I I thought it will give me runtime error but my feeling was like it can only be solved using segmentry algorithm. Can you please tell? Yeah, segment you know I I think I think I need to make some work on the segment uh segment and fen victory and there are some algorithms I need to work on finictory segment yeah so let us discuss about the fourth problem right so we'll go to the problem once we uh once we complete the second problem we'll go to the third and fourth so I'll take the ascending sum. Ascending sum is equal to Z. Descending sum is equal to Z. Now again for I equ=0 I is less than or equal to peak I ++. Then I have ascending sum plus is equal to months of I. Then for I is equal to P I is less than N I ++ descending sum plus is equal to nums of I right so let us go here uh let's write int n is equal to nums dot size no I is = 1 i is less than n I'm finding for the peak if if nums of i is lesser than nums of i minus one then we need to break but before breaking let the peak is peak uh index is equal to peak index is equal to i minus one i minus one right so I need to initialize int peak is = minus1 Okay. Okay. Okay.
Now for int i=0 i is less than or equal to peak i + plus ascending sum. We need to also uh initialize it nums of i. Then the same thing here where we have this as n then we have it as peak then we have descending.
sum right so long long ascending sum is equal to zero descending sum is equal to zero right now we have this conditions so if ascending sum ascending sum is if the ascending part is greater is greater than descending sum okay it's n s if it is greater and we will return zero. Else if descending part is greater if descending sum is greater than ascending sum then will greater else will return minus one that's it I think let us okay let me submit it and okay let us go to the third problem right so we'll just return it count connected okay this is also a hard problem, right? Count connected subgraphs with even node sum. You are given an undirected graph with nodes labeled from 0 to n minus one. So we are given with an unirect graph. So there is there are bool uh a and c peak variable. Okay.
Okay. I didn't get you across by using a bold encarable.
Okay. You are given an undirected graph with n. Okay. Uh note I has a value of nums I which is either zero or one.
Okay. The edges of the graphs are given by 2D array edges where edges of i is vi.
an edge between node ui and vi for a non- empty subset s of nodes in the graph. We consider the induced uh induced subgraph of s generated as follows. We keep only the nodes in s. We give only the edges whose two end points are both in s. Okay.
given an integer representing the number of non subsets s of nodes in the graph subscript the induced subgraph of s is connected the sum of node values in s should be even so that's the point the first thing we need to have so uh the previous chart is of the previous previous problem okay so I think it's the first problem I think you're talking about but Let's talk about the third problem which is quite interesting. So we are given with a graph.
We have some edges here.
All right. Okay.
Now the edges of the graphs are okay. We have connections. Okay. There are some connections. For a non-MPT subset S of nodes in the graph, we consider the induced subgraph of S generated as follows.
Okay, we also have a subgraph. We keep only the nodes in S. We keep only the edges whose two end points are both in S. Okay, let us see what's happening. I am quite confused with this. We keep only the nodes in S. We keep only the edges whose two end points are both in S in an integer representing the number of non- empty subset S of nodes in the graph such that the induced subgraph of S is connected.
Okay. We keep only the nodes only the edges with two end points.
Okay.
Okay. The induced subgr of S is connected sum of node values in S is even.
Okay, let me tell you uh I couldn't solve that question but like I thought of using connected component or disjoint set or set unit. Okay, let us see 1 0 1 nums is equal to 1 0 1. So 0 1 and then two edges is equal to 0 1 1 2. Let us have this.
Let us see. I have three nodes 0 1 and then two. Now I have 1 0 1 nums is equal to 1 0 1. I have 01 as a connection and 1 2 as a connection. Now uh there is an output of two. That means I'm quite having a okay let us see by looking at the examples. I think we need a greater example. But he doesn't have any greater examples. All edges are distinct.
Okay. Edges of I. So all edges are distinct. Okay.
Edge. Okay. For a node for a non empty subset as of nodes in the graph we consider. So I think it might be having a set union.
something like that.
Okay. We consider the induced subgraph of S generated as follows. We keep only the nodes in S. Keep only the edges whose two end points are both in S.
Okay. Non-MPT subset S of nodes in the graph. tested the induced subgraph of S generated induced let me say that as induced sub graph S as also keep only the nodes in S nodes in S we keep only the edges these two end points edges whose end points whose end points are in S. Let me tell you, let me tell you if there is three and then four.
Right? Now S is having one and then two. Right? Now induced subgraph will have nodes in S. I think this problem description can be quite misleading. They could have simply said find subsets of graph where all nodes in that subset are connected and total sum of their node value is even. Okay.
Are you sure Akash?
Is that a clear description? Let me uh I think there is no count connected subgraph with even nodes.
Let me copy it.
Go to the problems count.
Okay.
And this one 391.
Okay. Let us go to this discussions.
The number of cheaters on this. Okay.
58% acceptance.
No. No way. There will be 58% gang. Congrats me. This question is completed by me and the choose it. Let's go. Thanks lead code. You made my day.
What? This twostep verification got me out of the contest. Okay. And one verification issues. Yes. I couldn't even upload you. It's just simple recussion plus backtracking due to use concept.
That's why it's start position not fourth one as request was to to do backtracking in this I tried backtracking plus order set either DFS or BFS not that hard. Okay. But there I think there are less brute force. Okay. I think my approach is very bad.
I think there is all just tested I think. Yeah, I think it's okay.
uh they could have said the subsets of graphs where all nodes in the subset are like connected and total sum of their node value is even okay so we are saying that subset of these graphs where the sum is even how many how many subsets are there in this graph where the sum is even right I think I think DP I I think there will be no DP like this right I don't think of any DP here how can we go with is I think if you have four then go with three again right might be going with three and then if I have another another like seven so so to make two to get an even we need two events and two odds right two events odd or two odds that's it nothing much um so so if I start with every number subset I think it needs to be character but it's quite hectic let me go with the top okay Enumerate all subsets with bit mass.
Can we enumerate with bit mass? Let let us okay. Okay. I got an idea here.
So imagine we are having I think like if we have multiple components then the answer will be like component one plus answer of component two. Okay, master of component three. Okay, let us see.
But if you if you think, let me tell you one thing like imagine I have 1 3 2 Okay.
0 1 2 3 4 5. Now there will be subsets.
Uh the I can easily generate can easily generate easily generate subsets but the problem is how do you make sure the subsets are connected that's where I'm getting an uh you know a doubt that are this subset is connected or not or I Yes.
I z and why did they give us as 0 or one?
Okay.
We consider the induced subgraph of as we keep only the n we keep value of nums of i.
Okay. Node i has a value of nums i which is either zero or one. Okay. the edges of the graph be given by so I was thinking of like iterating through edges and then distress union approach okay but I think where where we can use the disjoint set union might be like when we need to find the parent parent of the edge sorry parent of the node but I think there is no need of using uh finding the parent of the node which we are right.
I think there is some DFS or DFS approach.
Okay. But let us see.
Let let me tell you one thing.
Let me tell you this simply. One and then I have a zero and then I have a one and then I have a zero and then one and then zero and then one and then one then a zero. Let me tell you here.
I think okay let let me tell you this is like having some uh indices indices I 0 1 2 3 4 5 6 7 Y let me tell you I'll be having a visited okay sorry a visited array which will be having 0 1 2 3 4 5 6 7 and then write now let me tell you I I haven't looked into zero so what I would do I'll go to this index where I have a zero now it is having one as value if you see one as the value then I'll mark it as I'll mark it as visited but before that here my sum will be one right so zero is visited. Now I'll go and see what are all the adjacent nodes where I'll have right. So I have an adjacent node which is of two right. So while I am uh creating these uh nodes or the graphs I would create it with with indices right that's what they give 0 and 1 one and two I would create it with indices now what I I will do is every time I need to go and check with numbers of I is this so okay let me write it again let me write it again let me rewrite it.
So instead I can just take this make a copy of this.
Okay.
This zero I need to remove this one.
There is this one.
like exploring the subsets using DFS like with maintaining the previous sum and increasing the answer gradually.
Yes. Yes. Go. I'm thinking of it. I don't know whether I'm correct or wrong but let me try it first.
So I might get a wrong answer but let me try it first.
I think I hope you got it. So, uh 0 0 2 1 3 4 uh 4 y 5 6 and then seven. I have the values as 0.
Sorry, sorry. I have the values as 1 0 1 0. Yes, Arash, you are right about the thing. But let me let me go with the with the approach. I might get it wrong also, but let us try. Now I'm going with going with index zero. So there will be this listed array 0 1 2 3 4 5 6 7 8. Now I have at index zero it is visited and the sum which I have here is one. Now is it you know equal to uh is it even? No. Right. Now let me go to the adjacent uh adjacent node where I have zero. So 1 + 0 is still let me write it over 1 + 0 is still sum as 1. Right? Now I'll go here. Now I got two. Now if you see I if every time I get the sum as even I would mark the count I'll just increment the count right now uh 1 and uh 0 1 0 1 2 3 are already listed. Now I'll go here. I got zero. So 2 + 0 is still two but three is already then I would go track backtracking then I would go to four right. So when I go to four the sum is still zero. Sum is still two. 2 + 0 is still two. Right? So let me four. Now from four I would go to where I have a one. Then the sum would become three. Right? But y is already listed. Then I would go backtrack from four. Four is already wasted. Then go to the next adjacent node which is five. So five is having zero. So 3 + 0 is still three. No need to up upgrade our count.
Right now uh okay. Uh now let's go let's go with one thing. one thing.
Let's wait for one time.
Every time if you see let let me try backtrack. Let me stop here. 0 1 and two are right. So I have the sum as 1 + 1 which is two. Now let me stop here. Imagine imagine this as your subset. Now what are the elements here? 1 and 1 0 and 0 which is even right so why I'm not counting it that's a mistake right let me tell you let me go back here so from four uh from one I would go to three which is 0 so 2 + 0 is still two which is even so this is also valid right now the count would become two.
Now let me track back to here where I have one as node. But before let me mark three as visited. Now I have one from one I'll go to four. Right? So four if I add zero the sum will be two itself but the count will be incremented. Now from Ford, Ford is already listed. Then I can go to Y.
I can go to Y. So I have to go to Y and mark it as listed and sum is now three.
Will I increment the count? No. Why?
because the the subset which I have is having a sum of 1 2 and three which is not even so.
So that's why I would not increment the count but while I backtrack I need to minus this one from the sum. So I would make it as two.
That's it. That's a great backtracking problem.
Right? So I would go to two now.
Uh now let us see I I also have a doubt.
Why I cannot I I think I would not get this one.
So this is also a subset right.
Let us check whether we are going in the right direction or not.
So I would then I would go to this. So yeah it is already listed. Four is already listed. Five is already listed.
Now 2 + 0 is 2. Five is already listed.
So here the sum is even. Now I would increment the count to four.
Right? Now from five I can go to seven.
Right? So if I go to seven the sum will be three. Now then 70 is already listed.
So uh back I would go to five and also decrement the sum to two. Then I would go to six. Then it is marked as listed. Then six is having a sum a digit of 1. So 2 + 1 is three which is not even. So the count still remains four.
Right?
Now I have some doubt. Let me tell you what my doubt is.
Okay. I have uh nons.length is 13.
So 13 is I 13 13 is 169 which is quite less. But I think backtracking would give me more than because of it might because of NQ but let us see.
So if you if you clearly see I'm saying the count as four only if start if I start with zero.
Let me save another thing. What if I started with this index one? Then I would have this subset. But I have already have uh counted this subset previously when I started with zero here. Right? There is this error.
Uh let us see.
I already have this into the count, right?
Okay.
There might be another way where we can sol whether they include connected using DFS or BFS. Okay.
Okay.
That's a good one bro. The hints are quite useful.
Okay, that that's the first time in a hard problem I have got the hints useful. So they are just saying that use bit mask use bit mask and get all the all the subsets if the uh check if the subset if the subset is connected connected If so, check sum in if uh if the sum sum is even then increment the count else need to do anything. If so, check sum.
If it if the subset is connected, then check the sum. These two questions are good, right? Yeah, bro. the third problem. I just saw the third problem but I don't know what uh to do with the fourth one. I don't know. I didn't see that.
Is it the continuation of the no? Okay, it's smallest. But let us see. Let us go a Yes, this these are quite intuit uh we need we need to you know we need to solve it.
I didn't even thought about the bit mask thing and also getting all the subset that's why I think I always say that to you look at the constraints right so how do I generate all the subsets that's the first one how do I generate all the subset let me go to the question which I have so Okay, let me go to the question where generate all the subsets of an array.
Okay, let me get the code.
So in nums I can get all the Okay. So push back temp I have these subsets. So vector of vector in subsets because I think this manipulation is enough.
We can use this uh I speed 1 to i some power of 2. Let me tell you how we can get the subsets. Let me tell you one thing. Imagine imagine I have 0 1 and then two. So to take this I would have I I would go with zero. I would go to 1 2 3 4 5 6 7. I'll tell you what is this. How do I represent 0 0? How do I represent 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 If you see if you see here 0 0 take none I'm not taking anything right so that would be empty array from 0 1 2 or I let me tell you 1 2 3 it would be easier for you how I can get subsets 1 2 and then three right so it is an empty is this kind of brute force uh no bro it is just you know uh it is just like generating the subsets right let me tell you here I'll have it is one right where I have one at three where I have one at two where I have one and then one two and three where I have one at one I got all the subsets if you see 1a 3 then 1 comma 2 then 1a 2a 3 that's how I get all for every nums array no arish bro it is something like generate it is how can I uh how can I tell is like let me tell you with another example.
Imagine 1 2 3 4 is given then 0 there will be from 0 2 what is 2^ 3 2^ 3 is 2 into 2 into 2 which is 2 4 2 is nothing but y - 1 which is 7 right so 7 I would represent seven like this right so that's how I would get all these you know every number if I have a one I would get the element at that uh index right so okay I hope you got it uh you know if you have any doubts you can just message me in LinkedIn I'll be solving your doubts so vector vector of in subsets sets.
So wherever I have this subsets I'll be having instead of 10 I will be creating subset right I have the subsets now where n is equal to int int n is equal to n do size I have all the subsets now Okay, I have the subsets.
I need to know whether they are connected or not, right?
Is connected. There is also a problem.
Every time this connected graph release code it's not even in hard problem.
Okay, let us see let us see if a subset is connected or not.
Um let me let me do a DFS or BFS so that I can easily mark every every element which I have visited as which I have visited as true. Right? So what I would do is for auto auto subset in subsets is connected the subset is connected then I would get the sum right then I would just get the sub now what I'm um having uh here is is I'm having nums of J instead I just need J right I'm just having the indices now I have the indices if the subset is connected int sum is equal to Z or out of x in subset sum plus is equal to nums of x.
Now if this sum if sum mod 2 is equal to zero then just increment the count in the count is equal to zero return count at the end. Now I need to write the uh I have the indices right.
So count of subset with graph. So this graph will be a vector of vector of int graph for auto edge in edges graph of edge of zero dot push back edge of one. The same thing it is zero and then one.
Now B connected of vector of int not uh it will be changing right not the same thing subset and then graph vector vector of vector of int graph Right.
Right. Graph now in this I'll create visited array.
Visited.
Okay.
Uh if anything is unvisited then you would mark it as so so let me take another another vector of int where I have visited array right so vector of visitor for let me I have this subset right I have this graph I have this subset have the graph and I also have the subset how do I get through the BFS plus. So we'll be having a Q of N Q. Now Q dot uh subset uh I have this indices uh right have the indices.
Okay. dot push subset of zero.
distant uh dot push back push back subset of zero while this Q while this while this Q is not empty then then int node is equal to Q dot front Q dot pop transfer auto neighbor in graph of node. So every neighbor if it is not listed now I need to check I think now let us take it as set instead of push back in set if ne is not then what I would do if this if it is not visited then give dot push the neighbor.
Push the neighbor.
Uh then also have this as visitor. So visitor dot insert the neighbor. Is there anything which I have missed? Nothing.
Okay.
Vector of int array registered dot begin subset begin subet and return if subset is equal to step array.
Okay, let us check it runs or not compile error. I think we got something visited.
It's the dot find dotspine neighbor from this tag here.
Any idea of who have solved this? Right?
I have already solved this random instance binding to pointer of type vector int defined behavior.
If anyone is having any doubt till now we got an error while referencing vector of end.
Okay.
I think there is another step. Okay.
Even How can we solve this? Actually, this is okay.
So if you see graph of edge of zero is is where I'm getting an okay let me Okay.
Okay.
Visitor dot find neighbor. Okay. If it is visited if it is if it is contained or if it is found then we are visiting it again. No it's not like yeah that's the error.
Okay.
Okay. Step dot.
Let me tell you one thing. Imagine uh imagine we are having the components like 1 2 and then three and I have four.
Now the subset is having 1 2 3 and then four. Now what I'm saying neighbor in graph of node is if visited.
No I think there is an error here.
How can the I didn't do this.
So if I'm going Is this okay?
Let me tell you one thing here.
Imagine a like I have one uh it is not present in the subset even then our BFS goes there right so I need a check here only if the neighbor is in the subset right that's way So let me tell you if I have 1 2 3 and this three is having four and six and I have five here. Now the subset is now the subset is 1 2 5 and then three.
Now when I get to three, so I get to one, then I go to two and then I go to five and then I go to three.
But I have this four, I have this six, but they are not present in the subset.
So also need to check whether the neighbor is present in the subset or not. So set of int subset subset set right which contains subset dot begin subset dot end. So if subset set dot count enable and is not okay.
Yeah I hope it gets accepted.
So it is quite less but I think the food problem might goes with you are given an array integer array nums where nums is strictly increasing.
Okay.
You are also given a 2D integer array queries where queries of I is equal to L I R I K I.
For each query consider the subarray nums L I. If it is like this, we need to have uh a sequence of numbers a sub array and we need uh another query of K which is having with us uh with us. So it is definitely a what is segment problem right? Consider the subarrays uh from the infinite segments of all possible integers to head to to the infinite from possibly even integers. Remove all elements that appear in the subarray nums l i to r.
Okay. Find the k i smallest integer remaining in the sequence after the removals.
Okay.
So I think this needs to be done again tomorrow while we discuss the uh the weekly contest. So for today it is just here till here. So if you have any doubts please let me know the live chat. We're going to end this live session in just 5 minutes. So, thank you for everyone who have attended my live session.
Sorry everyone for not giving you the fourth uh problem explanation but due to the time constants I haven't gave you.
So thank you everyone for watching this live stream.
by Alex.
We're going to end the slide session just for so thank you for thank you everyone for joining this live stream.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











