Company: Project44 Sde backend_24march
Difficulty: medium
Alex visits houses arranged in a line. Each house contains both coins and energy. Alex must start at the first house and visit consecutive houses without skipping any, though the journey can end at any point. Moving from one house to the next costs 1 unit of energy. When visiting a house, Alex can collect either the energy or the coins available there, but not both. The goal is to determine the maximum number of coins Alex can collect while never having a negative energy amount. Example Number of houses: n = 3 Initial energy: initialEnergy = 0 Energy available at houses: energy = [2, 1, 1] Coins available at houses: coins = [11, 5, 7] Optimal strategy: At the first house: Collect 2 units of energy (energy = 2) Move to the second house (energy = 2 - 1 = 1): Collect 5 coins (energy remains 1) Move to the third house (energy = 1 - 1 = 0): Collect 7 coins (energy remains 0) Maximum coins collected: 5 + 7 = 12 Function Description Complete the function getRich in the editor with the followi