{"id":"52607f20-c41e-46fb-92c9-8b548c11cd98","name":"Matrix Cells In Distance Order","description":"1. You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).\r\n2. Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= rows, cols &lt;= 100\r\n0 &lt; rCenter &lt; rows\r\n0 &lt; cCenter &lt; cols","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n#include <cmath>\n#include <algorithm>\nusing namespace std;\n\nvector<vector<int>> solve(int rows, int cols, int rCenter, int cCenter) {\n //write your code here\n return null;\n }\n\nint main() {\n int rows = 0,cols = 0,rCenter = 0,cCenter = 0;\n cin>>rows>>cols>>rCenter>>cCenter;\n vector<vector<int>>ans = solve(rows, cols, rCenter, cCenter);\n for (int i = 0; i < ans.size(); i++) {\n cout<<\"(\"<<ans[i][0]<<\", \"<<ans[i][1]<<\"), \";\n }\n cout<<endl;\n }"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int[][] solve(int rows, int cols, int rCenter, int cCenter) {\r\n //write your code here\r\n return null;\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n int rows = scn.nextInt();\r\n int cols = scn.nextInt();\r\n int rCenter = scn.nextInt();\r\n int cCenter = scn.nextInt();\r\n\r\n int[][]ans = solve(rows, cols, rCenter, cCenter);\r\n\r\n for (int i = 0; i < ans.length; i++) {\r\n System.out.print(\"(\" + ans[i][0] + \", \" + ans[i][1] + \"), \");\r\n }\r\n System.out.println();\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"2 3 1 2","sampleOutput":"(1, 2), (0, 2), (1, 1), (0, 1), (1, 0), (0, 0),","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":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"678e922a-50d6-4d0f-8e9b-85786d67403a","name":"Matrix Cells In Distance Order","slug":"matrix-cells-in-distance-order","type":1}],"next":{"id":"ac0aeb86-368c-4a83-bb58-5b69873d1026","name":"Matrix Cells In Distance Order","type":3,"slug":"matrix-cells-in-distance-order"},"prev":{"id":"903dfef3-3533-4203-9d46-2564fbd29523","name":"Maximum Number Of 1's Row MCQ","type":0,"slug":"maximum-number-of-1-s-row-mcq-q3134"}}}

Matrix Cells In Distance Order

1. You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter). 2. Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance.

{"id":"52607f20-c41e-46fb-92c9-8b548c11cd98","name":"Matrix Cells In Distance Order","description":"1. You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).\r\n2. Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= rows, cols &lt;= 100\r\n0 &lt; rCenter &lt; rows\r\n0 &lt; cCenter &lt; cols","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n#include <cmath>\n#include <algorithm>\nusing namespace std;\n\nvector<vector<int>> solve(int rows, int cols, int rCenter, int cCenter) {\n //write your code here\n return null;\n }\n\nint main() {\n int rows = 0,cols = 0,rCenter = 0,cCenter = 0;\n cin>>rows>>cols>>rCenter>>cCenter;\n vector<vector<int>>ans = solve(rows, cols, rCenter, cCenter);\n for (int i = 0; i < ans.size(); i++) {\n cout<<\"(\"<<ans[i][0]<<\", \"<<ans[i][1]<<\"), \";\n }\n cout<<endl;\n }"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int[][] solve(int rows, int cols, int rCenter, int cCenter) {\r\n //write your code here\r\n return null;\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n int rows = scn.nextInt();\r\n int cols = scn.nextInt();\r\n int rCenter = scn.nextInt();\r\n int cCenter = scn.nextInt();\r\n\r\n int[][]ans = solve(rows, cols, rCenter, cCenter);\r\n\r\n for (int i = 0; i < ans.length; i++) {\r\n System.out.print(\"(\" + ans[i][0] + \", \" + ans[i][1] + \"), \");\r\n }\r\n System.out.println();\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"2 3 1 2","sampleOutput":"(1, 2), (0, 2), (1, 1), (0, 1), (1, 0), (0, 0),","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":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"678e922a-50d6-4d0f-8e9b-85786d67403a","name":"Matrix Cells In Distance Order","slug":"matrix-cells-in-distance-order","type":1}],"next":{"id":"ac0aeb86-368c-4a83-bb58-5b69873d1026","name":"Matrix Cells In Distance Order","type":3,"slug":"matrix-cells-in-distance-order"},"prev":{"id":"903dfef3-3533-4203-9d46-2564fbd29523","name":"Maximum Number Of 1's Row MCQ","type":0,"slug":"maximum-number-of-1-s-row-mcq-q3134"}}}
plane

Editor


Loading...

Matrix Cells In Distance Order

easy

1. You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter). 2. Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance.

Constraints

1 <= rows, cols <= 100 0 < rCenter < rows 0 < cCenter < cols

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

2 3 1 2

Sample Output

(1, 2), (0, 2), (1, 1), (0, 1), (1, 0), (0, 0),

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode