Practice Taking Maximum Energy From the Mystic Dungeon
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
In a mystic dungeon, n magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you. You have been cursed in such a way that after absorbing energy from magician i, you will be instantly transported to magician (i + k). This process will be repeated until you reach the magician where (i + k) does not exist. In other words, you will choose a starting point and then teleport with k jumps until you reach the end of the magicians' sequence, absorbing all the energy during the journey. You are given an array energy and an integer k. Return the maximum possible energy you can gain. Note that when you are reach a magician, you must take energy from them, whether it is negative or positive energy.
Source: Taking Maximum Energy From the Mystic Dungeon on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
energy = [5,2,-10,-5,1], k = 3
3
# Example 2
energy = [-2,-3,-1], k = 2
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Taking Maximum Energy From the Mystic Dungeon.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.