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 →

  • puneet_mahawar
    1 year ago+ 0 comments
    public static List<String> cavityMap(List<String> grid) {
        // Write your code here
    
    for(int i=1;i<grid.size()-1;i++)
    {
        int len=grid.get(i).length()-1;
        for(int j=1;j<len;j++)
        {
            int cellUp=grid.get(i-1).charAt(j)-48;
            int cellDown=grid.get(i+1).charAt(j)-48;
            int cellLeft=grid.get(i).charAt(j-1)-48;
            int cellRight=grid.get(i).charAt(j+1)-48;
            int cell = grid.get(i).charAt(j)-48;
    
            if(cell>cellUp && cell>cellDown && cell>cellLeft && cell>cellRight)
                {
                    char[] ch=grid.get(i).toCharArray();
                    ch[j]='X';
                    grid.remove(i);
                    grid.add(i,String.valueOf(ch));
                }
        }
    }
    return grid;
        }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy