{"id":"9f04d03b-3f5e-41d3-be80-c0c3582e6f0a","name":"Sliding Puzzle","description":"On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4 directionally adjacent number and swapping it.\r\nGiven the puzzle board, print the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, print -1.\r\n\r\nsolved state is : {{1,2,3},{4,5,0}}","inputFormat":"Each of next 2 lines contain 3 integer.","outputFormat":"Min number of moves required to achieve solved state.","constraints":"rows = 2\r\ncols = 3","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint slidingPuzzle(vector<vector<int>>&v1)\n{\n \n}\n\nint main()\n{\n vector<vector<int>> v1(2,vector<int>(3));\n for(int i=0;i<2;++i) \n for(int j=0;j<3;++j) cin>>v1[i][j];\n int ans=slidingPuzzle(v1);\n cout<<ans<<\"\\n\";\n return 0;\n}"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\nclass Main {\n public static void main(String[] args) throws NumberFormatException, IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n int[][] arr = new int[2][3];\n\n for (int i = 0; i < 2; i++) {\n String[] st = br.readLine().split(\" \");\n for (int j = 0; j < 3; j++) {\n arr[i][j] = Integer.parseInt(st[j]);\n }\n }\n\n System.out.println(slidingPuzzle(arr));\n }\n\n public static int slidingPuzzle(int[][] board) {\n \n\n }\n \n \n \n \n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1 2 3\r\n4 0 5","sampleOutput":"1\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"7e07fddf-83bd-421e-848f-118f1f29541c","name":"Graphs For Intermediate","slug":"graphs-for-intermediate-493","type":0},{"id":"0aae6f63-3fda-4909-b5f9-ac7e50a41462","name":"Sliding Puzzle","slug":"sliding-puzzle","type":1}],"next":{"id":"16bee40b-0879-49fa-8a2f-149721760d44","name":"Sliding Puzzle","type":0,"slug":"sliding-puzzle"},"prev":{"id":"b5e00a9d-f3c7-4931-b45d-89f95cefd266","name":"As Far From Land As Possible","type":3,"slug":"as-far-from-land-as-possible"}}}

Sliding Puzzle

On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4 directionally adjacent number and swapping it. Given the puzzle board, print the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, print -1. solved state is : {{1,2,3},{4,5,0}}

{"id":"9f04d03b-3f5e-41d3-be80-c0c3582e6f0a","name":"Sliding Puzzle","description":"On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4 directionally adjacent number and swapping it.\r\nGiven the puzzle board, print the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, print -1.\r\n\r\nsolved state is : {{1,2,3},{4,5,0}}","inputFormat":"Each of next 2 lines contain 3 integer.","outputFormat":"Min number of moves required to achieve solved state.","constraints":"rows = 2\r\ncols = 3","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint slidingPuzzle(vector<vector<int>>&v1)\n{\n \n}\n\nint main()\n{\n vector<vector<int>> v1(2,vector<int>(3));\n for(int i=0;i<2;++i) \n for(int j=0;j<3;++j) cin>>v1[i][j];\n int ans=slidingPuzzle(v1);\n cout<<ans<<\"\\n\";\n return 0;\n}"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\nclass Main {\n public static void main(String[] args) throws NumberFormatException, IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n int[][] arr = new int[2][3];\n\n for (int i = 0; i < 2; i++) {\n String[] st = br.readLine().split(\" \");\n for (int j = 0; j < 3; j++) {\n arr[i][j] = Integer.parseInt(st[j]);\n }\n }\n\n System.out.println(slidingPuzzle(arr));\n }\n\n public static int slidingPuzzle(int[][] board) {\n \n\n }\n \n \n \n \n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1 2 3\r\n4 0 5","sampleOutput":"1\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"7e07fddf-83bd-421e-848f-118f1f29541c","name":"Graphs For Intermediate","slug":"graphs-for-intermediate-493","type":0},{"id":"0aae6f63-3fda-4909-b5f9-ac7e50a41462","name":"Sliding Puzzle","slug":"sliding-puzzle","type":1}],"next":{"id":"16bee40b-0879-49fa-8a2f-149721760d44","name":"Sliding Puzzle","type":0,"slug":"sliding-puzzle"},"prev":{"id":"b5e00a9d-f3c7-4931-b45d-89f95cefd266","name":"As Far From Land As Possible","type":3,"slug":"as-far-from-land-as-possible"}}}
plane

Editor


Loading...

Sliding Puzzle

easy

On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4 directionally adjacent number and swapping it. Given the puzzle board, print the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, print -1. solved state is : {{1,2,3},{4,5,0}}

Constraints

rows = 2 cols = 3

Format

Input

Each of next 2 lines contain 3 integer.

Output

Min number of moves required to achieve solved state.

Example

Sample Input

1 2 3 4 0 5

Sample Output

1

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode