Maximum Number of K-Divisible Components | Leetcode 2872 | DFS | Bi Weekly Contest 114

  Рет қаралды 524

Tech Courses

Tech Courses

Күн бұрын

Пікірлер: 10
@thisismr900
@thisismr900 Жыл бұрын
Reallly , my search for a good and clear explanation ends here! Thank u 900!
@techcourses4u
@techcourses4u Жыл бұрын
Thanks and Welcome 3000!!!
@552sonalprasad9
@552sonalprasad9 Жыл бұрын
I love your explanation.. keep making videos . I really need institutions of each question deeply .
@techcourses4u
@techcourses4u Жыл бұрын
Thank you, I will
@rajivkoiri1
@rajivkoiri1 20 күн бұрын
Seedhi baat no bakwas😀 Good one bro 👌
@techcourses4u
@techcourses4u 20 күн бұрын
Thanks!!!
@thisismr900
@thisismr900 Жыл бұрын
I have a doubt Here vectoradj(n) see,a node can have multiple neighbours How can u track them using this vector
@thisismr900
@thisismr900 Жыл бұрын
Shouldnt it be vectoradj
@techcourses4u
@techcourses4u Жыл бұрын
vector adj[n]; This is syntax for array of vectors. This representation means an array of size n whose each element is a vector. Like we have array of ints where each array element will store an integer. Here we have an array of vectors i.e. each element will store a vector (for multiple neighbours). Alternatively, you can think of it as a 2D vector where 1st dimension is fixed as n and second dimension is variable.
@thisismr900
@thisismr900 Жыл бұрын
class Solution { private: long long dfs( int currNode, int prevNode,int &splits,vector&adj,vector& values, int k){ long long nodeVal=values[currNode]; //visit the neighbours other than prevNode for(auto neighbour:adj[currNode]){ if(neighbour != prevNode) nodeVal+= dfs(neighbour, currNode,splits, adj, values, k); } if(nodeVal % k == 0){ splits++; return 0; } return nodeVal; } public: int maxKDivisibleComponents(int n, vector& edges, vector& values, int k) { vectoradj(n); for(auto e:edges){ adj[e[0]].push_back(e[1]); adj[e[1]].push_back(e[0]); } //run dfs from node 0 int splits=0; dfs(0,-1,splits,adj,values,k); return splits; } }; This works perfectly fine But with the syntax mentioned in video it gives error ,for obvious reasons@@techcourses4u
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Maximum Number of K Divisible Components | Leetcode
23:39
Ethos Typos
Рет қаралды 160
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 2,5 МЛН
Как стать ДЕЙСТВИТЕЛЬНО хорошим программистом
7:35
Бинарный происк
Рет қаралды 162 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН