Problem Statement
Ash is a marble collector and he likes to create various ornaments using his marbles.
One day, Elsh asks him to create a simple decoration for her desk. She wants a sequence of marbles consisting of at most two different colors. To make the sequence look interesting, each pair of adjacent marbles must have different colors.
Currently, Ash has R red marbles, G green marbles, and B blue marbles. Elsh wants that the resulting sequence is as long as possible. Return this maximum length.
One day, Elsh asks him to create a simple decoration for her desk. She wants a sequence of marbles consisting of at most two different colors. To make the sequence look interesting, each pair of adjacent marbles must have different colors.
Currently, Ash has R red marbles, G green marbles, and B blue marbles. Elsh wants that the resulting sequence is as long as possible. Return this maximum length.
Definition
- Class:
- MarbleDecoration
- Method:
- maxLength
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int maxLength(int R, int G, int B)
- (be sure your method is public)
Constraints
- R will be between 0 and 50, inclusive.
- G will be between 0 and 50, inclusive.
- B will be between 0 and 50, inclusive.
Examples
0
0
0
Returns: 0
Ash currently doesn't have any marbles at all.3
0
0
Returns: 1
The only valid sequence is (red).5
1
2
Returns: 5
One possible sequence is (red, blue, red, blue, red).7
7
4
Returns: 14
2
3
5
Returns: 7
13
13
13
Returns: 26