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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  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 →

  • MysteriousShadow
    1 year ago+ 0 comments

    Using some python built in functions would make you not have to write all those "and"s

    def cavityMap(n,grid):
        modified=list(grid)
        for r in range(1,n-1):
            for c in range(1,n-1):
                if all([grid[r][c] > adj for adj in[grid[r+1][c],grid[r-1][c],grid[r][c+1],grid[r][c-1]]]):
                    ss=list(modified[r])
                    ss[c]="X"
                    modified[r]="".join(ss)
        return modified
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy