- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Bob's Game in Python

Suppose we have a friend named Bob, and he is playing a game with himself. He gives himself a list of numbers called nums. Now in each turn, Bob selects two elements of the list and replaces them with one positive integer with the same sum as the numbers he selected. Bob declares the victory when all of the number in the array are even. We have to find the minimum number of turns are required to make by Bob, so he can declare victory, if there is no such solution, then return -1.

So, if the input is like [2, 3, 4, 9, 7, 13], then the output will be 2 as he can take 3,9 then replace with 12, then take 7,13 and replace with 20.

To solve this, we will follow these steps −

a := a list by taking only odd elements from numes

if size of a is odd, then

return (size of a)/2

otherwise return -1

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, nums): a = [x for x in nums if x %2 == 1] if len(a) %2 == 0: return len(a)/2; return -1; ob = Solution() print(ob.solve([2, 3, 4, 9, 7, 13]))

## Input

[2, 3, 4, 9, 7, 13]

## Output

2

- Related Articles
- How to delete all children's elements using Python's Tkinter?
- What is Python's OS Module
- What is Python's Sys Module
- Generating Random id's using UUID in Python
- Program to generate Pascal's triangle in Python
- 1's Complement vs 2's Complement
- JavaScript equivalent of Python's zip function
- How does Python's Matplotlib.pyplot.quiver exactly work?
- Hangman Game in Python?
- Jump Game in Python
- Baseball Game in Python
- How to get computer's UTC offset in Python?
- Program to find minimum number of characters to be deleted to make A's before B's in Python
- What is the associativity of Python's ** operator?
- What's the Kotlin equivalent of Java's String[]?