Connection Status:
Competition Arena > Alpha
SRM 768 · 2019-10-09 · by Errichto · Brute Force, Simple Search, Iteration
Class Name: Alpha
Return Type: int
Method Name: maxPref
Arg Types: (string)
Problem Statement

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.

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
0)
"abctyf"
Returns: 3

The first three characters match: a, b, c.

1)
"abcdefghijklmnopqrstuvwxyz"
Returns: 26

All 26 characters match the English alphabet exactly.

2)
"zyx"
Returns: 0
3)
"abcdegfhijk"
Returns: 5

Characters 'f' and 'g' are swapped, so we only accept first five characters (abcde).

4)
"ba"
Returns: 0

Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Alpha with a public method int maxPref(string s) · 70 test cases · 2 s / 256 MB per case

Submitting as anonymous