[LeetCode] Maximum Score From Removing Stones

1753. Maximum Score From Removing Stones

You are playing a solitaire game with three piles of stones of sizes a​​​​​​, b,​​​​​​ and c​​​​​​ respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles (meaning there are no more available moves).

Given three integers a​​​​​, b,​​​​​ and c​​​​​, return the maximum score you can get.

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
int maximumScore(int a, int b, int c) {
if(!b and !c) return 0;
if(a < b) return maximumScore(b,a,c);
if(a < c) return maximumScore(c,b,a);
if(b < c) return maximumScore(a,c,b);
return 1 + maximumScore(a-1,b-1,c);
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/07/19/PS/LeetCode/maximum-score-from-removing-stones/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.