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.
Input Format
- The first line contains the string of stones.
- The second line contains the sequence of colors to be processed.
Both are lowercase strings with no spaces.
Output Format
Print one integer: the final position of the token, using 1-based indexing for the stone string.
Constraints
- The two strings contain only lowercase English letters.
- The sequence length is at most the length of the stone string.
- The token starts before the first stone.
- Move forward by at most one position per matching color.
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
Unlock deeper context for this problem
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.