I paused the vid. And I almost done this. Question in my first attempt but a couple of test cases remain, then I start watching you and get a hint of indegree and Outdegree. Then I done this question
Done in the first attempt but with a little bit of higher complexity. After that done with O(n) time and space complexity, by taking hints from the video
Sir when I paused the video and tried myself..I got 87/92 test cases passed...got the mistake and realised it afterwards....after that ek hint mili indegree of a node ki then accepted ho gaya .....also trying the question after thinking before watching the video also helps to understand the video quickly....
best solution time complexity O(n) int findJudge(int n, vector& trust) { unordered_mapup; vector visited(n+1,0); for(auto temo:trust){ int a = temo[0]; int b =temo[1]; up[a]++; visited[b]++;
Bhaiya ye same question maine abhi do 3-4din pehle try kiya tha and I'm so happy i did it myself, still I'll watch this solution too😅. Ab dhire dhire Confidence aa rha hai
i coded...submission went wrong ...saw a hint from u...understood my mistake ....went back to the problem...and BOOM✨✨...my submission got accepted✌......all thanks to u bhaiya
*Bhaiya my method of doing this question* class Solution { public: int findJudge(int n, vector& trust) { vectorindegree(n+1,0); vectoroutdegree(n+1,0); for(int i=0; i
bhaiya my approach class Solution { class Data { int node; int ie; int oe; boolean visited; Data(int node, int ie, int oe, boolean visited) { this.node = node; this.ie = ie; this.oe = oe; this.visited = visited; } } public void bfs(ArrayList adj, Data[] arr, int source) { Queue q = new LinkedList(); q.add(source); arr[source].visited = true; while (!q.isEmpty()) { int node = q.poll(); for (int ele : adj.get(node)) { arr[node].oe += 1; arr[ele].ie += 1; if (!arr[ele].visited) { arr[ele].visited = true; q.add(ele); } } } } public int findJudge(int n, int[][] trust) { ArrayList adj = new ArrayList(); for (int i = 0; i < n + 1; i++) { adj.add(new ArrayList()); } for (int[] relation : trust) { int a = relation[0]; int b = relation[1]; adj.get(a).add(b); } Data[] arr = new Data[n + 1]; for (int i = 1; i
good explanation but it is not good implementation of graph except creating graph. here is my simple solution: def findJudge(n: int, trust: List[List[int]]) -> int: # Creating empty graph graph = {i:[] for i in range(1, n+1)} # creating Adjacency List for s, d in trust: graph[s].append(d) # probable index tmp = 0 # when a person doesn't trust anyone then its Adjacency List value will be zero for key,value in graph.items(): if len(value) == 0: tmp = key # Checking whether he is trusted by everybody for key,value in graph.items(): if key == tmp: continue elif tmp not in value: return -1
I paused the vid. And I almost done this. Question in my first attempt but a couple of test cases remain, then I start watching you and get a hint of indegree and Outdegree. Then I done this question
Mere demag me ab dhang se ghus gaya sir, thanks ❤ lot🔥
Done in the first attempt but with a little bit of higher complexity.
After that done with O(n) time and space complexity, by taking hints from the video
Superb solution! Nice concept!
Sir when I paused the video and tried myself..I got 87/92 test cases passed...got the mistake and realised it afterwards....after that ek hint mili indegree of a node ki then accepted ho gaya .....also trying the question after thinking before watching the video also helps to understand the video quickly....
Amazing 🤩 i proud on your efforts 😊
hn "everybody" must trust him wala part miss ho gya thha😅
best solution time complexity O(n)
int findJudge(int n, vector& trust) {
unordered_mapup;
vector visited(n+1,0);
for(auto temo:trust){
int a = temo[0];
int b =temo[1];
up[a]++;
visited[b]++;
}
for(int i=1;i
Bhaiya ye same question maine abhi do 3-4din pehle try kiya tha and I'm so happy i did it myself, still I'll watch this solution too😅. Ab dhire dhire Confidence aa rha hai
bro, how you recognized graph questions ?? mene padha to samaj hi nahi aaaya graph use hoga ki nahi isme ???
Thanks a lot buddy 😊
Keep learning
Thora time do aap questions practice me
Khud pe khud samjh aa jayega relax
@@PIYUSH-lz1zq mostly jaha pe 1.....n diya rehta hai waha pe graph lag sakta hai...not necessarily but
Oh what a explanation brother.❤❤❤❤
Thanks a lot
Great vid!😀
Thanks! 😁
i coded...submission went wrong ...saw a hint from u...understood my mistake ....went back to the problem...and BOOM✨✨...my
submission got accepted✌......all thanks to u bhaiya
tum sach me bhut mehnat karte ho dost good
@@HelloWorldbyprince thanks a lot bhaiya❤
How does the second case handle if the judge points to itself and others point to it also
that will also be n-1
i do this using hashing:-
if(trust.size()==0 && n==1) return 1;
unordered_mapmp;
for(auto i:trust){
mp[i[1]].push_back(i[0]);
}
int ans=-1;
for(auto i:mp){
if(i.second.size()==n-1) ans=i.first;
}
for(auto i:mp){
for(auto j:i.second){
if(j==ans && i.first!=ans) return -1;
}
}
return ans;
wahh yaar ekdum sahi hai mast
86 / 92 test cases passed.
great video
Glad you like my videos
Bhaiya Brute force se kiya
Pehle wrong answer aya
Fir ek mistake find ki and Accepted
But O(n^2) chala gaya 🥲
nice
Thanks a lot
Great vid!
Thanks a ton Manoj
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
Bhaiya Hashing ke videos ka agar PPT mil jata to bhoy help ho jati revision m 🙏
bhaiya ye data[x[i]]++ ek barr thoda sa explation kr dete wo map me jab asa use hota hai toh smj gya hua pr vector wala thoda sa
bahiya main adjList se bnaya or jis adjList k index k vector ka size ==0 hoga us index ko return kr denege but 87/92 test case he solve ho paya
thanks bro
amazing solution
*Bhaiya my method of doing this question*
class Solution {
public:
int findJudge(int n, vector& trust) {
vectorindegree(n+1,0);
vectoroutdegree(n+1,0);
for(int i=0; i
7/32 done (2.11.22)
keep learning
54 / 92 test cases passed. copied from leetcode
class Solution {
public:
int findJudge(int n, vector& trust) {
if(n==1)
return 1;
unordered_set s;
unordered_map mp;
for(int i=0;ifirst;
int b=itr->second;
if(b==n-1)
return a;
}
return -1;
}
};
amazing good work
class Solution {
public:
int findJudge(int n, vector& trust) {
vector adj(n+1);
for(auto i: trust){
adj[i[0]].push_back(i[1]);
}
unordered_map mp;
for(int i=0;i
Thanks bro for the love and support
ye line samaj nei aaya , please ek bar bol dijiya
for(auto x : trust){
data[x[0]]--;
data[x[1]]++;
}
playlist share kar dya
Thanks Randeep
thanks a ton
ab channel v share kar do
@@HelloWorldbyprince ok bhai
I solved this qs using map ,code- class Solution {
public:
int findJudge(int n, vector& trust) {
unordered_mapmp;
for(int i=0;i
Amazing
bhaiya my approach
class Solution {
class Data {
int node;
int ie;
int oe;
boolean visited;
Data(int node, int ie, int oe, boolean visited) {
this.node = node;
this.ie = ie;
this.oe = oe;
this.visited = visited;
}
}
public void bfs(ArrayList adj, Data[] arr, int source) {
Queue q = new LinkedList();
q.add(source);
arr[source].visited = true;
while (!q.isEmpty()) {
int node = q.poll();
for (int ele : adj.get(node)) {
arr[node].oe += 1;
arr[ele].ie += 1;
if (!arr[ele].visited) {
arr[ele].visited = true;
q.add(ele);
}
}
}
}
public int findJudge(int n, int[][] trust) {
ArrayList adj = new ArrayList();
for (int i = 0; i < n + 1; i++) {
adj.add(new ArrayList());
}
for (int[] relation : trust) {
int a = relation[0];
int b = relation[1];
adj.get(a).add(b);
}
Data[] arr = new Data[n + 1];
for (int i = 1; i
Amazing
phodo
Yo
This guy is simply irritating, initial 2 mins literally wasted on useless advice.
🥲
good explanation but it is not good implementation of graph except creating graph. here is my simple solution:
def findJudge(n: int, trust: List[List[int]]) -> int:
# Creating empty graph
graph = {i:[] for i in range(1, n+1)}
# creating Adjacency List
for s, d in trust:
graph[s].append(d)
# probable index
tmp = 0
# when a person doesn't trust anyone then its Adjacency List value will be zero
for key,value in graph.items():
if len(value) == 0:
tmp = key
# Checking whether he is trusted by everybody
for key,value in graph.items():
if key == tmp:
continue
elif tmp not in value:
return -1
return tmp
🙂
nice work Good
int findJudge(int n, vector& trust) {
if(n==1) return 1;
unordered_mapmp;
for(int i=0;isecond==n-1)
{
return i->first;
}
}
return -1;
}
nice work
91 / 92 test cases passed.