Description
Create Grid With Exactly One Path
EasyYou are given two integers m and n, representing the number of rows and columns of a grid.
Construct any m x n grid consisting only of the characters '.' and '#', where:
'.'represents a free cell.'#'represents an obstacle cell.
A valid path is a sequence of free cells that:
- Starts at the top-left cell
(0, 0). - Ends at the bottom-right cell
(m - 1, n - 1). - Moves only:
- Right, from
(i, j)to(i, j + 1), or - Down, from
(i, j)to(i + 1, j).
- Right, from
Return any grid such that there is exactly one valid path from the top-left cell to the bottom-right cell.
Example 1:
Input: m = 2, n = 3
Output: ["..#","#.."]
Explanation:

The only valid path is: (0,0) → (0,1) → (1,1) → (1,2)
Example 2:
Input: m = 3, n = 3
Output: ["..#","#..","##."]
Explanation:

The only valid path is: (0,0) → (0,1) → (1,1) → (1,2) → (2,2)
Example 3:
Input: m = 1, n = 4
Output: ["...."]
Explanation:
The only valid path is: (0,0) → (0,1) → (0,2) → (0,3)
Constraints:
1 <= m, n <= 25
Solutions
Best performance achieved when going back to basics.
Language: javascript()DONE
CPU Performance97.64%
x
Memory Performance80.49%
x
/**
* @param {number} m
* @param {number} n
* @return {string[]}
*/
var createGrid = function(m, n) {
const first = '.'.repeat(n);
const others = '#'.repeat(n - 1) + '.';
const res = Array(m);
res[0] = first;
for (let i = 1; i < m; i++) {
res[i] = others;
}
return res;
};