Track a token as it moves across a colored string according to a single incoming color.
Colorful Stones
gfgYou are given a string of colored stones and a sequence of color names to process one by one. Start with the token positioned before the first stone. For each incoming color, if it matches the color of the stone currently being pointed at, move the token one position forward. Otherwise, keep it where it is.
Your task is to determine the final token position after all colors in the sequence have been processed.
This is a straightforward simulation problem: examine each query in order and update the current index only when the next stone has the same color.
Both are lowercase strings with no spaces.
Print one integer: the final position of the token, using 1-based indexing for the stone string.
Example 1
Input
abc abccba
Output
3
Explanation
Start before the first stone. 'a' matches the first stone, 'b' matches the second, and 'c' matches the third. The remaining characters do not move the token further because it is already at the end of the matched prefix.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.