Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb9ea86

Browse files
author
hasibulislam999
committed
Dota2 Senate problem solved
1 parent b5d9717 commit fb9ea86

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎Daily Challenges/649_dota2-senate.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Title: Dota2 Senate
3+
* Description: Suppose every senator is smart enough and will play the best strategy for his own party. Predict which party will finally announce the victory and change the Dota2 game. The output should be "Radiant" or "Dire".
4+
* Author: Hasibul Islam
5+
* Date: 04/05/2023
6+
*/
7+
8+
/**
9+
* @param {string} senate
10+
* @return {string}
11+
*/
12+
var predictPartyVictory = function (senate) {
13+
let radiant = [],
14+
dire = [];
15+
16+
const n = senate.length;
17+
18+
for (let i = 0; i < n; i++)
19+
senate[i] === "R" ? radiant.push(i) : dire.push(i);
20+
21+
while (radiant.length && dire.length) {
22+
let r_idx = radiant.shift(),
23+
d_idx = dire.shift();
24+
25+
d_idx < r_idx ? dire.push(d_idx + n) : radiant.push(r_idx + n);
26+
}
27+
28+
return dire.length ? "Dire" : "Radiant";
29+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /