question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-compatibility-score-sum | [C++] DP + Bitmask | 15 lines of code with explanation | 0ms | Beats 100% | c-dp-bitmask-15-lines-of-code-with-expla-gxfl | We assign j-th mentor to i-th student from the set of mentors available. We iterate with a fixed mentors available. For every mentor_set, if we calculate the c | pratyushk82010 | NORMAL | 2021-07-25T22:35:34.717889+00:00 | 2021-07-25T22:35:34.717937+00:00 | 66 | false | We assign j-th mentor to i-th student from the set of mentors available. We iterate with a fixed mentors available. For every mentor_set, if we calculate the compatibility score of assigning j-th mentor to i-th student then what is important for us is the compatibility score of assigning all other mentors (exept j-th)... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | Easy bitmask and backtracking | easy-bitmask-and-backtracking-by-2pac_sh-i19g | Why backtracking\nThe contraints are only till 8, so we can explore all the paths.\nWhy bitmask\nRecursive call consumes less space, so, it is easy to keep trac | 2pac_shakur | NORMAL | 2021-07-25T10:14:31.202757+00:00 | 2021-07-25T10:14:31.202792+00:00 | 73 | false | **Why backtracking**\nThe contraints are only till 8, so we can explore all the paths.\n**Why bitmask**\nRecursive call consumes less space, so, it is easy to keep track of which mentor is assigned and which isn\'t.\n\n```\n /**\n Find compatablilty scores for each student to each mentor.\n \n T... | 1 | 0 | ['Bitmask', 'Kotlin'] | 0 |
maximum-compatibility-score-sum | Java - Bitmask DP - Easy to understand | java-bitmask-dp-easy-to-understand-by-al-5gm3 | \n\nclass Solution {\n Integer[] dp;\n int ALL;\n int[][] students;\n int[][] mentors;\n public int maxCompatibilitySum(int[][] students, int[][] | alan_black | NORMAL | 2021-07-25T08:13:55.668750+00:00 | 2021-07-25T08:13:55.668793+00:00 | 308 | false | \n```\nclass Solution {\n Integer[] dp;\n int ALL;\n int[][] students;\n int[][] mentors;\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n final int nStudents = students.length;\n final int nAnswers = students[0].length;\n this.students = students;\n thi... | 1 | 0 | ['Dynamic Programming', 'Bitmask', 'Java'] | 0 |
maximum-compatibility-score-sum | JAVA | java-by-kapil08-bu6t | \nclass Solution {\n int max=0;\n Set<Integer>set=new HashSet<>();\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n \n | kapil08 | NORMAL | 2021-07-25T07:19:28.425802+00:00 | 2021-07-25T07:19:28.425845+00:00 | 60 | false | ```\nclass Solution {\n int max=0;\n Set<Integer>set=new HashSet<>();\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n \n solve(students,mentors,"");\n return max;\n }\n \n void solve(int[][]students,int[][]mentor,String s){\n\t\n\t//find the ans from each p... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | [C++] Simple Backtracking Solution | c-simple-backtracking-solution-by-varun0-m183 | ```\nint res = 0;\n \nvoid countScore(vector >& mentors, vector >& students) {\n\tint count = 0;\n\tfor(int i = 0; i<students.size(); i++) {\n\t\tfor(int j = | varun09 | NORMAL | 2021-07-25T07:03:40.062658+00:00 | 2021-07-25T07:03:40.062700+00:00 | 37 | false | ```\nint res = 0;\n \nvoid countScore(vector<vector<int> >& mentors, vector<vector<int> >& students) {\n\tint count = 0;\n\tfor(int i = 0; i<students.size(); i++) {\n\t\tfor(int j = 0; j<students[i].size(); j++) {\n\t\t\tif(students[i][j] == mentors[i][j]) count++;\n\t\t}\n\t}\n\tres = max(res, count);\n}\n\nvoid pe... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | Simple Backtracking solution C++ | simple-backtracking-solution-c-by-gaurav-dk50 | \nclass Solution {\npublic:\n int calculate(vector<int>v1,vector<int>v2)\n {\n int s=0;\n for(int i=0;i<v1.size();i++)\n {\n | gaurav1903 | NORMAL | 2021-07-25T05:28:17.419166+00:00 | 2021-07-25T05:28:17.419210+00:00 | 30 | false | ```\nclass Solution {\npublic:\n int calculate(vector<int>v1,vector<int>v2)\n {\n int s=0;\n for(int i=0;i<v1.size();i++)\n {\n if(v1[i]==v2[i])\n s+=1;\n }\n return s;\n }\n int maxscore=0;\n \n void allcombo(vector<vector<int>>& students, ... | 1 | 0 | [] | 1 |
maximum-compatibility-score-sum | Python 2 lines brute force with permutations | python-2-lines-brute-force-with-permutat-6fd0 | python\nn = len(students)\nsums = []\nfor s in students:\n\ttemp = []\n\tfor m in mentors:\n\t\ttemp.append(sum([s[i] == m[i] for i in range(len(s))]))\n\tsums. | FACEPLANT | NORMAL | 2021-07-25T04:42:29.791184+00:00 | 2021-07-25T04:42:29.791214+00:00 | 66 | false | ```python\nn = len(students)\nsums = []\nfor s in students:\n\ttemp = []\n\tfor m in mentors:\n\t\ttemp.append(sum([s[i] == m[i] for i in range(len(s))]))\n\tsums.append(temp)\nperm = list(permutations(range(0, n)))\nresult = 0\nfor p in perm:\n\tresult = max(result, sum([sums[i][p[i]] for i in range(n)]))\nreturn resu... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | [C++] | [OPTIMIZED Backtracking Solution] | [Easy-To-Understand] | c-optimized-backtracking-solution-easy-t-hhvd | \nclass Solution {\npublic:\n inline int score(vector<int> &a, vector<int> &b, int &size)\n {\n int s=0;\n for(int i=0;i<size;++i)\n | prakhar-pipersania | NORMAL | 2021-07-25T04:39:55.691229+00:00 | 2021-07-25T05:48:50.869055+00:00 | 93 | false | ```\nclass Solution {\npublic:\n inline int score(vector<int> &a, vector<int> &b, int &size)\n {\n int s=0;\n for(int i=0;i<size;++i)\n if(a[i]==b[i])\n s++;\n return s;\n }\n inline void solve(int arr[], vector<bool> &a, int &m, int &n, int &ms, int l, int sum... | 1 | 0 | ['C'] | 0 |
maximum-compatibility-score-sum | python dfs recursion | python-dfs-recursion-by-ayushman_123-s75x | ```\ndef cscore(a,b):\n ans=0\n for i in range(len(a)):\n if a[i]==b[i]:\n ans+=1\n return ans \ndef function(students,mentors,n,s | Ayushman_123 | NORMAL | 2021-07-25T04:33:43.510353+00:00 | 2021-10-02T01:04:28.317483+00:00 | 180 | false | ```\ndef cscore(a,b):\n ans=0\n for i in range(len(a)):\n if a[i]==b[i]:\n ans+=1\n return ans \ndef function(students,mentors,n,score,ans,visited):\n \n if n==0:\n ans.append(score)\n return\n for i in range(len(students)):\n if not visited[i]:\n v... | 1 | 0 | ['Depth-First Search', 'Python'] | 0 |
maximum-compatibility-score-sum | Java Simple and easy to understand solution, clean code with comments | java-simple-and-easy-to-understand-solut-dkjd | \nclass Solution {\n int maxScoreSum;\n \n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int s = students.length;\n | satyaDcoder | NORMAL | 2021-07-25T04:17:46.626339+00:00 | 2021-07-25T04:17:46.626368+00:00 | 103 | false | ```\nclass Solution {\n int maxScoreSum;\n \n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int s = students.length;\n int m = mentors.length;\n \n //store the cores of each pair of students and mentors\n int[][] scores = new int[s][m];\n \n ... | 1 | 1 | ['Backtracking', 'Java'] | 0 |
maximum-compatibility-score-sum | JAVA DFS + Memorization faster than 100% | java-dfs-memorization-faster-than-100-by-qi5a | \nclass Solution {\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int[][] scores = new int[students.length][students.length]; | jianjia2 | NORMAL | 2021-07-25T04:17:43.268869+00:00 | 2021-07-25T04:19:33.534306+00:00 | 77 | false | ```\nclass Solution {\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int[][] scores = new int[students.length][students.length];\n for (int i = 0; i < scores.length; i++) {\n for (int j = 0; j < scores[0].length; j++) {\n scores[i][j] = getCompatibilit... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | Java Backtracking DFS | java-backtracking-dfs-by-hw1635-s4ot | \nclass Solution {\n public int max = 0;\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n List<Integer> scores = new ArrayLi | hw1635 | NORMAL | 2021-07-25T04:16:41.640953+00:00 | 2021-07-25T04:16:41.640981+00:00 | 72 | false | ```\nclass Solution {\n public int max = 0;\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n List<Integer> scores = new ArrayList<>(); \n boolean[] visited = new boolean[students.length];\n backtrack(students, mentors, 0, 0, visited);\n return max;\n }\n p... | 1 | 0 | [] | 1 |
maximum-compatibility-score-sum | [Python3] Simple Bitmask DP | python3-simple-bitmask-dp-by-blackspinne-1ata | \nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n m = len(students)\n n = len(st | blackspinner | NORMAL | 2021-07-25T04:10:15.896623+00:00 | 2021-07-25T21:22:13.362027+00:00 | 101 | false | ```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n m = len(students)\n n = len(students[0])\n complete = (1 << m) - 1\n scores = [[0] * m for _ in range(m)]\n def calc(st, me):\n score = 0\n for ... | 1 | 0 | [] | 1 |
maximum-compatibility-score-sum | [Python 3] Easy understand Backtracking Solution | python-3-easy-understand-backtracking-so-m1lh | The first thing we need to do is to initialize the student-teacher compatibility score matrix:\nmat[i][j] = n - sum(abs(students[i][x] - mentors[j][x]) for x in | danielxue | NORMAL | 2021-07-25T04:10:03.003601+00:00 | 2021-07-25T04:11:32.842146+00:00 | 88 | false | The first thing we need to do is to initialize the `student-teacher` compatibility score matrix:\n`mat[i][j] = n - sum(abs(students[i][x] - mentors[j][x]) for x in range(n))`\n\nAfter we build the compatibility score matrix, than it becomes the standard backtracking problem.\nCode:\n```python\nclass Solution:\n def ... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | C++ concise code | using next_permutation | O(n*(n*m)*n!) | c-concise-code-using-next_permutation-on-wyxx | \nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int n = students.size();\n | asciarp08 | NORMAL | 2021-07-25T04:09:09.255136+00:00 | 2021-07-25T04:14:16.501847+00:00 | 112 | false | ```\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int n = students.size();\n int m = students[0].size();\n vector<int>pos;\n \n for(int i = 0; i<n;i++){\n pos.push_back(i);\n }\n \n ... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | JAVA O(n^3) Kuhn-Munkres (Hungarian) | java-on3-kuhn-munkres-hungarian-by-reed_-5qzf | ```\nclass Solution {\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n return sln1(students, mentors);\n }\n \n privat | reed_w | NORMAL | 2021-07-25T04:07:27.075517+00:00 | 2021-07-25T04:07:27.075566+00:00 | 206 | false | ```\nclass Solution {\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n return sln1(students, mentors);\n }\n \n private int sln1(int[][] sts, int[][] mts){\n int m = sts.length;\n int n = sts[0].length;\n int[][] arr = new int[m][m];\n for(int i = 0;... | 1 | 2 | [] | 0 |
maximum-compatibility-score-sum | [C++] DP + next_permutation() 100% fast | c-dp-next_permutation-100-fast-by-satvik-tfjr | \nclass Solution {\npublic:\n\n int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& m) {\n vector<vector<int>>dp(s.size(),vector<int> | satvikshrivas | NORMAL | 2021-07-25T04:06:07.042285+00:00 | 2021-07-25T13:41:24.889950+00:00 | 236 | false | ```\nclass Solution {\npublic:\n\n int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& m) {\n vector<vector<int>>dp(s.size(),vector<int>(s.size(),0));\n \n for(int i =0;i<s.size();i++){\n for(int j =0;j<s.size();j++){\n int cnt=0;\n for(i... | 1 | 1 | ['Dynamic Programming', 'C'] | 0 |
maximum-compatibility-score-sum | Python Solution | python-solution-by-lzhangucb-9mct | \nclass Solution(object):\n def maxCompatibilitySum(self, students, mentors):\n """\n :type students: List[List[int]]\n :type mentors: L | lzhangucb | NORMAL | 2021-07-25T04:05:02.211987+00:00 | 2021-07-25T04:13:54.896320+00:00 | 75 | false | ```\nclass Solution(object):\n def maxCompatibilitySum(self, students, mentors):\n """\n :type students: List[List[int]]\n :type mentors: List[List[int]]\n :rtype: int\n """\n m = len(students)\n n = len(students[0])\n scores =[ [sum([students[i][k] == mentors[... | 1 | 1 | [] | 0 |
maximum-compatibility-score-sum | Python solution with backtracking | python-solution-with-backtracking-by-rhp-d1ic | \nclass Solution:\n \n def check_commonality(self, student, mentor):\n i = 0\n count = 0\n while i < len(student):\n if st | rhpatel | NORMAL | 2021-07-25T04:04:49.366262+00:00 | 2021-07-25T04:05:54.777608+00:00 | 235 | false | ```\nclass Solution:\n \n def check_commonality(self, student, mentor):\n i = 0\n count = 0\n while i < len(student):\n if student[i] == mentor[i]:\n count+=1\n i+=1\n return count\n \n def maxCompatibilitySum(self, students: List[List[int]], ... | 1 | 0 | ['Combinatorics', 'Python', 'Python3'] | 0 |
maximum-compatibility-score-sum | JAVA | Simple DFS | java-simple-dfs-by-uchihasasuke-ag26 | \nclass Solution {\n int[][] students;\n int[][] mentors;\n int len = 0;\n int res = 0;\n public int maxCompatibilitySum(int[][] _students, int[] | uchihasasuke | NORMAL | 2021-07-25T04:01:19.850762+00:00 | 2021-07-25T04:07:11.389082+00:00 | 169 | false | ```\nclass Solution {\n int[][] students;\n int[][] mentors;\n int len = 0;\n int res = 0;\n public int maxCompatibilitySum(int[][] _students, int[][] _mentors) { \n students = _students;\n mentors = _mentors;\n if(students == null || students.length == 0 || mentors == null ||... | 1 | 1 | [] | 0 |
maximum-compatibility-score-sum | brute-force C++ permutations | brute-force-c-permutations-by-claytonjwo-77bx | \nclass Solution {\npublic:\n using VI = vector<int>;\n using VVI = vector<VI>;\n int maxCompatibilitySum(VVI& A, VVI& B, int best = 0) {\n int | claytonjwong | NORMAL | 2021-07-25T04:00:45.417795+00:00 | 2021-07-25T04:00:45.417823+00:00 | 167 | false | ```\nclass Solution {\npublic:\n using VI = vector<int>;\n using VVI = vector<VI>;\n int maxCompatibilitySum(VVI& A, VVI& B, int best = 0) {\n int M = A.size(),\n N = A[0].size();\n sort(A.begin(), A.end());\n do {\n auto cand = 0;\n for (auto i{ 0 }; i < M... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | Using Recursion | using-recursion-by-rachanikhilrnr-abwp | IntuitionHere you need to understand that you can link any of the student to any of the mentor and explore all the posibilities to get max scoreApproachI hope y | rachanikhilrnr | NORMAL | 2025-04-10T07:10:49.029468+00:00 | 2025-04-10T07:10:49.029468+00:00 | 3 | false | # Intuition
Here you need to understand that you can link any of the student to any of the mentor and explore all the posibilities to get max score
# Approach
I hope you already know recursion & dynamic programming !
Loop through all the students
One student at a time and try all possiblities of mentors...
Conside... | 0 | 0 | ['Dynamic Programming', 'Recursion', 'Java'] | 0 |
reshape-the-matrix | Java Concise O(nm) time | java-concise-onm-time-by-compton_scatter-d1vc | \npublic int[][] matrixReshape(int[][] nums, int r, int c) {\n int n = nums.length, m = nums[0].length;\n if (r*c != n*m) return nums;\n int[][] res = | compton_scatter | NORMAL | 2017-04-30T03:04:28.788000+00:00 | 2018-10-24T18:17:30.146724+00:00 | 31,347 | false | ```\npublic int[][] matrixReshape(int[][] nums, int r, int c) {\n int n = nums.length, m = nums[0].length;\n if (r*c != n*m) return nums;\n int[][] res = new int[r][c];\n for (int i=0;i<r*c;i++) \n res[i/c][i%c] = nums[i/m][i%m];\n return res;\n}\n``` | 327 | 2 | [] | 36 |
reshape-the-matrix | One loop | one-loop-by-stefanpochmann-gut1 | We can use matrix[index / width][index % width] for both the input and the output matrix.\n\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n | stefanpochmann | NORMAL | 2017-04-30T07:11:21.850000+00:00 | 2018-09-26T04:54:59.576207+00:00 | 18,359 | false | We can use `matrix[index / width][index % width]` for both the input and the output matrix.\n\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int m = nums.length, n = nums[0].length;\n if (r * c != m * n)\n return nums;\n int[][] reshaped = new int[r][c];\n for (... | 171 | 3 | [] | 17 |
reshape-the-matrix | ✅ C++ One-Loop Easy Solution | Column-first and Row-first Approaches | c-one-loop-easy-solution-column-first-an-m23c | There\'s nothing much to this problem - Just check if total elements in both matrices will be same and then transform. I have mentioned two approaches below.\n\ | archit91 | NORMAL | 2021-07-05T07:33:14.194909+00:00 | 2022-01-12T18:49:52.143808+00:00 | 15,977 | false | There\'s nothing much to this problem - Just check if total elements in both matrices will be same and then transform. I have mentioned two approaches below.\n\n----\n\n\u2714\uFE0F ***Solution (Row-First Approach)***\n\nIterate each row column-by-column, wrap around when you reach the end on one row and move to the ne... | 169 | 7 | ['C'] | 10 |
reshape-the-matrix | [Python] Intuitive + Direct for Beginners with Illustrations | python-intuitive-direct-for-beginners-wi-klng | Given a matrix mat of 3 rows * 4 columns, \nwe want reshape it into 2 rows (r = 2) * 6 columns(c = 6): \n\n[[0, 1, 2, 3],\n [4, 5, 6, 7], | ziaiz-zythoniz | NORMAL | 2022-05-17T05:45:14.586264+00:00 | 2022-05-17T06:04:56.764490+00:00 | 10,336 | false | Given a matrix `mat` of 3 rows * 4 columns, \nwe want reshape it into 2 rows (`r = 2`) * 6 columns(`c = 6`): \n```\n[[0, 1, 2, 3],\n [4, 5, 6, 7], -> [[0, 1, 2, 3, 4, 5],\n [8, 9, 10, 11]] [6, 7, 8, 9, 10, 11]]\n```\n**Step 1:** Flatten t... | 157 | 0 | ['Matrix', 'Python', 'Python3'] | 10 |
reshape-the-matrix | JAVA SOLUTION || DETAILED EXPLANATION || EASY APPROCH || 100% Efficent | java-solution-detailed-explanation-easy-qvyv3 | Approch -``\n\n1st condition to be checked -\nFirstly will have to check if the product of dimension of the given array matrix(mat) and the product of dimension | sarrthac | NORMAL | 2022-01-28T18:27:21.701045+00:00 | 2022-01-28T18:27:50.503700+00:00 | 10,447 | false | # Approch -``\n\n***1st condition** to be checked -*\nFirstly will have to check if the product of dimension of the given array matrix(**mat**) and the product of dimensions of the new array matrix are eqaul. If they are not equal this means we cannot fill all the elements perfectly in one of the matrix hence in this c... | 141 | 1 | ['Java'] | 12 |
reshape-the-matrix | Python Solutions | python-solutions-by-stefanpochmann-lzxb | Solution 1 - NumPy\n\n\nWhen I read "MATLAB", I immediately thought "NumPy". Thanks to @fallcreek for pointing out tolist, makes converting the result to the co | stefanpochmann | NORMAL | 2017-04-30T07:01:29.434000+00:00 | 2017-04-30T07:01:29.434000+00:00 | 19,772 | false | #### **Solution 1 - `NumPy`**\n\n\nWhen I read "MATLAB", I immediately thought "NumPy". Thanks to @fallcreek for pointing out `tolist`, makes converting the result to the correct type easier than what I had originally.\n```\nimport numpy as np\n\nclass Solution(object):\n def matrixReshape(self, nums, r, c):\n ... | 91 | 10 | [] | 16 |
reshape-the-matrix | [Python] One pass - Clean & Concise | python-one-pass-clean-concise-by-hiepit-dp9y | Python 3\n\nclass Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n m, n = len(mat), len(mat[0])\n | hiepit | NORMAL | 2021-07-05T08:04:11.715005+00:00 | 2021-07-05T08:04:11.715047+00:00 | 3,686 | false | **Python 3**\n```\nclass Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n m, n = len(mat), len(mat[0])\n if r * c != m * n: return mat # Invalid size -> return original matrix\n ans = [[0] * c for _ in range(r)]\n for i in range(m * n):\n ... | 65 | 3 | [] | 3 |
reshape-the-matrix | Javascript ES6 simple solution | javascript-es6-simple-solution-by-leomac-a8t6 | \nvar matrixReshape = function (nums, r, c) {\n var arr = nums.flat();\n if (r * c != arr.length) return nums;\n\n var res = [];\n while (arr.length) res.pu | leomacode | NORMAL | 2020-07-13T21:23:23.125193+00:00 | 2020-07-13T21:23:23.125228+00:00 | 2,832 | false | ```\nvar matrixReshape = function (nums, r, c) {\n var arr = nums.flat();\n if (r * c != arr.length) return nums;\n\n var res = [];\n while (arr.length) res.push(arr.splice(0, c));\n return res;\n};\n``` | 58 | 1 | ['JavaScript'] | 8 |
reshape-the-matrix | Easy Java Solution | easy-java-solution-by-shawngao-iotb | \npublic class Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int m = nums.length, n = nums[0].length;\n if (m * n ! | shawngao | NORMAL | 2017-04-30T03:05:45.954000+00:00 | 2018-09-03T23:15:13.686661+00:00 | 7,645 | false | ```\npublic class Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int m = nums.length, n = nums[0].length;\n if (m * n != r * c) return nums;\n \n int[][] result = new int[r][c];\n int row = 0, col = 0;\n for (int i = 0; i < m; i++) {\n f... | 53 | 1 | [] | 8 |
reshape-the-matrix | C solution | c-solution-by-stefanpochmann-uq1n | \nint** matrixReshape(int** nums, int m, int n, int r, int c, int** columnSizes, int* returnSize) {\n if (r * c != m * n) {\n r = m;\n c = n;\n | stefanpochmann | NORMAL | 2017-05-03T12:28:04.121000+00:00 | 2018-10-14T03:57:36.655603+00:00 | 11,002 | false | ```\nint** matrixReshape(int** nums, int m, int n, int r, int c, int** columnSizes, int* returnSize) {\n if (r * c != m * n) {\n r = m;\n c = n;\n }\n\n *returnSize = r;\n int** result = (int**) malloc(r * sizeof(int*));\n *columnSizes = (int*) malloc(r * sizeof(int));\n for (int i = 0; ... | 46 | 4 | [] | 5 |
reshape-the-matrix | Easy-to-understand python solution | easy-to-understand-python-solution-by-pe-0l7q | \nclass Solution(object):\n def matrixReshape(self, nums, r, c):\n """\n :type nums: List[List[int]]\n :type r: int\n :type c: in | peterwu | NORMAL | 2017-06-03T12:16:03.449000+00:00 | 2018-09-29T06:42:06.460468+00:00 | 4,732 | false | ```\nclass Solution(object):\n def matrixReshape(self, nums, r, c):\n """\n :type nums: List[List[int]]\n :type r: int\n :type c: int\n :rtype: List[List[int]]\n """\n if len(nums) * len(nums[0]) != r * c:\n return nums\n \n ans = [[]]\n ... | 44 | 1 | ['Python'] | 9 |
reshape-the-matrix | Very Easy || 100% || Fully Explained || Java, C++, Python, JavaScript, Python3 | very-easy-100-fully-explained-java-c-pyt-7gwt | Java Solution:\n\n// Runtime: 1 ms, faster than 92.33% of Java online submissions for Reshape the Matrix.\n// Time Complexity : O(r*c)\n// Space Complexity : O( | PratikSen07 | NORMAL | 2022-08-26T18:00:17.806842+00:00 | 2022-08-26T18:00:17.806887+00:00 | 6,172 | false | # **Java Solution:**\n```\n// Runtime: 1 ms, faster than 92.33% of Java online submissions for Reshape the Matrix.\n// Time Complexity : O(r*c)\n// Space Complexity : O(r*c)\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n // If transformation doesn\'t occur, return mat...\n ... | 39 | 2 | ['Array', 'C', 'Matrix', 'Simulation', 'Python', 'Java', 'Python3', 'JavaScript'] | 4 |
reshape-the-matrix | [C++] [Java] Clean Code - 5 lines (2 Solution) | c-java-clean-code-5-lines-2-solution-by-tyv4v | Java\n\nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int m = nums.length, n = nums[0].length, o = m * n;\n i | alexander | NORMAL | 2017-04-30T03:08:34.543000+00:00 | 2018-09-06T06:57:20.812361+00:00 | 10,619 | false | **Java**\n```\nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int m = nums.length, n = nums[0].length, o = m * n;\n if (r * c != o) return nums;\n int[][] res = new int[r][c];\n for (int i = 0; i < o; i++) res[i / c][i % c] = nums[i / n][i % n];\n r... | 39 | 1 | [] | 6 |
reshape-the-matrix | Python, Simple with Explanation | python-simple-with-explanation-by-awice-xuuz | Collect the values of the array A, and then put them into the answer of size nR x nC.\n\n\ndef matrixReshape(self, A, nR, nC):\n if len(A) * len(A[0]) != nR | awice | NORMAL | 2017-04-30T03:02:39.101000+00:00 | 2017-04-30T03:02:39.101000+00:00 | 6,497 | false | Collect the values of the array A, and then put them into the answer of size ```nR x nC```.\n\n```\ndef matrixReshape(self, A, nR, nC):\n if len(A) * len(A[0]) != nR * nC:\n return A\n \n vals = (val for row in A for val in row)\n return [[vals.next() for c in xrange(nC)] for r in xrange(nR)]\n``... | 37 | 2 | [] | 5 |
reshape-the-matrix | Python - One Line, Two Line, Yield, Generator, Circular Index, Numpy - with explaination(#556) | python-one-line-two-line-yield-generator-xiip | Solution #1: Using Numpy\nBelow is the one line code which makes use of numpy.reshape method provided by numpy.\npython\nimport numpy\nclass Solution:\n def | abhira0 | NORMAL | 2021-07-05T08:49:17.626368+00:00 | 2021-07-05T17:01:42.547471+00:00 | 2,068 | false | # Solution #1: Using Numpy\nBelow is the one line code which makes use of numpy.reshape method provided by numpy.\n```python\nimport numpy\nclass Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n return numpy.reshape(mat,(r,c)) if r*c==len(mat)*len(mat[0]) else ma... | 29 | 1 | ['Queue', 'Python', 'Python3'] | 6 |
reshape-the-matrix | Python Beginner Solution - Beats 82% | python-beginner-solution-beats-82-by-lov-33de | ```\ndef rotate(nums, r, c):\n flat_list = []\n matrix = []\n\n for sublist in nums:\n for item in sublist:\n flat_list.append(item)\ | lovefishly | NORMAL | 2020-03-09T15:25:28.946178+00:00 | 2020-03-09T16:35:45.216072+00:00 | 2,965 | false | ```\ndef rotate(nums, r, c):\n flat_list = []\n matrix = []\n\n for sublist in nums:\n for item in sublist:\n flat_list.append(item)\n\n if len(flat_list) != r * c:\n return nums\n else:\n for i in range(0,len(flat_list),c):\n matrix.append(flat_list[i:i+c])\n ... | 29 | 0 | ['Python', 'Python3'] | 4 |
reshape-the-matrix | Java in one pass ,faster than 100% | java-in-one-pass-faster-than-100-by-rohi-49jv | Please UpVote if you like the solution Happy Coding !!!\n\nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int m = nums.le | rohitkumarsingh369 | NORMAL | 2021-07-05T08:45:46.679606+00:00 | 2021-07-05T18:19:35.178708+00:00 | 1,112 | false | *Please **UpVote** if you like the solution **Happy Coding** !!!*\n```\nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int m = nums.length, n = nums[0].length;\n if (r * c != m * n)\n return nums;\n int[][] reshaped = new int[r][c];\n for (int i = 0; i < r * c; i++... | 21 | 0 | ['Java'] | 3 |
reshape-the-matrix | ✅ Reshape the Matrix | One-Loop Clean and Easy Solution | reshape-the-matrix-one-loop-clean-and-ea-ulhs | There\'s nothing much to this problem - Just check if total elements in both matrices will be same and then transform. I have mentioned two approaches below.\n\ | archit91 | NORMAL | 2021-07-05T07:34:34.589125+00:00 | 2021-07-05T08:53:11.441556+00:00 | 1,643 | false | There\'s nothing much to this problem - Just check if total elements in both matrices will be same and then transform. I have mentioned two approaches below.\n\n\u2714\uFE0F ***Solution (Row-First Approach)***\n\nIterate each row column-by-column, wrap around when you reach the end on one row and move to the next row. ... | 20 | 4 | ['C'] | 3 |
reshape-the-matrix | [Python] One pass solution, explained | python-one-pass-solution-explained-by-db-p8y1 | First approach is to reshape to line and then reshape it to new shape. However we can do smarter: just iterate over all elements line by line and use res[count/ | dbabichev | NORMAL | 2021-07-05T07:51:54.472515+00:00 | 2021-07-05T07:51:54.472543+00:00 | 844 | false | First approach is to reshape to line and then reshape it to new shape. However we can do smarter: just iterate over all elements line by line and use `res[count//c][count\\%c] = nums[i][j]` to fill element by element. \n\n#### Complexity\nTime complexity is `O(mn)`, space complexity is `O(mn)`, but in fact it is `O(1)`... | 19 | 2 | ['Math', 'Matrix'] | 1 |
reshape-the-matrix | Beats 100% || Simple and easy to understand || C++ | beats-100-simple-and-easy-to-understand-2h8k8 | \n\n# Code\n\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int m = mat.size() , n= mat[0] | Amit_2001 | NORMAL | 2023-01-17T21:23:35.727203+00:00 | 2023-01-17T21:23:35.727246+00:00 | 3,232 | false | \n\n# Code\n```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int m = mat.size() , n= mat[0].size();\n vector<vector<int>>v(r,vector<int>(c));\n queue<int>q;\n if(m*n == r*c){\n for(int i=0;i<m;i++){\n ... | 18 | 0 | ['C++'] | 0 |
reshape-the-matrix | [C++] Easy Implementation: For Beginners | c-easy-implementation-for-beginners-by-r-gni8 | Approach: Firstly, check the dimensions required to reshape the matrix. If the multiplication of rows and columns of the original matrix is not equal to the mul | rsgt24 | NORMAL | 2021-07-05T07:32:48.605372+00:00 | 2021-07-06T06:13:14.969942+00:00 | 921 | false | **Approach:** Firstly, check the dimensions required to reshape the matrix. If the multiplication of rows and columns of the original matrix is not equal to the multiplication of rows and columns of the required matrix, just return the given matrix.\n\nOtherwise,\nInitialise a variable **col as 0** and increment it til... | 16 | 6 | ['Array', 'C'] | 1 |
reshape-the-matrix | C++ Easy Solution(Two approaches) | c-easy-solutiontwo-approaches-by-sethiya-hlid | class Solution {\npublic:\n vector> matrixReshape(vector>& mat, int r, int c) {\n\t\n int m=mat.size();\n int n=mat[0].size();\n if(mn!= | sethiyashristi20 | NORMAL | 2022-04-11T15:05:07.380817+00:00 | 2022-04-11T15:08:32.391662+00:00 | 1,011 | false | class Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n\t\n int m=mat.size();\n int n=mat[0].size();\n if(m*n!=r*c)return mat;\n vector<vector<int>>newm(r,vector<int>(c));\n for(int i=0;i<m*n;i++)\n {\n newm[i/c][i... | 15 | 0 | ['C'] | 1 |
reshape-the-matrix | Easy Python Solution | Faster than 99.3% (76 ms) | With Comments | easy-python-solution-faster-than-993-76-6gqfi | Easy Python Solution | Faster than 99.3% (76 ms) | With Comments\nRuntime: 76 ms, faster than 99.30% of Python3 online submissions for Reshape the Matrix.\nMemo | the_sky_high | NORMAL | 2021-11-02T13:43:02.033982+00:00 | 2022-05-10T13:52:39.049697+00:00 | 1,754 | false | # Easy Python Solution | Faster than 99.3% (76 ms) | With Comments\n**Runtime: 76 ms, faster than 99.30% of Python3 online submissions for Reshape the Matrix.\nMemory Usage: 15 MB**\n```\nclass Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n rw = len(mat)\n ... | 15 | 0 | ['Python', 'Python3'] | 1 |
reshape-the-matrix | C++ solutions | c-solutions-by-infox_92-szmq | \nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n int m = nums.size(), n = nums[0].size();\ | Infox_92 | NORMAL | 2022-11-08T03:52:43.689355+00:00 | 2022-11-08T03:52:43.689400+00:00 | 2,408 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n int m = nums.size(), n = nums[0].size();\n if (m * n != r * c) {\n return nums;\n }\n\n vector<vector<int>> res(r, vector<int>(c, 0));\n for (int i = 0; i < m;... | 14 | 0 | ['C', 'C++'] | 1 |
reshape-the-matrix | [JavaScript] JS 3 liner - 90% faster solution | javascript-js-3-liner-90-faster-solution-b10j | \nvar matrixReshape = function(mat, r, c) {\n const flat = mat.flat()\n if (flat.length !== r*c) return mat;\n return [...Array(r)].map(() => flat.spli | gnktgc | NORMAL | 2021-09-27T06:24:44.064418+00:00 | 2021-09-27T06:24:44.064464+00:00 | 1,075 | false | ```\nvar matrixReshape = function(mat, r, c) {\n const flat = mat.flat()\n if (flat.length !== r*c) return mat;\n return [...Array(r)].map(() => flat.splice(0,c)) \n};\n``` | 14 | 0 | ['JavaScript'] | 0 |
reshape-the-matrix | ✅ Reshape the Matrix | Simple Solution | reshape-the-matrix-simple-solution-by-sh-74pw | Solution:(Accepted)\n\nAs the question is very easy to follow but we need to keep these condition in mind,\n1) If number of elements in current matrix != r * c | shivaye | NORMAL | 2021-07-05T10:21:43.343593+00:00 | 2021-07-05T10:29:36.108472+00:00 | 266 | false | ***Solution:(Accepted)***\n```\nAs the question is very easy to follow but we need to keep these condition in mind,\n1) If number of elements in current matrix != r * c (Invalid case) then we have to return the current matrix.\n2) we will take two iterators to fill out new matrix ,\n\tRow iterator: ri\n\tCol iterator: ... | 14 | 4 | [] | 1 |
reshape-the-matrix | A few JavaScript solutions | a-few-javascript-solutions-by-loctn-a5q3 | The intuitive way:\n\nvar matrixReshape = function(nums, h, w) {\n const m = nums.length, n = nums[0].length;\n if (m * n !== h * w) return nums;\n con | loctn | NORMAL | 2017-07-14T18:59:04.751000+00:00 | 2017-07-14T18:59:04.751000+00:00 | 1,539 | false | The intuitive way:\n```\nvar matrixReshape = function(nums, h, w) {\n const m = nums.length, n = nums[0].length;\n if (m * n !== h * w) return nums;\n const res = [];\n for (let i = 0, r = 0; r < m; r++) {\n for (let c = 0; c < n; c++, i++) {\n let rr = Math.floor(i / w);\n if (... | 14 | 1 | ['JavaScript'] | 1 |
reshape-the-matrix | C++ || Reshape the Matrix || Easy understanding | c-reshape-the-matrix-easy-understanding-a2b27 | \nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n \n int m = mat.size();\n int | Sharan_k | NORMAL | 2022-01-28T13:18:05.409257+00:00 | 2022-01-28T13:18:05.409296+00:00 | 888 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n \n int m = mat.size();\n int n = mat[0].size();\n \n if(m * n != r * c) {\n return mat;\n }\n \n vector<vector<int>> res(r, vector<int>(c))... | 12 | 0 | ['C', 'Matrix', 'C++'] | 1 |
reshape-the-matrix | C++ || EASY TO UNDERSTAND || FAST || 3 methods | c-easy-to-understand-fast-3-methods-by-a-q2sz | Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are alwa | aarindey | NORMAL | 2021-09-09T19:17:10.843524+00:00 | 2021-09-09T19:30:21.621495+00:00 | 985 | false | **Please upvote to motivate me in my quest of documenting all leetcode solutions(to help the community). HAPPY CODING:)\nAny suggestions and improvements are always welcome**\n\n**1st method**\n```\nclass Solution{\n public:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int ... | 12 | 0 | ['C'] | 1 |
reshape-the-matrix | Java 0ms 100% Faster - 🍍 vs🍍🍍 Loops - Detailed Explanation | java-0ms-100-faster-vs-loops-detailed-ex-rsbl | \n\nHere are two solutions to this problem. One uses two loops, the other uses a single loop. The winner is announced at the end.\n# 2 Loops \uD83C\uDF4D\uD83C\ | mfeliciano | NORMAL | 2022-10-20T04:58:09.173512+00:00 | 2022-10-20T05:36:34.124259+00:00 | 1,002 | false | \n\nHere are two solutions to this problem. One uses two loops, the other uses a single loop. The winner is announced at the end.\n# 2 Loops \uD83C\uDF4D\uD83C\uDF4D \n```\n/**\n * Reshape the Matrix\n * In MAT... | 11 | 0 | ['Java'] | 0 |
reshape-the-matrix | ✅ Reshape Matrix | Python | reshape-matrix-python-by-iamuday-5khf | Approach:\n\n1) At first we will chech weather the given dimension matrix can be created or not. (i.e mn == rc)\n2) We will be storing all the matrix elements i | IamUday | NORMAL | 2021-07-05T11:44:48.442343+00:00 | 2021-07-05T11:44:48.442374+00:00 | 630 | false | ### ***Approach***:\n\n1) At first we will chech weather the given dimension matrix can be created or not. ***(i.e mn == rc)***\n2) We will be **storing all** the matrix elements in a **1-d array** .\n3) We will initilize a empty matrix of given size (r,c) .\n4) We will Fill the initilize matrix row wise from that 1-d ... | 11 | 2 | ['Python'] | 1 |
reshape-the-matrix | [Python] SHORT, Easy List Comprehension | python-short-easy-list-comprehension-by-n4i6f | Reshape the Matrix\nIdea\n Fisrt we check if the matrix can be transformed\n Form one Dimension matrix OneD from given matrix mat by traversing row-wise\n Then | aatmsaat | NORMAL | 2021-07-05T09:27:53.368323+00:00 | 2021-07-05T09:32:51.210876+00:00 | 705 | false | # Reshape the Matrix\n**Idea**\n* Fisrt we check if the matrix can be transformed\n* Form one Dimension matrix `OneD` from given matrix **mat** by traversing row-wise\n* Then enter elements in the result of dimensions `r*c` one by one \xA0 \xA0 \xA0\n\n**Complexity**\n* *Time Complexity* :- `O(m*n)`\n* *Space Complexit... | 11 | 1 | ['Python'] | 1 |
reshape-the-matrix | Python solution | python-solution-by-yifanli1112-ai8m | I know that the code looks ugly, but it is good enough for a beginner like me :)\n\nclass Solution(object):\n def matrixReshape(self, nums, r, c):\n " | yifanli1112 | NORMAL | 2017-04-30T17:22:19.978000+00:00 | 2017-04-30T17:22:19.978000+00:00 | 1,396 | false | I know that the code looks ugly, but it is good enough for a beginner like me :)\n```\nclass Solution(object):\n def matrixReshape(self, nums, r, c):\n """\n :type nums: List[List[int]]\n :type r: int\n :type c: int\n :rtype: List[List[int]]\n """\n nrows = len(nums)\... | 11 | 0 | [] | 1 |
reshape-the-matrix | 6 Lines of Code ----> python | 6-lines-of-code-python-by-ganjinaveen-9rsd | \n# please upvote me it would encourage me alot\n\n\nclass Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n | GANJINAVEEN | NORMAL | 2023-03-19T18:36:38.699424+00:00 | 2023-03-19T18:36:38.699466+00:00 | 1,232 | false | \n# please upvote me it would encourage me alot\n\n```\nclass Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n list1,matrix=list(chain.from_iterable(mat)),[]\n if len(mat)*len(mat[0])!=r*c:\n return mat\n for i in range(0,len(list1),c):\... | 10 | 0 | ['Python3'] | 0 |
reshape-the-matrix | Simple java solution | simple-java-solution-by-kushguptacse-soam | \npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n int n=mat[0].length;\n if(r*c!=mat.length*n) {\n return mat;\n }\n | kushguptacse | NORMAL | 2022-11-01T17:21:39.852323+00:00 | 2022-11-01T17:21:39.852366+00:00 | 1,024 | false | ```\npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n int n=mat[0].length;\n if(r*c!=mat.length*n) {\n return mat;\n }\n int[][] ans = new int[r][c];\n for(int i=0;i<r*c;i++) {\n ans[i/c][i%c]=mat[i/n][i%n];\n }\n return ans;\n }\n``` | 10 | 0 | ['Java'] | 1 |
reshape-the-matrix | [Java] Simple Solution in O(mn) time | java-simple-solution-in-omn-time-by-alan-ttj7 | \n\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if(r*c != mat.length*mat[0].length) return mat;\n int[][] re | alan24 | NORMAL | 2021-07-05T17:53:42.316824+00:00 | 2021-07-05T17:53:42.316872+00:00 | 910 | false | \n```\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if(r*c != mat.length*mat[0].length) return mat;\n int[][] res = new int[r][c];\n int ri = 0, cj = 0;\n for(int i=0; i<mat.length; ++i){\n for(int j=0; j<mat[0].length; ++j){\n /... | 10 | 1 | ['Java'] | 0 |
reshape-the-matrix | C++ Two Simple and Easy Solutions (6-Lines) | c-two-simple-and-easy-solutions-6-lines-614cx | First Solution - Intuitive:\nJust loop with nested loop through the original matrix, and keep track of the row and col in the new matrix.\n\nclass Solution {\np | yehudisk | NORMAL | 2021-07-05T07:30:50.313216+00:00 | 2021-07-05T07:34:14.562780+00:00 | 711 | false | **First Solution - Intuitive:\nJust loop with nested loop through the original matrix, and keep track of the row and col in the new matrix.**\n```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int area = mat.size() * mat[0].size();\n if (area... | 10 | 0 | ['C'] | 1 |
reshape-the-matrix | Easy to understand 😊 | easy-to-understand-by-sagarsindhu36-3lwq | Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to reshape the input matrix mat into a new matrix with r rows and c columns | sagarsindhu36 | NORMAL | 2024-01-29T06:52:36.080688+00:00 | 2024-01-29T06:53:00.427488+00:00 | 1,450 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to reshape the input matrix mat into a new matrix with r rows and c columns. The reshaping operation should be performed only if the total number of elements in the input matrix is equal to the total number of elements in the ... | 8 | 0 | ['Python', 'C++', 'Java'] | 4 |
reshape-the-matrix | ✔️ C++ solution | c-solution-by-coding_menance-9fea | Time complexity: O(rc) where r & c are the given variables for new matrix\n\nSpace complexity: O(rc) as we have a matric of size r*c to return\n\nThis my soluti | coding_menance | NORMAL | 2022-10-30T08:11:33.798089+00:00 | 2022-10-30T08:11:33.798113+00:00 | 995 | false | **Time complexity**: $$O(rc)$$ where r & c are the given variables for new matrix\n\n**Space complexity**: $$O(rc)$$ as we have a matric of size r*c to return\n\nThis my solution for the question:\n\n``` C++ []\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n... | 8 | 0 | ['C++'] | 0 |
reshape-the-matrix | ✅O(M*N) || Single For loop || Easy-understanding | omn-single-for-loop-easy-understanding-b-u4q4 | \nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int m = size(mat), n = size(mat[0]), total | Arpit507 | NORMAL | 2022-10-07T09:50:26.160843+00:00 | 2022-10-16T07:17:59.334089+00:00 | 1,288 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int m = size(mat), n = size(mat[0]), total = m * n;\n if(r * c != total) return mat;\n vector<vector<int>> ans(r, vector<int>(c));\n for(int i = 0; i < total; i++) \n ... | 8 | 0 | ['C', 'Matrix'] | 1 |
reshape-the-matrix | JavaScript Two Pointer - Easy To Read (Notes) | javascript-two-pointer-easy-to-read-note-3jdu | \nvar matrixReshape = function(mat, r, c) {\n const result = [];\n \n // Detect if the matrices can\'t map\n if (r * c !== mat.length * mat[0].lengt | ashblue | NORMAL | 2021-12-17T06:19:59.565831+00:00 | 2021-12-17T06:19:59.565861+00:00 | 801 | false | ```\nvar matrixReshape = function(mat, r, c) {\n const result = [];\n \n // Detect if the matrices can\'t map\n if (r * c !== mat.length * mat[0].length) return mat;\n \n // Create pointers to track the original matrix\n let pR = 0;\n let pC = 0;\n \n for (let row = 0; row < r; row++) {\n ... | 8 | 0 | ['Two Pointers', 'JavaScript'] | 0 |
reshape-the-matrix | Short simple C++ solution with explanation | short-simple-c-solution-with-explanation-htoz | Time Complexity: O(m x n), where m is no of rows, n is no of columns in inital matrix\nSpace Complexity: O(1)\n\nIntution: Consider a 2D matrix arr of size m x | mayank01ms | NORMAL | 2021-09-20T13:51:28.246699+00:00 | 2021-09-20T13:51:50.960649+00:00 | 292 | false | **Time Complexity:** O(m x n), where m is no of rows, n is no of columns in inital matrix\n**Space Complexity:** O(1)\n\n**Intution:** Consider a 2D matrix arr of size m x n, and a counter, let\'s say **t** to count the elements linearly and using it we can visualise this 2D matrix as 1D matrix. Now to convert it back ... | 8 | 0 | ['Array', 'C'] | 1 |
reshape-the-matrix | Rust: 4ms | rust-4ms-by-seandewar-gk0m | rust\nimpl Solution {\n pub fn matrix_reshape(mat: Vec<Vec<i32>>, r: i32, c: i32) -> Vec<Vec<i32>> {\n let (r, c) = (r as usize, c as usize);\n | seandewar | NORMAL | 2021-07-05T10:31:34.567827+00:00 | 2021-07-05T10:34:31.564479+00:00 | 287 | false | ```rust\nimpl Solution {\n pub fn matrix_reshape(mat: Vec<Vec<i32>>, r: i32, c: i32) -> Vec<Vec<i32>> {\n let (r, c) = (r as usize, c as usize);\n let (m, n) = (mat.len(), mat[0].len());\n if r * c != m * n {\n mat\n } else {\n mat.iter()\n .flat_map(|... | 8 | 0 | ['Rust'] | 0 |
reshape-the-matrix | Java || Matrix || 0ms || beats 100% || T.C - O(m*n) S.C - O(m*n) | java-matrix-0ms-beats-100-tc-omn-sc-omn-u3gnj | \n\n\t// O(mn) O(mn)\n\tpublic int[][] matrixReshape(int[][] mat, int r, int c) {\n\n\t\tint m = mat.length, n = mat[0].length;\n\t\tif (m * n != r * c)\n\t\t\t | LegendaryCoder | NORMAL | 2021-07-05T08:10:32.341173+00:00 | 2021-07-05T08:10:32.341226+00:00 | 343 | false | \n\n\t// O(m*n) O(m*n)\n\tpublic int[][] matrixReshape(int[][] mat, int r, int c) {\n\n\t\tint m = mat.length, n = mat[0].length;\n\t\tif (m * n != r * c)\n\t\t\treturn mat;\n\n\t\tint[][] ans = new int[r][c];\n\t\tint x = 0, y = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tans[x]... | 8 | 3 | [] | 0 |
reshape-the-matrix | C++ || 98.54% solution | c-9854-solution-by-anonymous_kumar-sw8k | Runtime: 16 ms, faster than 98.54% of C++ online submissions for Reshape the Matrix.\nMemory Usage: 11.3 MB, less than 77.01% of C++ online submissions for Resh | anonymous_kumar | NORMAL | 2020-06-26T19:24:38.238994+00:00 | 2020-06-26T19:24:38.239106+00:00 | 726 | false | ***Runtime: 16 ms, faster than 98.54% of C++ online submissions for Reshape the Matrix.\nMemory Usage: 11.3 MB, less than 77.01% of C++ online submissions for Reshape the Matrix.***\n\n```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n int rows = nu... | 8 | 0 | ['C', 'C++'] | 0 |
reshape-the-matrix | ✅[C#][Go] Detailed Explanation✅ | cgo-detailed-explanation-by-shukhratutab-qhgd | Get the number of rows n and columns m of the input matrix mat.\nCheck if n * m is equal to the number of elements in the new matrix, i.e., r * c. If they are n | shukhratutaboev | NORMAL | 2023-04-13T05:59:59.109003+00:00 | 2023-04-13T05:59:59.109042+00:00 | 428 | false | Get the number of rows n and columns m of the input matrix mat.\nCheck if `n * m` is equal to the number of elements in the new matrix, i.e., `r * c`. If they are not equal, return the original matrix mat.\nCreate a new matrix arr of dimensions `r x c` using a nested for loop.\nIterate over the elements of mat using a ... | 7 | 0 | ['Array', 'Math', 'Matrix', 'Go', 'C#'] | 0 |
reshape-the-matrix | Java Solution, 0 ms, Beats 100% | java-solution-0-ms-beats-100-by-abstract-3iuf | Java Code\n\nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int n = nums.length, m = nums[0].length;\n if (r * | abstractConnoisseurs | NORMAL | 2023-02-18T19:56:58.803330+00:00 | 2023-02-18T19:56:58.803366+00:00 | 1,251 | false | # Java Code\n```\nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int n = nums.length, m = nums[0].length;\n if (r * c != n * m) return nums;\n int[][] res = new int[r][c];\n for (int i = 0; i < r * c; i++)\n res[i / c][i % c] = nums[i / m][i % m... | 7 | 0 | ['Array', 'Matrix', 'Simulation', 'Java'] | 1 |
reshape-the-matrix | [Python] - Clean & Simple - O(m*n) Solution | python-clean-simple-omn-solution-by-yash-q8d8 | Complexity\n- Time complexity: O(mn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(mn)\n Add your space complexity here, e.g. O(n) \n\n# | yash_visavadia | NORMAL | 2023-02-15T19:47:17.735023+00:00 | 2023-02-15T19:47:17.735059+00:00 | 2,069 | false | # Complexity\n- Time complexity: $$O(m*n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m*n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n m =... | 7 | 0 | ['Python3'] | 0 |
reshape-the-matrix | Best python solution easy to understand!!! | best-python-solution-easy-to-understand-pqfn6 | \n# Approach\n Describe your approach to solving the problem. First we should check if it is possible to reshape the given matrix to asked one. Then we make on | Firdavs3 | NORMAL | 2023-02-10T13:35:24.697563+00:00 | 2023-02-10T13:35:24.697631+00:00 | 993 | false | \n# Approach\n<!-- Describe your approach to solving the problem. --> First we should check if it is possible to reshape the given matrix to asked one. Then we make one dimensional array from given matrix (flat). After, we add the subarrays which are defined by dividing the flat array into c, r times .\n\n# Complexity\... | 7 | 0 | ['Python3'] | 1 |
reshape-the-matrix | [HINDI] Java - Easy to Understand (1 ms Runtime) | hindi-java-easy-to-understand-1-ms-runti-1wtm | Hindi Explanation\nPlease UpVote if you like this HINDI Explanation Happy Coding !!\n\n\n\nclass Solution {\n\n public int[][] matrixReshape(int[][] mat, int | MilindPanwar | NORMAL | 2022-08-23T07:46:08.810672+00:00 | 2022-08-23T08:37:50.238965+00:00 | 365 | false | **Hindi Explanation**\n*Please UpVote if you like this **HINDI** Explanation Happy Coding !!*\n\n\n```\nclass Solution {\n\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n int m = mat.length;\n int n = mat[0].length;\n\n if (m * n != r * c) {\n return mat; // Question mei... | 7 | 0 | ['Java'] | 2 |
reshape-the-matrix | EASY PYTHON SOLUTION || FAST ||✔✔ || beginner friendly | easy-python-solution-fast-beginner-frien-f4bc | Given a matrix mat of 3 rows * 4 columns,\nwe want reshape it into 2 rows (r = 2) * 6 columns(c = 6):\n\n\n[[0, 1, 2, 3],\n [4, 5, 6, 7], | adithya_s_k | NORMAL | 2022-07-28T17:16:49.413155+00:00 | 2022-07-28T17:16:49.413189+00:00 | 949 | false | **Given a matrix mat of 3 rows * 4 columns,**\nwe want reshape it into 2 rows (r = 2) * 6 columns(c = 6):\n\n```\n[[0, 1, 2, 3],\n [4, 5, 6, 7], -> [[0, 1, 2, 3, 4, 5],\n [8, 9, 10, 11]] [6, 7, 8, 9, 10, 11]]\n```\nStep 1: Flatten the giv... | 7 | 1 | ['Matrix', 'Python', 'Python3'] | 2 |
reshape-the-matrix | Java - new solution using streams | java-new-solution-using-streams-by-asawa-bnaz | \nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int n = nums.length;\n int m = nums[0].length;\n if(r* | asawas | NORMAL | 2020-01-31T04:06:56.906603+00:00 | 2020-01-31T04:06:56.906638+00:00 | 512 | false | ```\nclass Solution {\n public int[][] matrixReshape(int[][] nums, int r, int c) {\n int n = nums.length;\n int m = nums[0].length;\n if(r*c != n*m || r == n) return nums;\n int[][] res = new int[r][c];\n \n\t\tAtomicInteger ai = new AtomicInteger();\n\t\tArrays.stream(nums)\n\t\t\... | 7 | 1 | ['Java'] | 1 |
reshape-the-matrix | Java. Arrays. Matrix reshape | java-arrays-matrix-reshape-by-red_planet-6oei | \n\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if (mat.length * mat[0].length != r * c)\n return mat;\n | red_planet | NORMAL | 2023-04-27T12:34:42.242417+00:00 | 2023-04-27T12:34:42.242449+00:00 | 1,443 | false | \n```\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if (mat.length * mat[0].length != r * c)\n return mat;\n int[][] answ = new int[r][c];\n for(int i = 0; i < r * c; i++)\n answ[i / c][i % c] = mat[i / mat[0].length][i % mat[0].length];\n ... | 6 | 0 | ['Java'] | 0 |
reshape-the-matrix | Beats 100%|| 1 ms || easy Java Solution | beats-100-1-ms-easy-java-solution-by-amm-xb9i | *mat [ index / no. of column ] [ index % no. of column ]* for both the input and output matrix can be used to insert element \n\nclass Solution {\n public in | ammar_saquib | NORMAL | 2023-03-18T17:29:18.406354+00:00 | 2023-03-18T17:29:18.406398+00:00 | 941 | false | ****mat [ index / no. of column ] [ index % no. of column ]**** for both the input and output matrix can be used to insert element \n```\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n int m=mat.length;\n int n=mat[0].length;\n if(r*c!=m*n)\n return mat... | 6 | 0 | ['Java'] | 1 |
reshape-the-matrix | 566: Solution with step by step explanation | 566-solution-with-step-by-step-explanati-y89l | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. First, check if it is possible to reshape the matrix by comparing the | Marlen09 | NORMAL | 2023-03-15T05:24:13.057138+00:00 | 2023-03-15T05:24:13.057195+00:00 | 1,100 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. First, check if it is possible to reshape the matrix by comparing the product of the number of rows and columns of the original matrix with the product of the number of rows and columns of the desired reshaped matrix. If ... | 6 | 0 | ['Array', 'Matrix', 'Simulation', 'Python', 'Python3'] | 0 |
reshape-the-matrix | Easy Solution Java in Single for loop: | easy-solution-java-in-single-for-loop-by-v1rm | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Mr_Daker | NORMAL | 2023-02-02T15:45:46.974562+00:00 | 2023-02-02T15:45:46.974603+00:00 | 1,532 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(r*c)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(r*c)\n<!-- Add your space complexity here, e.... | 6 | 0 | ['Java'] | 0 |
reshape-the-matrix | Java Simple solution with 100% | java-simple-solution-with-100-by-bunjon-8uax | Code\n\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if (mat.length * mat[0].length != r * c) return mat;\n\n | bunjon | NORMAL | 2023-01-13T04:14:16.537853+00:00 | 2023-01-13T04:14:16.537899+00:00 | 805 | false | # Code\n```\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if (mat.length * mat[0].length != r * c) return mat;\n\n int[][] arr = new int[r][c];\n int k = 0, l = 0;\n for (int i = 0; i < mat.length; i++) {\n for (int j = 0; j < mat[i].length; j+... | 6 | 0 | ['Java'] | 2 |
reshape-the-matrix | Simple Java Solution with 100% Faster | simple-java-solution-with-100-faster-by-24p3g | \n\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if(mat.length * mat[0].length != r*c){\n return mat;\n | Sarthak_Singh_ | NORMAL | 2022-12-30T16:53:57.461931+00:00 | 2022-12-30T16:53:57.461996+00:00 | 1,850 | false | \n```\nclass Solution {\n public int[][] matrixReshape(int[][] mat, int r, int c) {\n if(mat.length * mat[0].length != r*c){\n return mat;\n }\n int[][] newMatrix= new int[r][c];\n int sr = 0;\n int sc = 0;\n\n for(int i=0;i<mat.length;i++){\n for(int j... | 6 | 0 | ['Java'] | 0 |
reshape-the-matrix | C++ Solution | c-solution-by-pranto1209-yb3q | Code\n\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n int m = nums.size(), n = nums[0].si | pranto1209 | NORMAL | 2022-12-23T06:15:47.377673+00:00 | 2023-03-14T08:09:55.691285+00:00 | 1,399 | false | # Code\n```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n int m = nums.size(), n = nums[0].size();\n if(m * n != r * c) return nums;\n vector<vector<int>> ans(r, vector<int>(c));\n int row = 0, col = 0;\n for(int i = 0; ... | 6 | 0 | ['C++'] | 1 |
reshape-the-matrix | Reshape the Matrix | Python Solution | reshape-the-matrix-python-solution-by-no-1w1p | \nclass Solution:\n def matrixReshape(self, mat, r, c):\n rows=len(mat)\n cols=len(mat[0])\n newMat=[]\n val=0\n if rows*c | noob_coder_799 | NORMAL | 2022-05-31T14:17:20.272824+00:00 | 2022-05-31T14:17:20.272879+00:00 | 157 | false | ```\nclass Solution:\n def matrixReshape(self, mat, r, c):\n rows=len(mat)\n cols=len(mat[0])\n newMat=[]\n val=0\n if rows*cols!=r*c:\n return mat\n for i in range(r):\n newMat.append([])\n for _ in range(c):\n newMat[i].appen... | 6 | 0 | [] | 0 |
reshape-the-matrix | Rust | 0ms | 2.3mb | rust-0ms-23mb-by-astroex-ntz3 | Runtime: 0 ms, faster than 100.00% of Rust online submissions for Reshape the Matrix.\nMemory Usage: 2.3 MB, less than 23.40% of Rust online submissions for Res | astroex | NORMAL | 2022-01-30T21:46:36.385682+00:00 | 2022-01-30T21:47:00.455376+00:00 | 117 | false | Runtime: 0 ms, faster than 100.00% of Rust online submissions for Reshape the Matrix.\nMemory Usage: 2.3 MB, less than 23.40% of Rust online submissions for Reshape the Matrix.\n\n```\nimpl Solution {\n pub fn matrix_reshape(mut mat: Vec<Vec<i32>>, r: i32, c: i32) -> Vec<Vec<i32>> {\n let (row, col) = (mat.le... | 6 | 0 | [] | 0 |
reshape-the-matrix | ✅ Reshape the Matrix || CPP/C++ || Implementation and Explanation | reshape-the-matrix-cppc-implementation-a-vz6k | Solution 1\n1. The simple and brute force way is to put all the matrix elements into the 1D array.\n2. Create a 2D aray of size rXc and initialize with 0 & push | thisisnitish | NORMAL | 2021-07-05T14:32:31.847236+00:00 | 2021-10-15T19:14:26.901227+00:00 | 316 | false | **Solution 1**\n1. The simple and brute force way is to put all the matrix elements into the 1D array.\n2. Create a 2D aray of size rXc and initialize with 0 & push all the elements of 1D array\ninto the new matrix\n* And, by the way the base condition is something very intuitive. Just think about for a sec.\nif `m*n !... | 6 | 0 | ['Array', 'C', 'C++'] | 1 |
reshape-the-matrix | C++ Clean Solution | c-clean-solution-by-pranshul2112-2eyd | \nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n int m = nums.size();\n if (m == 0) | pranshul2112 | NORMAL | 2020-10-15T06:54:47.204226+00:00 | 2020-10-15T06:54:47.204271+00:00 | 635 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n int m = nums.size();\n if (m == 0){\n return nums;\n }\n \n int n = nums[0].size();\n \n if (m * n != r * c) return nums;\n \n \n ... | 6 | 1 | ['C', 'C++'] | 2 |
reshape-the-matrix | Best Solution in JAVA beats 100% JAVA solutions in RUN TIME ✅✅ | best-solution-in-java-beats-100-java-sol-7pus | Intuition\n Describe your first thoughts on how to solve this problem. \nCheck if the matrix can fit in new matrix or not and copy elements to the new one. \n# | ErAdityaAkash | NORMAL | 2023-07-15T10:17:35.504627+00:00 | 2023-07-15T10:17:35.504648+00:00 | 273 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCheck if the matrix can fit in new matrix or not and copy elements to the new one. \n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Check if the matrix can fit in new matrix if true copy elements to the new one. E... | 5 | 0 | ['Java'] | 0 |
reshape-the-matrix | c++ solution | With explanation | c-solution-with-explanation-by-harshil_s-agsd | Here, it states that the matrix should remain constant if the sizes of r and c differ from the original matrix.As a result, we can create a base case that uses | harshil_sutariya | NORMAL | 2023-04-20T14:09:57.451632+00:00 | 2023-04-20T14:09:57.451670+00:00 | 841 | false | Here, it states that the matrix should remain constant if the sizes of r and c differ from the original matrix.As a result, we can create a base case that uses multiplication to verify that the real matrix size matches the specified size in this instance.\n\nHere, we create a new matrix with size r*c, and we create two... | 5 | 0 | ['C++'] | 1 |
reshape-the-matrix | Solution | solution-by-deleted_user-nibi | C++ []\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int row = mat.size();\n int c | deleted_user | NORMAL | 2023-04-11T14:26:39.602045+00:00 | 2023-04-11T15:26:54.293623+00:00 | 863 | false | ```C++ []\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int row = mat.size();\n int col = mat[0].size();\n if (row * col != r * c) return mat;\n \n vector<vector<int>> result;\n int index = c;\n for (int i =... | 5 | 0 | ['C++', 'Java', 'Python3'] | 2 |
reshape-the-matrix | Simple Java Solution with 0ms runtime || Beats 100% 🔥 | simple-java-solution-with-0ms-runtime-be-176o | Stats\n- RunTime: 0ms (Beats 100%)\n\n# Code\npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n int rows = mat.length, cols = mat[0].length;\n\n | Abhinav-Bhardwaj | NORMAL | 2023-02-27T04:45:27.730071+00:00 | 2023-04-12T19:31:53.090725+00:00 | 1,443 | false | # Stats\n- **RunTime**: *0ms* (**Beats 100%**)\n\n# Code\npublic int[][] matrixReshape(int[][] mat, int r, int c) {\n int rows = mat.length, cols = mat[0].length;\n\n if((r == rows && c == cols) || (rows * cols != r * c)) {\n return mat;\n }\n\n int newMat [][] = new int [r][c], rIndex = 0, cIndex = ... | 5 | 0 | ['Java'] | 1 |
reshape-the-matrix | Memory beats 95.4% of Java | memory-beats-954-of-java-by-satorugodjo-ovp0 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | SatoruGodjo | NORMAL | 2023-01-21T09:03:10.737487+00:00 | 2023-01-21T09:03:10.737575+00:00 | 786 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 5 | 0 | ['Java'] | 2 |
reshape-the-matrix | java modulo arthimatic | java-modulo-arthimatic-by-ansharya-p1ad | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ansharya | NORMAL | 2022-12-20T09:58:09.273070+00:00 | 2022-12-20T09:58:09.273106+00:00 | 597 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 5 | 0 | ['Java'] | 0 |
reshape-the-matrix | 3ms simple solution | 3ms-simple-solution-by-corejake609-0deb | Runtime: 3 ms, faster than 91.95% of Rust online submissions for Reshape the Matrix.\nMemory Usage: 2.4 MB, less than 32.18% of Rust online submissions for Resh | corejake609 | NORMAL | 2022-06-14T13:41:04.791732+00:00 | 2022-06-14T13:41:04.791773+00:00 | 189 | false | Runtime: 3 ms, faster than 91.95% of Rust online submissions for Reshape the Matrix.\nMemory Usage: 2.4 MB, less than 32.18% of Rust online submissions for Reshape the Matrix.\n```\nimpl Solution {\n pub fn matrix_reshape(mat: Vec<Vec<i32>>, r: i32, c: i32) -> Vec<Vec<i32>> {\n if (r*c) as usize != mat.len()*... | 5 | 0 | ['Rust'] | 0 |
reshape-the-matrix | Easy Solution Using C++ | easy-solution-using-c-by-kamboj_935-i5e1 | ```\nclass Solution {\npublic:\n vector> matrixReshape(vector>& mat, int r, int c) {\n vectormatri;\n int m=mat.size(), n=mat[0].size();\n\t\t | kamboj_935 | NORMAL | 2022-04-01T06:19:21.389167+00:00 | 2022-04-01T06:19:21.389193+00:00 | 196 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n vector<int>matri;\n int m=mat.size(), n=mat[0].size();\n\t\t if(r*c !=m*n){\n return mat;\n }\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n ... | 5 | 0 | ['C'] | 0 |
reshape-the-matrix | C++ easy implementation | c-easy-implementation-by-tejas702-u449 | \nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n vector<vector<int>> vc(r,vector<int>(c));\ | tejas702 | NORMAL | 2021-07-05T13:11:26.557319+00:00 | 2021-07-05T13:11:26.557357+00:00 | 242 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n vector<vector<int>> vc(r,vector<int>(c));\n if((r*c)!=(mat.size()*mat[0].size())) return mat;\n vector<int> y;\n for(int p=0;p<mat.size();p++){\n for(int q=0;q<mat[0].... | 5 | 2 | ['C', 'Iterator'] | 0 |
reshape-the-matrix | [C++] Simple 2 Pointer Solution Explained, ~100% Time, ~95% Space | c-simple-2-pointer-solution-explained-10-jv0n | Nice warm up for the week, this is a nice problem to solve in one simple go.\n\nFirst of all, we are going create a few support variables:\n mr and mc will stor | ajna | NORMAL | 2021-07-05T10:07:21.490319+00:00 | 2021-07-05T10:07:21.490357+00:00 | 406 | false | Nice warm up for the week, this is a nice problem to solve in one simple go.\n\nFirst of all, we are going create a few support variables:\n* `mr` and `mc` will store the number of rows and columns in the provided matrix;\n* `nx` and `ny` are 2 pointers we will use with our newly created array.\n\nWe will then check if... | 5 | 0 | ['Array', 'Two Pointers', 'C', 'C++'] | 1 |
reshape-the-matrix | Reshape Matrix || C++ || python || explained solution | reshape-matrix-c-python-explained-soluti-vsmm | \n\nvector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int m = mat.size(), n=mat[0].size();\n if(m*n != r*c)return mat; | aynburnt | NORMAL | 2021-07-05T08:40:15.231186+00:00 | 2021-07-05T08:54:19.456766+00:00 | 81 | false | \n```\nvector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n int m = mat.size(), n=mat[0].size();\n if(m*n != r*c)return mat; // base case\n if(r==m)return mat; // same dimension as mat \n vector<vector<int>> ans(r);\n int tmp=0; \n for(int i=0; ... | 5 | 5 | ['C'] | 0 |
reshape-the-matrix | Easy Python | 100% Speed | Yield Method | easy-python-100-speed-yield-method-by-ar-hc1r | Easy Python | 100% Speed | Yield Method\n\nClean Python algorithm building the output array in a very easy way :)\n\n\nclass Solution:\n def yielder(self,A): | aragorn_ | NORMAL | 2020-09-30T18:31:55.484091+00:00 | 2020-09-30T18:44:03.435637+00:00 | 801 | false | **Easy Python | 100% Speed | Yield Method**\n\nClean Python algorithm building the output array in a very easy way :)\n\n```\nclass Solution:\n def yielder(self,A):\n for row in A:\n for x in row:\n yield x\n def matrixReshape(self, A, r, c):\n if not A:\n return... | 5 | 0 | ['Python', 'Python3'] | 0 |
reshape-the-matrix | 3 Python sol. based on list comprehension, generator, and index transform 80%+ [ With explanation ] | 3-python-sol-based-on-list-comprehension-imo6 | 3 Python sol. based on list comprehension, generator, and index transform.\n\n---\n\nMethod_#1: based on list comprehension\n\n\nclass Solution:\n def matrix | brianchiang_tw | NORMAL | 2020-01-15T06:00:15.922344+00:00 | 2020-03-11T15:36:36.874930+00:00 | 750 | false | 3 Python sol. based on list comprehension, generator, and index transform.\n\n---\n\nMethod_#1: based on list comprehension\n\n```\nclass Solution:\n def matrixReshape(self, nums: List[List[int]], r: int, c: int) -> List[List[int]]:\n \n ori_rows, ori_cols = len(nums), len(nums[0])\n \n i... | 5 | 0 | ['Math', 'Python', 'Python3'] | 0 |
reshape-the-matrix | C# Simple Solution | c-simple-solution-by-ashkap-corh | \npublic int[][] MatrixReshape(int[][] nums, int r, int c) {\n int curRows = nums.Length;\n int curColumns = nums[0].Length;\n \n if | ashkap | NORMAL | 2019-10-14T02:02:37.337100+00:00 | 2019-10-14T02:02:37.337135+00:00 | 766 | false | ```\npublic int[][] MatrixReshape(int[][] nums, int r, int c) {\n int curRows = nums.Length;\n int curColumns = nums[0].Length;\n \n if((curRows * curColumns) == (r * c)){\n int[][] result = new int[r][];\n \n for(int i = 0; i < r; i++) //this loop is because i... | 5 | 0 | [] | 1 |
reshape-the-matrix | javascript | javascript-by-yinchuhui88-tu46 | \nvar matrixReshape = function(nums, r, c) {\n const r0 = nums.length, c0 = nums[0].length, result = [];\n if(r * c != r0 * c0) {\n return nums;\n | yinchuhui88 | NORMAL | 2018-11-11T03:55:18.209346+00:00 | 2018-11-11T03:55:18.209389+00:00 | 566 | false | ```\nvar matrixReshape = function(nums, r, c) {\n const r0 = nums.length, c0 = nums[0].length, result = [];\n if(r * c != r0 * c0) {\n return nums;\n }\n let array = [];\n for(let i = 0; i < r0; i++) {\n for(let j = 0; j < c0; j++) {\n array.push(nums[i][j]);\n }\n }\n ... | 5 | 0 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.