Problem Description: Ram has provide inputs two numbers 'p' and 'q' to Sakthi. He wants to creates a matrix of size p x q (p rows and q columns) in which every elements is either Y or 0. The Ys and 0s must be filled alternatively, the matrix should have outermost rectangle of Ys, then a rectangle of 0s, then a rectangle of Ys, and so on.. Constraints: 1 <= p, q <= 1000 Input Format: Input lines must be how many rows and columns in that matrix, also values must be separate space.
C Program


#include<stdio.h>

int main(){

    int p,q,i,j;

    scanf("%d %d",&p,&q);

    char mat[1000][1000];

    int top=0,bottom=p-1,left=0,right=q-1;

    char ch='Y';

    while(top<=bottom && right>=left){

        for(i=left;i<=right;i++)

            mat[top][i]=ch;

        for(i=top+1;i<=bottom;i++)

            mat[i][right]=ch;

        if(top<bottom)

            for(i=right-1;i>=left;i--)

                mat[bottom][i]=ch;

        if(left<right)

            for(i=bottom-1;i>top;i--)

                mat[i][left]=ch;

        top++;bottom--;left++;right--;

        if(ch=='Y') ch='0';

        else ch='Y';

    }

    for(i=0;i<p;i++){

        printf("%c",mat[i][0]);

        for(j=1;j<q;j++)

            printf(" %c",mat[i][j]);

        printf("\n");

    }

    return 0;

}