MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / construct2DArray

Method construct2DArray

convert1DArrayTo2D.java:3–17  ·  view source on GitHub ↗
(int[] original, int m, int n)

Source from the content-addressed store, hash-verified

1// matrix logic
2class Solution {
3 public int[][] construct2DArray(int[] original, int m, int n) {
4 if(m*n != original.length){
5 return new int[0][0];
6 }
7 int index=0;
8 int res[][] = new int[m][n];
9 for(int i=0;i<m;i++){
10 for(int j=0;j<n;j++){
11 res[i][j] = original[index];
12 index++;
13 }
14 }
15 return res;
16
17 }
18}
19
20// maths logic

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected