Shortest Path to Get All Keys II BFS II Bit Manipulation II BFS Visit More than Once II Leetcode 864

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • In this video, I'll talk about how to solve Leetcode 864. Shortest Path to Get All Keys II BFS II Bit Manipulation II BFS Visit More than Once
    Checkout DSA-169 Series: • Aryan DSA-169 Series |...
    Problem Link: leetcode.com/problems/shortes...
    Code & Notes: drive.google.com/file/d/1OxGa...
    Let's Connect:
    📝Linkedin: / aryan-mittal-0077
    📸 Instagram: / aryan_mittal_007
    📱Telegram : t.me/aryan_mittal_group
    🤖 Github: github.com/aryan-0077
    🛍️ Products I use in Videos: (✨ Marked for Mostly requested Products)
    Main Camera (Canon 200D ii): amzn.to/41cfS5h
    Vlog Camera (iphone 13): amzn.to/42aOJRh
    Tripod for Lectures: amzn.to/3HMoloF
    Tripod for Vlogs: amzn.to/44wGL6L
    ✨Mic: amzn.to/41bj8gU
    Shadow Multi Colour Light: amzn.to/41bmIrq
    Main Light: amzn.to/3LF6BNb
    Tripod for Lights: amzn.to/3LFcQAt
    Softbox for Lights: amzn.to/42mHqWE
    ✨My Pen Tablet for Notes: amzn.to/44A61ZJ
    ✨New Tablet for Notes: amzn.to/44BjTDa
    Tablet Stand: amzn.to/3NMFIJR
    Power Bank: amzn.to/421yHsZ
    ✨USB Hub: amzn.to/3p8NGTf
    ✨HardDisk to store Lectures: amzn.to/3HKafEs
    ✨My Laptop: amzn.to/44w12ct
    ✨My Monitor: amzn.to/3LCG6YL
    My UPS: amzn.to/3Lydy2y
    My UPS old: amzn.to/3LXT0C3
    ✨My Mouse: amzn.to/3LYmJdY
    ✨My Keyboard: amzn.to/3NJs4ah
    Resources you can try:
    Learn Coding: • Complete RoadMap for C...
    🎥Channel Playlists
    🎥 Baap Graph Series - by Aryan: • Baap Graph Series - by...
    🎥Dynamic Programming: • Complete Dynamic Progr...
    🎥Bit Manipulation: • Complete BIT MANIPULAT...
    🎥Mathematics for DSA: • Complete Mathematics f...
    🎥Leetcode Top Interview Questions: • FAANG & Leetcode Inter...
    🎥Codeforces Problem B Ladder: • Complete PROBLEM B LAD...
    🎥Codeforces Problem C Ladder: • Codeforces PROBLEM C L...
    🎥Codeforces Problem D Ladder: • Complete PROBLEM D LAD...
    🎥 Top 150 Interview Questions: • Top 150 Interview Ques...
    🎥 Complete Array Problem Playlist: • Complete Array Intuit...
    🎥 Complete Binary Search Problem Playlist: • Complete Binary Search...
    🎥 Complete Stack Playlist: • Complete Stack & Queue...
    🎥 Complete Graph Problem Playlist: • Complete Graph Intuiti...
    🎥 Complete TREE Playlist: • Complete TREE Intuitio...
    🎥 Complete DP Problem Solving: • Complete DP Intuition ...
    🎥 Complete Linked List: • Complete Linked List I...
    🎥 Complete Greedy Problem Playlist: • Complete Greedy Intui...
    🎥 Complete Divide & Conquer Algorithm Playlist: • Complete Divide & Conq...
    🎥 Complete Trie Playlist: • Complete Trie Intuitio...
    🎥 Complete Mathematics & Number Theory Problems: • Complete Mathematics &...
    About Channel:
    We teach about how you can grow in life & educate about programming in Fun & Intuitional way.
    About Me:
    I am Aryan Mittal - a Software Engineer, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
    ✨ Timelines✨
    0:00 - Bakwas
    0:50 - Problem Explanation
    2:43 - Intuition Building
    15:28 - Logic Walkthrough + Code (+Bit Manipulation)
    31:40 - Complexity Analysis
    ✨ Hashtags ✨
    #programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Komentáře • 37

  • @ARYANMITTAL
    @ARYANMITTAL  Před rokem +5

    Do Comment, uptill where you guys were able to think for this problem & what you guys learned in today's Problem ❤!!
    Checkout DSA-169 Series: czcams.com/video/5BuKVS-Vnws/video.html
    Problem Link: leetcode.com/problems/shortest-path-to-get-all-keys/description/
    Code & Notes: drive.google.com/file/d/1OxGaZe2jH-lXo1ry7Ay0UN_MIBnrLyvE/view?usp=sharing

    • @GodOfFaith
      @GodOfFaith Před rokem

      hey aryan i wanna ask you something thats very off topic ,
      why don't you join google as an SDE ?
      i mean you can get referrals much easily as you are working in goldman sachs....
      your coding skills are so good....
      and thats why i was wondering.

    • @morrisonsempire9354
      @morrisonsempire9354 Před rokem +1

      Can you please explain this doubt in the while loop if i dont use that size loop and direcly doing the increment of steps during popoing the element as i generally do any of bfs kind of questions then it is giving wrong answer in first 2 test case why??
      while (!q.empty())
      {
      vector curr = q.front();
      q.pop();
      ++steps;
      if (curr[0] == (1 = 0 and newrow < n and newcol >= 0 and newcol < m)
      {
      char ch = grid[newrow][newcol];
      if (ch == '#')
      continue;
      if (ch >= 'a' and ch (ch - 'A') & 1) == 0)
      continue;
      if (!visit.count(to_string(keys) + " " + to_string(newrow) + " " + to_string(newcol)))
      {
      visit.insert(to_string(keys) + " " + to_string(newrow) + " " + to_string(newcol));
      q.push({keys, newrow, newcol});
      }
      }
      }
      }

  • @aryamanagarwal1977
    @aryamanagarwal1977 Před rokem +9

    Sir I saw your baap graph series and legit it was the best graph plyalist I have seen so far , and I was able to solve this question myself
    Great work sir
    BTW I am also from mnnit (cse)😅😅😅

  • @dewanshpatle9056
    @dewanshpatle9056 Před rokem +3

    man those jokes in middle are really awesome, you are a great explainer. Thanks for all the hardwork ❤.

  • @tejuschaturvedi6234
    @tejuschaturvedi6234 Před rokem +3

    excellent explanaton for such a tough question .

  • @anexocelisia9377
    @anexocelisia9377 Před rokem +5

    was waiting

  • @Yashcolab
    @Yashcolab Před 13 dny

    that 9:21 moment came and i was totally unprepared for it lmao
    XD

  • @jagratgupta8392
    @jagratgupta8392 Před rokem +1

    Very tough ques bhaiya 😅😅...got the intuition but solving and checking each and every thing was really confusing and tough ....you explained really well❤❤

  • @hitengoyal5457
    @hitengoyal5457 Před rokem +2

    Why can't we apply dijkstra algorithm?

  • @sherlockjunior8612
    @sherlockjunior8612 Před rokem +5

    Why is no one talking about what he says here: 9:18
    XD

  • @SurajYadav-py1do
    @SurajYadav-py1do Před rokem

    amazing explanation bro

  • @beinghappy9223
    @beinghappy9223 Před rokem

    Toughest question I faced so far
    Btw amazing explanation .

  • @sahilyadav5662
    @sahilyadav5662 Před rokem

    why you have used the loop for(int i=0;i

    • @yugaanshgautam6893
      @yugaanshgautam6893 Před rokem +1

      to update steps efficiently, you require one step to proceed to the next level in the graph.

  • @ankurchaudhary924
    @ankurchaudhary924 Před rokem +2

    Note::: that the goal is to obtain all the keys not to open all the locks.

  • @pool477
    @pool477 Před rokem +5

    Future striver

  • @animesh414
    @animesh414 Před rokem

    kya ham dfs se ye problem solve nhi kr skte kya ?

  • @your_daddy_mf
    @your_daddy_mf Před rokem

    Bhai khud kese karte ho ? Koi sheet follow kar rhe kya ? please reply

  • @CristianoRonaldo-ku1uz

    Can you help me with the code. Getting WA on TC-13 I think I have to do backtracking properly but not getting how to do it.
    class Solution {
    public:
    int dx[4] = {0,0,1,-1};
    int dy[4] = {1,-1,0,0};
    vector grids;
    multiset st;

    void help(vector&vp, multiset stcpy, int &i, int &j, int &ans,int sol,vector vis){
    if(vp[i][j]==INT_MAX){
    return;
    }
    if(vp[i][j]==INT_MIN && stcpy.find(grids[i][j]-'A')==stcpy.end()){
    return;
    }
    if(stcpy == st){
    ans = min(ans,sol);
    return;
    }
    vis[i][j] = 1;
    for(int l =0; l=0 && sti=0 && stj=0 && vp[sti][stj]

  • @shlokjhunjhunwalakol
    @shlokjhunjhunwalakol Před rokem

    Can anyone tell me why my code is giving tle 😭😭😭
    class Solution {
    private:
    bool isValid(vector& grid, int i, int j, int m, int n, vector& keys){
    if(i=n || grid[i][j]=='#')return false;
    if(grid[i][j]>='A' && grid[i][j]

  • @gyanaranjansahoo6258
    @gyanaranjansahoo6258 Před rokem

    if (c >= 'A' && c > (c - 'A')) & 1) == 0) {
    continue;
    }
    in this part can't we do ((1 >> (c - 'A')) & 1) == 0 insted of ((keys >> (c - 'A')) & 1) == 0 ?

  • @shwetanshusood9450
    @shwetanshusood9450 Před rokem

    Can you help me with this code.. i am not getting how to do it
    The general public often body shame the people who are obese or not beautiful as per their standard of weight. They do not even consider that it might be a medical condition for some people. Because of this, the people start doubting themselves and start cutting them off from the general discussions or the public places. To fight body shaming and spread awareness about the issue, an event is conducted in the city where people are participating and are ranked according to their weights from highest to lowest. The people with the same weights are ranked the same.
    There are N people who have already participated. The official has noted their weight and has ranked them. The problem is, he has fallen sick and there are still P people who are left to rank and participate. Considering this, you are expected to finish the process and provide the rank of the P people. Once the person is ranked, his weight is included in the category and the weight of the new person will have to consider this weight also to be ranked. To help you out, the new P people are organized in a queue in increasing order of their weights.
    Input Format
    The first line of input consists of two space-separated integers, N and P, number of people already ranked and number of people left to be ranked respectively.
    The second line of input consists of N space-separated integers arranged in decreasing order, representing the weight of the N people.
    The third line of input consists of P space-separated integers arranged in increasing order, representing the weight of the P people.
    Constraints
    1

  • @muskankashyap1776
    @muskankashyap1776 Před rokem +2

    code is failing at test case ["@...a",".###A","b.BCc"]..

  • @asthajain2511
    @asthajain2511 Před rokem +3

    Cant we apply dfs here ??

    • @ARYANMITTAL
      @ARYANMITTAL  Před rokem +4

      Nopes, forget keys, locks and obstacles, if i had asked you give me shortest path to reach from x1,y1 to x2, y2. How will you have solved it via DFS? It just traverse the path depth wise, thus only making sure that we reach that point, and not in shortest time/distance.

    • @anexocelisia9377
      @anexocelisia9377 Před rokem +1

      @@ARYANMITTAL can we apply bfs everytime we need to find the shortest path?

    • @raunakkumar6144
      @raunakkumar6144 Před rokem

      @@ARYANMITTALWe can use dfs with backtraking to solve it write ,yeah it will be exponential complexity ,but we can right?

  • @namanchandak1532
    @namanchandak1532 Před rokem +1

    What is the error in my code it is
    failing the below test case
    ["...#","a..@","#..#","b.#B",".##A"]
    class Solution {
    public:
    int n,m;
    int dfs(vector& grid,int i,int j,int lock,set&st,vector&dp)
    {
    if(i=m || grid[i][j]=='#')
    return 1e9;
    if(lock==0 )
    return 0;
    cout

  • @koushikboddapalli4400

    Whats wrong with this code...please figure it out... thanks in advance
    vector directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    int shortestPathAllKeys(vector& grid) {
    int n = grid.size();
    int m = grid[0].size();
    int x = -1,y = -1,max_len = -1;
    for(int i = 0;i < n;i++)
    {
    for(int j = 0;j < m;j++)
    {
    char c = grid[i][j];
    if(grid[i][j] == '@')
    {
    x = i;
    y = j;
    }
    if(grid[i][j]>='a' && grid[i][j]=0 && nx < n && ny>=0 && ny < m && grid[nx][ny]!='#');
    };

    int steps = 0;
    while(!q.empty())
    {
    int size = q.size();
    for(int i = 0;i < size;i++)
    {
    int keys = q.front().first;
    int curr = q.front().second;
    q.pop();

    if(keys == (1 = 'a' && c

  • @parthpandey.
    @parthpandey. Před 10 měsíci

    Don't take it the wrong way, but your explanations are often too lengthy, which can be boring for us. Additionally, it may seem like you are trying to come across as too smart. To be honest, if I were present there, I might have been tempted to express my frustration with a tight slap. I'm saying this because your video tends to irritate me.

  • @shlokjhunjhunwalakol
    @shlokjhunjhunwalakol Před rokem

    Can anyone tell me why my code is giving tle 😭😭😭
    class Solution {
    private:
    bool isValid(vector& grid, int i, int j, int m, int n, vector& keys){
    if(i=n || grid[i][j]=='#')return false;
    if(grid[i][j]>='A' && grid[i][j]

  • @shlokjhunjhunwalakol
    @shlokjhunjhunwalakol Před rokem

    Can anyone tell me why my code is giving tle 😭😭😭
    class Solution {
    private:
    bool isValid(vector& grid, int i, int j, int m, int n, vector& keys){
    if(i=n || grid[i][j]=='#')return false;
    if(grid[i][j]>='A' && grid[i][j]

  • @shlokjhunjhunwalakol
    @shlokjhunjhunwalakol Před rokem

    Can anyone tell me why my code is giving tle 😭😭😭
    class Solution {
    private:
    bool isValid(vector& grid, int i, int j, int m, int n, vector& keys){
    if(i=n || grid[i][j]=='#')return false;
    if(grid[i][j]>='A' && grid[i][j]

  • @shlokjhunjhunwalakol
    @shlokjhunjhunwalakol Před rokem

    Can anyone tell me why my code is giving tle 😭😭😭
    class Solution {
    private:
    bool isValid(vector& grid, int i, int j, int m, int n, vector& keys){
    if(i=n || grid[i][j]=='#')return false;
    if(grid[i][j]>='A' && grid[i][j]