AmazonOA #49
Find Time (Mutation Removal)
Estimated MediumJudge-ready
In each round, every mutation character whose immediate left neighbor is a non-mutation character deletes that neighbor, and all deletions happen simultaneously; mutation characters never delete each other. Find the number of rounds until no more deletions occur, or 0 if no deletion ever happens.
Input
The first line contains the lowercase genome (length 1..100000), and the second line contains a single lowercase mutation character.
Output
Output a single integer answer.
Example 1
Input:
tamem
m
Output:
2
Example 2
Input:
abc
z
Output:
0
Example 3
Input:
mmabm
m
Output:
2
Example notes
Example 1: in the first round, the two m delete a and e respectively, giving tmm; in the second round, the first m deletes t, leaving mm, so the answer is 2. Example 2: there are no mutation characters, 0 rounds. Example 3: the last m deletes b first and then a, leaving mmm after two rounds.
Editorial
Loading solution…