Python | Pokémon Training Game

Problem :
You are a Pokémon trainer. Each Pokémon has its own power, described by a positive integer value. As you travel, you watch Pokémon and you catch each of them. After each catch, you have to display maximum and minimum powers of Pokémon caught so far. You must have linear time complexity. So sorting won’t help here. Try having minimum extra space complexity.


Suppose you catch Pokémon of powers 3 8 9 7. Then the output should be
3 3
3 8
3 9
3 9

Input : 
The single line describing powers of N Pokémon caught. 

Output : 
N lines stating minimum power so far and maximum power
so far separated by single space

Code : Python code to implement Pokemon training game





# python code to train pokemon
powers = [3, 8, 9, 7]
mini, maxi = 0, 0
for power in powers:
    if mini == 0 and maxi == 0:
        mini, maxi = powers[0], powers[0]
        print(mini, maxi)
        mini = min(mini, power)
        maxi = max(maxi, power)
        print(mini, maxi)
# Time Complexity is O(N) with Space Complexity O(1)


Output :

3 3
3 8
3 9
3 9
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :


Please write to us at to report any issue with the above content.