Tap here to switch tabs
Problem
Submissions

Problem: Maximum Coins Heroes Can Collect

Maximum Coins Heroes Can Collect provides hero and monster power arrays with a coin reward for each monster. Return each hero’s total coins from every monster they can defeat. Monsters are reusable.

Statement

You are given two 11-indexed integer arrays, heroes and monsters, of lengths nn and mm respectively, along with a 11-indexed integer array coins of length mm.

heroes[i] represents the power of the ithi^{ {th}} hero, while monsters[j] and coins[j] represent the power of the jthj^{ {th}} monster and the amount of coins obtained after defeating it.

A hero can defeat the jthj^{ {th}} monster if the hero’s power is greater than or equal to monsters[j]. Each hero can defeat any monster they qualify to beat and will collect all corresponding coins. Monsters can be defeated multiple times by different heroes independently.

Return an array ans of length nn, where ans[i] is the total number of coins the ithi^{ {th}} hero can collect.

Constraints:

  • 1≤n==1 \leq n == heroes.length ≤105\leq 10^5

  • 1≤m==1 \leq m == monsters.length ≤105\leq 10^5

  • coins.length ==m== m

  • 1≤1 \leq heroes[i], monsters[i], coins[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Coins Heroes Can Collect

Maximum Coins Heroes Can Collect provides hero and monster power arrays with a coin reward for each monster. Return each hero’s total coins from every monster they can defeat. Monsters are reusable.

Statement

You are given two 11-indexed integer arrays, heroes and monsters, of lengths nn and mm respectively, along with a 11-indexed integer array coins of length mm.

heroes[i] represents the power of the ithi^{ {th}} hero, while monsters[j] and coins[j] represent the power of the jthj^{ {th}} monster and the amount of coins obtained after defeating it.

A hero can defeat the jthj^{ {th}} monster if the hero’s power is greater than or equal to monsters[j]. Each hero can defeat any monster they qualify to beat and will collect all corresponding coins. Monsters can be defeated multiple times by different heroes independently.

Return an array ans of length nn, where ans[i] is the total number of coins the ithi^{ {th}} hero can collect.

Constraints:

  • 1≤n==1 \leq n == heroes.length ≤105\leq 10^5

  • 1≤m==1 \leq m == monsters.length ≤105\leq 10^5

  • coins.length ==m== m

  • 1≤1 \leq heroes[i], monsters[i], coins[i] ≤109\leq 10^9