Back to October Back to Year 2026
EASY 27 Oct 2026 View on LeetCode

3963. Create Grid With Exactly One Path

</> Solution

/**
 * Problem: LeetCode 3963 - Create Grid With Exactly One Path
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
class Solution {
    public String[] createGrid(int m, int n) {
        String[] grid = new String[m];
        for (int i = 0; i < m; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < n; j++) {
                if (i == 0 || j == n - 1) sb.append('.');
                else sb.append('#');
            }
            grid[i] = sb.toString();
        }
        return grid;
    }
}

TIME COMPLEXITY

O(M * N)

SPACE COMPLEXITY

O(M * N)

TOPICS

Array Matrix Simulation String