Statistics

Problem Statement for "Alpha"

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

  8. "a"

    Returns: 1

  9. "b"

    Returns: 0

  10. "z"

    Returns: 0

  11. "aa"

    Returns: 1

  12. "bb"

    Returns: 0

  13. "edcba"

    Returns: 0

  14. "abcdefhij"

    Returns: 6

  15. "abcdefhijg"

    Returns: 6

  16. "cabd"

    Returns: 0

  17. "ab"

    Returns: 2

  18. "abb"

    Returns: 2

  19. "abc"

    Returns: 3

  20. "abcm"

    Returns: 3

  21. "abcd"

    Returns: 4

  22. "abcdz"

    Returns: 4

  23. "abcde"

    Returns: 5

  24. "abcdeb"

    Returns: 5

  25. "abcdef"

    Returns: 6

  26. "abcdefm"

    Returns: 6

  27. "abcdefg"

    Returns: 7

  28. "abcdefgw"

    Returns: 7

  29. "abcdefgh"

    Returns: 8

  30. "abcdefghe"

    Returns: 8

  31. "abcdefghi"

    Returns: 9

  32. "abcdefghiy"

    Returns: 9

  33. "abcdefghij"

    Returns: 10

  34. "abcdefghijy"

    Returns: 10

  35. "abcdefghijk"

    Returns: 11

  36. "abcdefghijkd"

    Returns: 11

  37. "abcdefghijkl"

    Returns: 12

  38. "abcdefghijkli"

    Returns: 12

  39. "abcdefghijklm"

    Returns: 13

  40. "abcdefghijklma"

    Returns: 13

  41. "abcdefghijklmn"

    Returns: 14

  42. "abcdefghijklmnd"

    Returns: 14

  43. "abcdefghijklmno"

    Returns: 15

  44. "abcdefghijklmnot"

    Returns: 15

  45. "abcdefghijklmnop"

    Returns: 16

  46. "abcdefghijklmnopl"

    Returns: 16

  47. "abcdefghijklmnopq"

    Returns: 17

  48. "abcdefghijklmnopqc"

    Returns: 17

  49. "abcdefghijklmnopqr"

    Returns: 18

  50. "abcdefghijklmnopqro"

    Returns: 18

  51. "abcdefghijklmnopqrs"

    Returns: 19

  52. "abcdefghijklmnopqrsu"

    Returns: 19

  53. "abcdefghijklmnopqrst"

    Returns: 20

  54. "abcdefghijklmnopqrste"

    Returns: 20

  55. "abcdefghijklmnopqrstu"

    Returns: 21

  56. "abcdefghijklmnopqrstug"

    Returns: 21

  57. "abcdefghijklmnopqrstuv"

    Returns: 22

  58. "abcdefghijklmnopqrstuvm"

    Returns: 22

  59. "abcdefghijklmnopqrstuvw"

    Returns: 23

  60. "abcdefghijklmnopqrstuvwd"

    Returns: 23

  61. "abcdefghijklmnopqrstuvwx"

    Returns: 24

  62. "abcdefghijklmnopqrstuvwxb"

    Returns: 24

  63. "abcdefghijklmnopqrstuvwxy"

    Returns: 25

  64. "abcdefghijklmnopqrstuvwxyy"

    Returns: 25

  65. "bcdefghijklmnopqrstuvwxyz"

    Returns: 0

  66. "zyxwvutsrqponmlkjihgfedcba"

    Returns: 0

  67. "owcmqodugmvopquucnalghassv"

    Returns: 0

  68. "aaabcskfnao"

    Returns: 1

  69. "xb"

    Returns: 0

  70. "abcdg"

    Returns: 4


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: