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

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

Пікірлер: 37

  • @ARYANMITTAL
    @ARYANMITTAL Жыл бұрын

    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: kzread.info/dash/bejne/Z3aprbiMXbnUp9Y.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

    Жыл бұрын

    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

    Жыл бұрын

    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 = 0 and newcol { 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 Жыл бұрын

    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 Жыл бұрын

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

  • @tejuschaturvedi6234
    @tejuschaturvedi6234 Жыл бұрын

    excellent explanaton for such a tough question .

  • @anexocelisia9377
    @anexocelisia9377 Жыл бұрын

    was waiting

  • @jagratgupta8392
    @jagratgupta8392 Жыл бұрын

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

  • @sherlockjunior8612
    @sherlockjunior8612 Жыл бұрын

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

  • @hitengoyal5457
    @hitengoyal5457 Жыл бұрын

    Why can't we apply dijkstra algorithm?

  • @SurajYadav-py1do
    @SurajYadav-py1do Жыл бұрын

    amazing explanation bro

  • @beinghappy9223
    @beinghappy9223 Жыл бұрын

    Toughest question I faced so far Btw amazing explanation .

  • @Yashcolab
    @Yashcolab12 күн бұрын

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

  • @sahilyadav5662
    @sahilyadav5662 Жыл бұрын

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

  • @yugaanshgautam6893

    @yugaanshgautam6893

    Жыл бұрын

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

  • @pool477
    @pool477 Жыл бұрын

    Future striver

  • @ankurchaudhary924
    @ankurchaudhary924 Жыл бұрын

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

  • @animesh414
    @animesh414 Жыл бұрын

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

  • @your_daddy_mf
    @your_daddy_mf Жыл бұрын

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

  • @shlokjhunjhunwalakol
    @shlokjhunjhunwalakol Жыл бұрын

    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]

  • @CristianoRonaldo-ku1uz
    @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]

  • @shwetanshusood9450
    @shwetanshusood9450 Жыл бұрын

    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

  • @gyanaranjansahoo6258
    @gyanaranjansahoo6258 Жыл бұрын

    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 ?

  • @muskankashyap1776
    @muskankashyap1776 Жыл бұрын

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

  • @adityaanand799

    @adityaanand799

    8 күн бұрын

    yess it is failing on this

  • @adityaanand799

    @adityaanand799

    8 күн бұрын

    @ARYANMITTAL

  • @asthajain2511
    @asthajain2511 Жыл бұрын

    Cant we apply dfs here ??

  • @ARYANMITTAL

    @ARYANMITTAL

    Жыл бұрын

    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

    Жыл бұрын

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

  • @raunakkumar6144

    @raunakkumar6144

    Жыл бұрын

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

  • @koushikboddapalli4400
    @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 { for(int j = 0;j { char c = grid[i][j]; if(grid[i][j] == '@') { x = i; y = j; } if(grid[i][j]>='a' && grid[i][j]=0 && nx =0 && ny }; int steps = 0; while(!q.empty()) { int size = q.size(); for(int i = 0;i { int keys = q.front().first; int curr = q.front().second; q.pop(); if(keys == (1 = 'a' && c

  • @namanchandak1532
    @namanchandak1532 Жыл бұрын

    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

  • @parthpandey.
    @parthpandey.10 ай бұрын

    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 Жыл бұрын

    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 Жыл бұрын

    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 Жыл бұрын

    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 Жыл бұрын

    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]

Келесі