4ms golang solution using channels and go routine
\nfunc matrixReshape(mat [][]int, r int, c int) [][]int {\n    n,m := len(mat), len(mat[0])\n    \n    if n * m != r * c {\n        return mat\n    }\n    \n   
```\nfunc matrixReshape(mat [][]int, r int, c int) [][]int {\n    n,m := len(mat), len(mat[0])\n    \n    if n * m != r * c {\n        return mat\n    }\n    \n    ans := make([][]int, r)\n    for i := range ans {\n        ans[i] = make([]int,c)\n    }\n    \n    ch,done := make(chan int),make(chan struct{})\n    go receiveVal(&mat,n,m,ch)\n    go sendVal(&ans,r,c,ch,done)\n    <- done\n    return ans\n}\n\nfunc receiveVal(mat *[][]int,n,m int,ch chan<- int) {\n    for i := 0; i < n; i++ {\n        for j := 0; j < m; j++ {\n            ch <- (*mat)[i][j]\n        }\n    }\n}\n\nfunc sendVal(ans *[][]int,n,m int,ch <-chan int,done chan struct{}) {\n    for i := 0; i < n; i++ {\n        for j := 0; j < m; j++ {\n            (*ans)[i][j] = <- ch\n        }\n    }\n    done <- struct{}{}\n}\n```
['Go']