Sliding Puzzle | Detailed for Beginners | Leetcode 773 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 127th Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good 2D Array BFS based problem : Sliding Puzzle | Detailed for Beginners | Leetcode 773 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Sliding Puzzle | Detailed for Beginners | Leetcode 773 | codestorywithMIK
Company Tags : Airbnb
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/2-D Array/Sliding Puzzle.cpp
Leetcode Link : https://leetcode.com/problems/sliding-puzzle/description
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
The solution uses Breadth-First Search (BFS) to solve the sliding puzzle problem. The idea is to treat each board configuration as a node in a graph and find the shortest path (minimum moves) from the initial board state to the target state ("123450").
Steps:
Convert the board to a string: The initial board configuration is converted into a string to facilitate easy comparison and manipulation.
Adjacency list for valid moves: A predefined map stores the valid moves for the empty slot (0), representing adjacent positions where the 0 can slide.
Use BFS for exploration: A queue is used to perform BFS, starting from the initial configuration. Each level of BFS corresponds to a single move.
Swap positions to generate new states: For each state, the adjacent configurations are generated by swapping 0 with its neighboring positions.
Track visited states: A Set is used to avoid revisiting configurations, ensuring efficiency.
Stop when the target is reached: If the target configuration is found during BFS, the number of moves (level) is returned.
Return -1 if unsolvable: If the BFS completes without finding the target, the puzzle is deemed unsolvable.
This approach ensures that all possible states are explored in the shortest path order, making it both optimal and efficient.
✨ Timelines✨
00:00 - Introduction
#MIK #mik #Mik
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik