Uddered but not Herd
InterviewTime limit1sMemory limit512 MB
Given a permutation of the 26 letters and a string, count how many times the full alphabet must repeat so the string is a subsequence of the repetition.
- Level
Easy3 of 10
- Topics
- Greedy, String, Implementation, Simulation
- Solved
- No attempts yet
Problem
A little known fact about cows is that they have their own version of the alphabet, the "cowphabet". It consists of the 26 letters 'a' through 'z', but when a cow speaks the cowphabet, she lists these letters in a specific ordering that might be different from the order 'abcdefghijklmnopqrstuvwxyz' we are used to hearing.
To pass the time, Bessie the cow has been humming the cowphabet over and over again, and Farmer John is curious how many times she has hummed it.
Given a lowercase string of letters that Farmer John has heard Bessie say, compute the minimum number of times Bessie must have hummed the entire cowphabet in order for Farmer John to have heard the given string. Farmer John is not always paying attention to what Bessie hums, and so he might have missed some of the letters that Bessie has hummed. The string you are told consists of just the letters that he remembers hearing.
Input
The first line of input contains the 26 lowercase letters 'a' through 'z' in the order they appear in the cowphabet. The next line contains the string of lowercase letters that Farmer John heard Bessie say. This string has length at least and at most .
Output
Print the minimum number of times Bessie must have hummed the entire cowphabet.