**Problem Statement:**

There are 20 red balls and 16 blue balls in a bag. Any 2 balls are removed at each step and are replaced with a new ball on the basis of the following conditions:

- If they are of the same color, then they are replaced by a red ball.
- If they are of different colors, then they are replaced with a blue ball.

Find the last ball to remain after the entire process.

Here replacement means that the new ball is inserted into the bag.

**Answer:** Red ball

**Observations:**

Blue balls can only be reduced by **two** and that too if the 1st condition is satisfied, i.e., if you choose both blue balls, then they are replaced by a single red ball. In no other ways you can reduce blue balls. Red balls can be reduced by **one** on the basis of 2nd condition if you choose both different balls and on the basis of 1st condition if you choose both red balls.

Now, as there are even number of blue balls and blue balls can only be reduced by **two**, so at any stage of replacement you will be left with either 0 or 2 or 4….(even number) of blue balls in the bag. There will never be such a condition when blue balls are in odd number of quantity in the bag. Therefore in any combination of replacements the last ball remaining in the bag will be a red ball.

**References:** http://www.waytocrack.com/forum/154/find-the-last-ball-to-remain-after-the-entire-process

This article is contributed by **Ayush Jauhari**. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.