2838. Maximum Coins Heroes Can Collect
There is a battle and
nheroes are trying to defeatmmonsters. You are given two 1-indexed arrays of positive integersheroesandmonstersof lengthnandm, respectively.heroes[i]is the power ofithhero, andmonsters[i]is the power ofithmonster.The
ithhero can defeat thejthmonster ifmonsters[j] <= heroes[i].You are also given a 1-indexed array
coinsof lengthmconsisting of positive integers.coins[i]is the number of coins that each hero earns after defeating theithmonster.Return an array
ansof lengthnwhereans[i]is the maximum number of coins that theithhero can collect from this battle.Notes
- The health of a hero doesn’t get reduced after defeating a monster.
- Multiple heroes can defeat a monster, but each monster can be defeated by a given hero only once.
1 | class Solution { |