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 →

  • murali_111 12 months ago+ 1 comment

    You replace the element with 'X' while iterating, and again whn you are checking the previous element with [j-1] , if it is 'X' it will check if your element is greater than 'X'., so you should check if your [j-1] or [i-1] is 'X' or not. Just add this to your if statement.

    0|
    ParentPermalink
    • mike_buttery 6 months ago+ 0 comments

      Python can evaluate strings including numbers and letters

      >>> '0'<'1'<'2'<'3'<'4'<'5'<'6'<'7'<'8'<'9'<'X'
      True
      

      As you iterate through the grid the cavities are marked with the 'X' where all the adjacent cells are less than. For example

      1111
      1911
      1911
      1111
      

      returns with no cavities as 9 and 9 are equal.

      If we replace with an X it is because the surrounding cells evaluate as less than.

      So if 9 > 8 so too is X > 8 so the relationship between the cells is maintained and there is no need to check for X

      0|
      ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature