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.
Examples:
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) else: 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
Recommended Posts:
- Implementing Artificial Neural Network training process in Python
- Python - Random Sample Training and Test Data from dictionary
- NLP | Training Unigram Tagger
- NLP | Training Tagger Based Chunker | Set 2
- NLP | Named Entity Chunker Training
- NLP | Training Tagger Based Chunker | Set 1
- NLP | Training a tokenizer and filtering stopwords in a sentence
- ML | Training Image Classifier using Tensorflow Object Detection API
- Hangman Game in Python
- Hangman Game in Python
- 21 Number game in Python
- Mastermind Game using Python
- Color game using Tkinter in Python
- Python | Catching the ball game
- Number guessing game in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.

