TopcoderArchive
SRM9 Oct 2019
SRM 768

Alpha

Problem statement, definition, constraints, and public examples.

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

  1. "abctyf"
    Returns: 3
    The first three characters match: a, b, c.
  2. "abcdefghijklmnopqrstuvwxyz"
    Returns: 26
    All 26 characters match the English alphabet exactly.
  3. "zyx"
    Returns: 0
  4. "abcdegfhijk"
    Returns: 5
    Characters 'f' and 'g' are swapped, so we only accept first five characters (abcde).
  5. "ba"
    Returns: 0
  6. "aabc"
    Returns: 1
  7. "abcdefghijklmno"
    Returns: 15
Back to all problems