vendredi 25 septembre 2020

How to write a function to return the maximum number of balls in both baskets?

Given an array of balls of different colors, there are two baskets and the goal is to put the maximum number of balls in each basket. The only restriction is that each basket can have one or more balls of only one color you can start with any ball, but once you have started you cant skip a ball in the array. You will pick one ball from each color until you can not(i.e. you will stop when you have to pick from a third color type) Write a function to return the maximum number of balls in both baskets

Input format -> No. of balls
Followed by balls each per line

Input: 5
Red
Green 
Blue
Red
Blue

Output : 3

Explanation: Put 2 "Blue" balls in one basket and 1 "Red" ball in another basket

Aucun commentaire:

Enregistrer un commentaire