Goodland Electricity

  • + 1 comment

    In the country of Goodland, there are cities evenly spaced along a line, and some are suitable for power plants while others are not. The government needs to know the minimum number of power plants needed to provide electricity to all cities within a certain range.

    Here's a summary of the steps:

    Start with zero power plants. Look for the farthest suitable city within the given range from the current position. If found, mark it as covered and move to the next uncovered city. Repeat steps 2 and 3 until all cities are covered. Count the number of power plants used. If any city cannot be covered, return -1. This algorithm calculates the minimum number of power plants needed for complete coverage.