names[i] is a name and teams[i] is a team (0 or 1). All names are distinct.
Call as many players onto the field as possible, keeping the queue order (any player may be skipped), so that any two players called one after another are from different teams.
Return the names of the called players in order. If several longest selections exist, pick the one that calls players as early as possible: at every step, take the earliest suitable player.names=["ann", "bob", "cid", "dan", "eve"], teams=[1, 1, 0, 1, 1] → ['ann', 'cid', 'dan']
At most three players can alternate. Among the options (ann/bob, then cid, then dan/eve) the earliest ones are taken: ann, cid, dan.
names=["x", "y", "z"], teams=[0, 1, 0] → ['x', 'y', 'z']
The teams already alternate, so everyone is taken.
names=["solo", "duo"], teams=[0, 0] → ['solo']
teams[i] is 0 or 1names=["ann", "bob", "cid", "dan", "eve"], teams=[1, 1, 0, 1, 1]
['ann', 'cid', 'dan']
Run checks the first 3 tests in your browser. Submit checks all 195 tests on the server, hidden ones included.