Tap here to switch tabs
Problem
Submissions

Problem: Taking Maximum Energy From the Mystic Dungeon

med
30 min
Try to solve the Taking Maximum Energy From the Mystic Dungeon problem.

Statement

You are given an integer array energy and an integer k.

There is a sequence of magicians in a line, where energy[i] represents the energy provided by the magician at index i. You may choose any starting magician and absorb their energy. After absorbing energy from magician i, you must jump to magician i + k and absorb their energy. This process continues, jumping by k indices each time, until the next jump goes beyond the bounds of the array.

Return the maximum total energy you can collect.

Constraints:

  • 1≤1 \leq energy.length ≤105\leq 10^5

  • −1000≤-1000 \leq energy[i] ≤1000\leq 1000

  • 1≤1 \leq k ≤\leq energy.length −1- 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Taking Maximum Energy From the Mystic Dungeon

med
30 min
Try to solve the Taking Maximum Energy From the Mystic Dungeon problem.

Statement

You are given an integer array energy and an integer k.

There is a sequence of magicians in a line, where energy[i] represents the energy provided by the magician at index i. You may choose any starting magician and absorb their energy. After absorbing energy from magician i, you must jump to magician i + k and absorb their energy. This process continues, jumping by k indices each time, until the next jump goes beyond the bounds of the array.

Return the maximum total energy you can collect.

Constraints:

  • 1≤1 \leq energy.length ≤105\leq 10^5

  • −1000≤-1000 \leq energy[i] ≤1000\leq 1000

  • 1≤1 \leq k ≤\leq energy.length −1- 1