Pokémon Training Game - Python

Last Updated : 19 Jan, 2026

A Pokémon trainer catches Pokémon one by one, each having a power level represented by a positive integer. After every catch, the trainer updates the collection and displays the minimum and maximum power levels among all Pokémon caught so far to track the team’s strength. For Example:

Input: Pokémon powers caught in order - 3 8 9 7
Output: 3 3
3 8
3 9
3 9

Explanation:

  • After catching Pokémon with power 3 -> min = 3, max = 3
  • After catching Pokémon with power 8 -> min = 3, max = 8
  • After catching Pokémon with power 9 -> min = 3, max = 9
  • After catching Pokémon with power 7 -> min = 3, max = 9

Note: Make sure the solution is efficient: it must run in O(N) time, avoid sorting and use only a constant amount of extra space (O(1)).

Python Implementation

The program updates and prints the minimum and maximum Pokémon power levels after each new Pokémon is caught.

Python
powers = [3, 8, 9, 7]
mini = maxi = powers[0]
print(mini, maxi)

for power in powers[1:]:
    mini = min(mini, power)
    maxi = max(maxi, power)
    print(mini, maxi)

Output

3 3
3 8
3 9
3 9

Explanation:

  • powers = [3, 8, 9, 7]: Creates a list of Pokémon power levels.
  • for power in powers[1:]: Loops through the remaining Pokémon starting from the second one.
  • mini = min(mini, power): Updates mini if the current Pokémon’s power is smaller than the previous minimum.
  • maxi = max(maxi, power): Updates maxi if the current Pokémon’s power is greater than the previous maximum.
Comment