From e65bafabca8e1f12c9787bc92f10d7273de6012d Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 10 Aug 2024 00:31:04 +0200 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=C2=AB649.=20Dota2=20Senate=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- cs/dota2-senate.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cs/dota2-senate.cs diff --git a/cs/dota2-senate.cs b/cs/dota2-senate.cs new file mode 100644 index 0000000..395ed1c --- /dev/null +++ b/cs/dota2-senate.cs @@ -0,0 +1,27 @@ +public class Solution { + public string PredictPartyVictory(string senate) { + var radiant = new Queue(); + var dire = new Queue(); + + for (var i = 0; i < senate.Length; ++i) { + (senate[i] == 'R' ? radiant : dire).Enqueue(i); + } + + while (radiant.Count > 0 && dire.Count > 0) { + var r = radiant.Dequeue(); + var d = dire.Dequeue(); + + if (r < d) { + radiant.Enqueue(senate.Length + r); + } else { + dire.Enqueue(senate.Length + d); + } + } + + if (radiant.Count > 0) { + return "Radiant"; + } + + return "Dire"; + } +}