{"id":"9e692a3e-8def-4a7f-b4a2-8111bbe0fd91","name":"Flood Fill","description":"1. You are given a number n, representing the number of rows.\r\n2. You are given a number m, representing the number of columns.\r\n3. You are given n*m numbers, representing elements of 2d array a. The numbers can be 1 or 0 only.\r\n4. You are standing in the top-left corner and have to reach the bottom-right corner. \r\nOnly four moves are allowed 't' (1-step up), 'l' (1-step left), 'd' (1-step down) 'r' (1-step right). You can only move to cells which have 0 value in them. You can't move out of the boundaries or in the cells which have value 1 in them (1 means obstacle)\r\n5. Complete the body of floodfill function - without changing signature - to print all paths that can be used to move from top-left to bottom-right.\r\n\r\nNote1 -> Please check the sample input and output for details\r\nNote2 -> If all four moves are available make moves in the order 't', 'l', 'd' and 'r'","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * m number of elements","outputFormat":"trrrdlt\r\ntlldrt\r\n.. and so on","constraints":"1 &lt;= n &lt;= 10\r\n1 &lt;= m &lt;= 10\r\ne1, e2, .. n * m elements belongs to set (0, 1)","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n\nusing namespace std;\n\nvoid floodfill(int[][] maze) {\n\n}\n\nint main() {\n int n, m;\n cin >> n >> m;\n vector < vector < int >> arr(n, vector < int > (m));\n\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n cin >> arr[i][j];\n\n floodfill(arr);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int m = scn.nextInt();\r\n int[][] arr = new int[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n arr[i][j] = scn.nextInt();\r\n }\r\n }\r\n floodfill(arr, 0, 0, \"\");\r\n }\r\n \r\n // asf -> answer so far\r\n public static void floodfill(int[][] maze, int sr, int sc, String asf) {\r\n \r\n }\r\n}"},"python":{"code":"# asf -> answer so far\ndef floodfill(maze, sr, sc, asf):\n #write your code here\n \n\n\ndef main():\n n, m = input().split()\n n = int(n)\n m = int(m)\n arr = []\n for i in range(n): \n row = list(map(int, input().split()))\n arr.append(row)\n floodfill(arr, 0, 0, \"\");\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"3 3\r\n0 0 0\r\n1 0 1\r\n0 0 0","sampleOutput":"rddr","questionVideo":"https://www.youtube.com/embed/FkkgY7qQF_s","hints":[],"associated":[{"id":"26e517af-4077-4b38-b35c-86409cf55450","name":"(Flood Fill)How to visit the cells which have already been visited and not visit the same ?","slug":"flood-fill-how-to-visit-the-cells-which-have-already-been-visited-and-not-visit-the-same","type":4},{"id":"2907b146-61bf-48cb-ab84-1daeef7ef0c8","name":"(Flood Fill) what will be the space complexity for this question ?","slug":"flood-fill-what-will-be-the-space-complexity-for-this-question","type":4},{"id":"b6c10152-6637-4d81-8282-15d4f4a3a350","name":"(Flood Fill)In which cases will we return (from negative base cases) ?","slug":"flood-fill-in-which-cases-will-we-return-from-negative-base-cases","type":4},{"id":"dc09ae51-5bbc-4b18-af0f-2770fd158616","name":"(Flood Fill) What is the time complexity of this question ?","slug":"flood-fill-what-is-the-time-complexity-of-this-question","type":4}],"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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"eac2a729-6416-4858-93a7-244c0cd57302","name":"Flood Fill","slug":"flood-fill","type":1}],"next":{"id":"6eb3f7aa-b7a2-48a1-a957-9a5e8f0b076b","name":"Flood Fill","type":3,"slug":"flood-fill"},"prev":{"id":"0015462c-5978-41d4-8f93-e47d8494272f","name":"Print Encodings","type":3,"slug":"print-encodings"}}}

Flood Fill

1. You are given a number n, representing the number of rows. 2. You are given a number m, representing the number of columns. 3. You are given n*m numbers, representing elements of 2d array a. The numbers can be 1 or 0 only. 4. You are standing in the top-left corner and have to reach the bottom-right corner. Only four moves are allowed 't' (1-step up), 'l' (1-step left), 'd' (1-step down) 'r' (1-step right). You can only move to cells which have 0 value in them. You can't move out of the boundaries or in the cells which have value 1 in them (1 means obstacle) 5. Complete the body of floodfill function - without changing signature - to print all paths that can be used to move from top-left to bottom-right. Note1 -> Please check the sample input and output for details Note2 -> If all four moves are available make moves in the order 't', 'l', 'd' and 'r'

{"id":"9e692a3e-8def-4a7f-b4a2-8111bbe0fd91","name":"Flood Fill","description":"1. You are given a number n, representing the number of rows.\r\n2. You are given a number m, representing the number of columns.\r\n3. You are given n*m numbers, representing elements of 2d array a. The numbers can be 1 or 0 only.\r\n4. You are standing in the top-left corner and have to reach the bottom-right corner. \r\nOnly four moves are allowed 't' (1-step up), 'l' (1-step left), 'd' (1-step down) 'r' (1-step right). You can only move to cells which have 0 value in them. You can't move out of the boundaries or in the cells which have value 1 in them (1 means obstacle)\r\n5. Complete the body of floodfill function - without changing signature - to print all paths that can be used to move from top-left to bottom-right.\r\n\r\nNote1 -> Please check the sample input and output for details\r\nNote2 -> If all four moves are available make moves in the order 't', 'l', 'd' and 'r'","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * m number of elements","outputFormat":"trrrdlt\r\ntlldrt\r\n.. and so on","constraints":"1 &lt;= n &lt;= 10\r\n1 &lt;= m &lt;= 10\r\ne1, e2, .. n * m elements belongs to set (0, 1)","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n\nusing namespace std;\n\nvoid floodfill(int[][] maze) {\n\n}\n\nint main() {\n int n, m;\n cin >> n >> m;\n vector < vector < int >> arr(n, vector < int > (m));\n\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n cin >> arr[i][j];\n\n floodfill(arr);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int m = scn.nextInt();\r\n int[][] arr = new int[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n arr[i][j] = scn.nextInt();\r\n }\r\n }\r\n floodfill(arr, 0, 0, \"\");\r\n }\r\n \r\n // asf -> answer so far\r\n public static void floodfill(int[][] maze, int sr, int sc, String asf) {\r\n \r\n }\r\n}"},"python":{"code":"# asf -> answer so far\ndef floodfill(maze, sr, sc, asf):\n #write your code here\n \n\n\ndef main():\n n, m = input().split()\n n = int(n)\n m = int(m)\n arr = []\n for i in range(n): \n row = list(map(int, input().split()))\n arr.append(row)\n floodfill(arr, 0, 0, \"\");\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"3 3\r\n0 0 0\r\n1 0 1\r\n0 0 0","sampleOutput":"rddr","questionVideo":"https://www.youtube.com/embed/FkkgY7qQF_s","hints":[],"associated":[{"id":"26e517af-4077-4b38-b35c-86409cf55450","name":"(Flood Fill)How to visit the cells which have already been visited and not visit the same ?","slug":"flood-fill-how-to-visit-the-cells-which-have-already-been-visited-and-not-visit-the-same","type":4},{"id":"2907b146-61bf-48cb-ab84-1daeef7ef0c8","name":"(Flood Fill) what will be the space complexity for this question ?","slug":"flood-fill-what-will-be-the-space-complexity-for-this-question","type":4},{"id":"b6c10152-6637-4d81-8282-15d4f4a3a350","name":"(Flood Fill)In which cases will we return (from negative base cases) ?","slug":"flood-fill-in-which-cases-will-we-return-from-negative-base-cases","type":4},{"id":"dc09ae51-5bbc-4b18-af0f-2770fd158616","name":"(Flood Fill) What is the time complexity of this question ?","slug":"flood-fill-what-is-the-time-complexity-of-this-question","type":4}],"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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"eac2a729-6416-4858-93a7-244c0cd57302","name":"Flood Fill","slug":"flood-fill","type":1}],"next":{"id":"6eb3f7aa-b7a2-48a1-a957-9a5e8f0b076b","name":"Flood Fill","type":3,"slug":"flood-fill"},"prev":{"id":"0015462c-5978-41d4-8f93-e47d8494272f","name":"Print Encodings","type":3,"slug":"print-encodings"}}}
plane

Editor


Loading...

Flood Fill

easy

1. You are given a number n, representing the number of rows. 2. You are given a number m, representing the number of columns. 3. You are given n*m numbers, representing elements of 2d array a. The numbers can be 1 or 0 only. 4. You are standing in the top-left corner and have to reach the bottom-right corner. Only four moves are allowed 't' (1-step up), 'l' (1-step left), 'd' (1-step down) 'r' (1-step right). You can only move to cells which have 0 value in them. You can't move out of the boundaries or in the cells which have value 1 in them (1 means obstacle) 5. Complete the body of floodfill function - without changing signature - to print all paths that can be used to move from top-left to bottom-right. Note1 -> Please check the sample input and output for details Note2 -> If all four moves are available make moves in the order 't', 'l', 'd' and 'r'

Constraints

1 <= n <= 10 1 <= m <= 10 e1, e2, .. n * m elements belongs to set (0, 1)

Format

Input

A number n A number m e11 e12.. e21 e22.. .. n * m number of elements

Output

trrrdlt tlldrt .. and so on

Example

Sample Input

3 3 0 0 0 1 0 1 0 0 0

Sample Output

rddr

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode