Find the Town Judge | Graph practice question | Leetcode 997 | Degree of Graph Hello world Playlist

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ม.ค. 2025

ความคิดเห็น • 68

  • @abhijeetsingh7321
    @abhijeetsingh7321 ปีที่แล้ว +3

    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

  • @nikhilaswal7324
    @nikhilaswal7324 2 ปีที่แล้ว +1

    Mere demag me ab dhang se ghus gaya sir, thanks ❤ lot🔥

  • @GAURAV-cy4hh
    @GAURAV-cy4hh ปีที่แล้ว +1

    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

  • @gokulnaathb2627
    @gokulnaathb2627 9 หลายเดือนก่อน

    Superb solution! Nice concept!

  • @ani68
    @ani68 2 ปีที่แล้ว +7

    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....

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 ปีที่แล้ว +3

      Amazing 🤩 i proud on your efforts 😊

    • @Apex_Alpha53
      @Apex_Alpha53 2 ปีที่แล้ว +2

      hn "everybody" must trust him wala part miss ho gya thha😅

  • @privicyismyth9958
    @privicyismyth9958 2 ปีที่แล้ว +3

    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

  • @shridharsarraf2188
    @shridharsarraf2188 3 ปีที่แล้ว +1

    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

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 3 ปีที่แล้ว +1

      bro, how you recognized graph questions ?? mene padha to samaj hi nahi aaaya graph use hoga ki nahi isme ???

    • @HelloWorldbyprince
      @HelloWorldbyprince  3 ปีที่แล้ว +1

      Thanks a lot buddy 😊
      Keep learning

    • @HelloWorldbyprince
      @HelloWorldbyprince  3 ปีที่แล้ว +1

      Thora time do aap questions practice me
      Khud pe khud samjh aa jayega relax

    • @ani68
      @ani68 2 ปีที่แล้ว +2

      @@PIYUSH-lz1zq mostly jaha pe 1.....n diya rehta hai waha pe graph lag sakta hai...not necessarily but

  • @foisalchowdhury6573
    @foisalchowdhury6573 ปีที่แล้ว

    Oh what a explanation brother.❤❤❤❤

  • @sumitbaghel9987
    @sumitbaghel9987 2 ปีที่แล้ว +1

    Great vid!😀

  • @oqant0424
    @oqant0424 2 ปีที่แล้ว

    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

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 ปีที่แล้ว +1

      tum sach me bhut mehnat karte ho dost good

    • @oqant0424
      @oqant0424 2 ปีที่แล้ว

      @@HelloWorldbyprince thanks a lot bhaiya❤

  • @mancysaxena6869
    @mancysaxena6869 ปีที่แล้ว

    How does the second case handle if the judge points to itself and others point to it also
    that will also be n-1

  • @praveengupta0972
    @praveengupta0972 2 ปีที่แล้ว +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;

  • @divyansh1391
    @divyansh1391 2 ปีที่แล้ว

    86 / 92 test cases passed.

  • @rahulgupta2322
    @rahulgupta2322 3 ปีที่แล้ว +1

    great video

  • @Coder_DhruvArora
    @Coder_DhruvArora 2 ปีที่แล้ว +1

    Bhaiya Brute force se kiya
    Pehle wrong answer aya
    Fir ek mistake find ki and Accepted
    But O(n^2) chala gaya 🥲

  • @himanshusahu6879
    @himanshusahu6879 ปีที่แล้ว +1

    nice

  • @manojgollapelli9856
    @manojgollapelli9856 2 ปีที่แล้ว

    Great vid!

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 ปีที่แล้ว +1

      Thanks a ton Manoj
      Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @ogbuddha7835
    @ogbuddha7835 3 ปีที่แล้ว

    Bhaiya Hashing ke videos ka agar PPT mil jata to bhoy help ho jati revision m 🙏

  • @satyamsrivastava1871
    @satyamsrivastava1871 2 ปีที่แล้ว +1

    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

  • @DeepakKumar-oz5ky
    @DeepakKumar-oz5ky 6 หลายเดือนก่อน

    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

  • @shaantyagi2187
    @shaantyagi2187 2 ปีที่แล้ว

  • @rahulgautam6387
    @rahulgautam6387 2 ปีที่แล้ว

    amazing solution

  • @neerajgarg9096
    @neerajgarg9096 2 ปีที่แล้ว +2

    *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

  • @oqant0424
    @oqant0424 2 ปีที่แล้ว

    7/32 done (2.11.22)

  • @divyansh1391
    @divyansh1391 2 ปีที่แล้ว

    54 / 92 test cases passed. copied from leetcode

  • @inderjeetsingh797
    @inderjeetsingh797 ปีที่แล้ว

    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;
    }
    };

  • @abhisheksamboddu6580
    @abhisheksamboddu6580 2 ปีที่แล้ว

    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

  • @birattamrajak3948
    @birattamrajak3948 ปีที่แล้ว +1

    ye line samaj nei aaya , please ek bar bol dijiya
    for(auto x : trust){
    data[x[0]]--;
    data[x[1]]++;
    }

  • @cr7johnChan
    @cr7johnChan 2 ปีที่แล้ว +1

    playlist share kar dya

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 ปีที่แล้ว +1

      Thanks Randeep
      thanks a ton
      ab channel v share kar do

    • @cr7johnChan
      @cr7johnChan 2 ปีที่แล้ว

      @@HelloWorldbyprince ok bhai

  • @ravindrayadav6103
    @ravindrayadav6103 ปีที่แล้ว

    I solved this qs using map ,code- class Solution {
    public:
    int findJudge(int n, vector& trust) {
    unordered_mapmp;
    for(int i=0;i

  • @aakashtyagi3376
    @aakashtyagi3376 6 หลายเดือนก่อน

    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

  • @TarunKEE
    @TarunKEE 2 ปีที่แล้ว

    phodo

  • @zhunzargulhane6741
    @zhunzargulhane6741 ปีที่แล้ว

    This guy is simply irritating, initial 2 mins literally wasted on useless advice.

  • @dibakarmandal2148
    @dibakarmandal2148 2 ปีที่แล้ว

    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
    🙂

  • @subhankarraja2268
    @subhankarraja2268 ปีที่แล้ว

    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;
    }

  • @divyansh1391
    @divyansh1391 2 ปีที่แล้ว +2

    91 / 92 test cases passed.