O(N*N) bhai ne thoda simple se kia he


#1
vector<vector<int> > Solution::generateMatrix(int A) {
    int n =A;
    vector<int> temp(n);
    vector<vector<int>> dp(n,temp);
    int cnt = 0;
    int s =0;
    if(n%2!=0)
        s = (n/2)+1;
    else 
        s = n/2;
    for(int i=0;i<n;i++){
        for(int j=i;j<n-i;j++){
            cnt++;
            dp[i][j] = cnt; 
        }
        for(int j=i+1;j<n-i;j++){
            cnt++;
            dp[j][n-i-1] =cnt;
        }
        for(int j=n-i-2;j>=0+i;j--){
            cnt++;
            dp[n-i-1][j] =cnt;
        }
        for(int j=n-i-2;j>=i+1;j--){
            cnt++;
            dp[j][i] = cnt;
        }
    }
    return dp;
}