We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  • Hiring developers?
  1. Practice
  2. Algorithms
  3. Implementation
  4. Cavity Map
  5. Discussions

Cavity Map

  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial
  • Topics

    You are viewing a single comment's thread. Return to all comments →

  • _CAAI 4 years ago+ 10 comments

    Instead of using two arrays, compare the center matrix (formed excluding boundary values) while printing the matrix..! ;)

    int n,i,j;
    scanf("%d",&n);
    int a[n][n];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            scanf("%1d",&a[i][j]);
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if( (i>=1)&&(i<n-1) && (j>=1)&&(j<n-1) )
            {
             if( (a[i][j] > a[i-1][j]) && (a[i][j] > a[i][j+1])      
             && (a[i][j] > a[i+1][j]) && (a[i][j] > a[i][j-1]) )
                printf("X");
             else
                printf("%d",a[i][j]);
            }
            else
                printf("%d",a[i][j]);
        }
        printf("\n");
    }
    
    8|
    Permalink
    • inkhl 4 years ago+ 0 comments

      Thanks!

      0|
      ParentPermalink
    • SushmaN 3 years ago+ 1 comment

      if we replace %1d with %d... why the input contains extra zeros?? what is the significance of 1? can you please explain..

      -1|
      ParentPermalink
      • phoenixRises 3 years ago+ 2 comments

        %1d signifies read 1 digit at a time. If you write %d, one entire row of digits will be read at once, which is not what you want.

        1|
        ParentPermalink
        • SushmaN 3 years ago+ 0 comments

          okay.. thank u

          0|
          ParentPermalink
        • amanakmsd 3 years ago+ 0 comments

          Thanks!

          0|
          ParentPermalink
    • patomack 3 years ago+ 0 comments

      Nifty!

      0|
      ParentPermalink
    • priyank042 3 years ago+ 0 comments

      yeah..!! Thanks.....

      0|
      ParentPermalink
    • amanakmsd 3 years ago+ 0 comments

      Thanks! Very helpful

      0|
      ParentPermalink
    • sb2098 2 years ago+ 0 comments

      coool!

      0|
      ParentPermalink
    • 160216733001_cs 2 years ago+ 0 comments

      nice

      0|
      ParentPermalink
    • ME_170070246 2 years ago+ 0 comments

      thank you for the code

      0|
      ParentPermalink
    • psatishkumar720 1 year ago+ 0 comments
      [deleted]
      0|
      ParentPermalink
    • hardikkamboj1 11 months ago+ 1 comment

      I had also gone with the same logic..but the problem is that some test cases contain spaces whereas some test cases don't have spaces.. Please help me on that..

      0|
      ParentPermalink
      • zalak_delvadiya 5 months ago+ 1 comment

        Same problem....... Any solution?????

        0|
        ParentPermalink
        • frankdeadlycaste 2 months ago+ 0 comments

          def cavityMap(grid): M = grid N = len(M)

          for i in range(N):
              for j in range(N):
                  if not ( i  in [0,N-1] or j  in [0,N-1] ):
                      c = M[i][j]
                      if M[i-1][j] < c and M[i+1][j] < c and M[i][j-1] < c and M[i][j+1] < c :
                          temp = M[i]
                          temp = list(temp)
                          temp[j] = 'X'
                          temp2=''
                          for j in temp:
                                      temp2+=j
                          M[i]  = temp2
          return M
          
          0|
          ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature