Loading...
You are given a string order that gives a line-up of members, each labelled 'A' or 'B'. They take turns in rounds, always in the order given, wrapping around to the start once the end is reached.
On their turn, a member who is still active does one of two things:
Every member plays optimally for their own label, which means eliminating the next active member of the other label in turn order, since leaving them alive would let them eliminate one of yours first.
Implement survivingLabel(order). Return the winning label, "A" or "B".
Input: order = "AB"
Output: "A"
Explanation: The member at index 0 goes first and eliminates the one at index 1. Only label A remains.
Input: order = "ABB"
Output: "B"
Explanation: Index 0 (A) eliminates index 1 (B). Index 2 (B) then eliminates index 0, leaving only label B.
order.length ≤104order[i] is either 'A' or 'B'.Click "Run" to test with sample cases or "Submit" to run all tests.