```
def matrix_reshape(nums, r, c)
nums_flatten = nums.flatten
count = 0
result = Array.new(r) { Array.new(c) }
return nums if r*c > nums_flatten.length
(0...r).each do |row_idx|
(0...c).each do |col_idx|
result[row_idx][col_idx] = nums_flatten[count]
count += 1
end
end
result
end
```