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