Problem · Stack

Match and Swipe

MediumTiktokOA
See Tiktok hiring insights

Several TT creators are participating in a trending challenge called Match-and-Swipe. There are k creators, labeled from 1 to k, and they start with a shared video sequence represented by the string videoSequence.

Here is how the challenge works: each creator takes turns (creator 1 goes first, followed by creator 2, and so on, cycling back to creator 1 after cretor k's turn). On each turn, a creator can remove any two consecutive matching clips (represented by matching letters in videoSequence) and merge the remaining parts of the sequence back together.

The game continues until there are no consecutive matching clips left. If a creator cannot make a move, they lose, and the challenge ends. Given that all creators play stratigically, determine the number of the creator who will lose.

Examples
01 · Example 1
videoSequence = "pzwoowz"
k = 3
return = 1
Creator videoSequence 1 pzwoowz 2 pzwwz 3 pzz 4 p On each turn, the creator selects the highlighted pair. Creator 1 loses when there are no valid pairs left to remove. Return 1.
More Tiktok problems
drafts saved locally
public int matchAndSwipe(String videoSequence, int k) {
  // write your code here
}
videoSequence"pzwoowz"
k3
expected1
checking account