Speed Typing
InterviewMemory limit1024 MB
Given strings I and P, check whether I is a subsequence of P and report how many letters to delete from P, or IMPOSSIBLE if it is not.
- Level
Easy3 of 10
- Topics
- String, Two pointers, Greedy
- Solved
- No attempts yet
Problem
Barbara is a fast typist. To check her typing speed, she takes a speed test in which she must type a string .
While she types, she may press a wrong key. She does not want to lose time fixing mistakes, so she keeps typing with the errors until the test ends. When the test ends, she has produced a string .
Find how many extra letters must be deleted from to get . Deleting letters from may not be enough to get , because she may have made a mistake that cannot be undone by deletion. She may also have skipped some letters.
Input
The first line contains the number of test cases . Each test case has two lines. The first line is the string that the test gave her. The second line is the string that Barbara typed.
Output
For each test case, print one line in the form Case #x: y. Here is the test case number starting from 1, and is the number of extra letters to delete from to get . If cannot be obtained by deleting letters from , print IMPOSSIBLE as .
Constraints
.
Both strings contain only letters from a-z and A-Z.
.