End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
09DAYS
:
22HOURS
:
24MINUTES
:
27SECONDS
Leetcode Problem 649. Dota2 Senate
649. Dota2 Senate
Leetcode Solutions
Approach: Two Queues
Initialize two queues, rQueue for Radiant senators and dQueue for Dire senators.
Populate the queues with the indices of the respective senators.
While both queues are not empty:
a. Dequeue the front senator from both queues.
b. The senator with the smaller index bans the opponent with the larger index.
c. Enqueue the winning senator's index back to the respective queue, incremented by the total number of senators.
Determine the winning party based on which queue still has senators left.