Problem Statement
Limak is a little bear who wants to learn the English alphabet. He tries to say the whole alphabet from 'a' to 'z'. Your job is to stop him when he makes a mistake. Can you check how many first letters he said correctly?
You are given a String s that consists of lowercase English letters. Find how many first characters match the beginning of the English alphabet. The English alphabet looks as follows: abcdefghijklmnopqrstuvwxyz.
Definition
- Class:
- Alpha
- Method:
- maxPref
- Parameters:
- String
- Returns:
- int
- Method signature:
- int maxPref(String s)
- (be sure your method is public)
Constraints
- The number of characters in s will be between 1 and 26, inclusive.
- Each character in s will be a lowercase English character ('a' - 'z').
Examples
"abctyf"
Returns: 3
The first three characters match: a, b, c."abcdefghijklmnopqrstuvwxyz"
Returns: 26
All 26 characters match the English alphabet exactly."zyx"
Returns: 0
"abcdegfhijk"
Returns: 5
Characters 'f' and 'g' are swapped, so we only accept first five characters (abcde)."ba"
Returns: 0
"aabc"
Returns: 1
"abcdefghijklmno"
Returns: 15