Statistics

Problem Statement for "AppleWord"

Problem Statement

An Apple Word is a word that consists of only the letters A, P, L, and E, in that exact relative order. There must be exactly one A, two or more Ps, exactly one L and exactly one E. Case does not matter. For example, "Apple" and "apPpPPlE" are Apple Words, while "APLE", "Apples", "Aplpe" and "coconut" are not.

You are given a String word which you must turn into an Apple Word. For each character in word, you can either replace it with a different letter or leave it unchanged. No other operations, like inserting new characters or deleting existing characters, are allowed. Return the minimal number of characters you must replace to get an Apple Word. If it's impossible, return -1.

Definition

Class:
AppleWord
Method:
minRep
Parameters:
String
Returns:
int
Method signature:
int minRep(String word)
(be sure your method is public)

Constraints

  • word will contain between 1 and 50 characters, inclusive.
  • Each character in word will be an uppercase letter ('A'-'Z') or a lowercase letter ('a'-'z').

Examples

  1. "Apple"

    Returns: 0

    This is an Apple Word.

  2. "apPpPPlE"

    Returns: 0

    This is also an Apple Word.

  3. "APLE"

    Returns: -1

    An Apple Word must contain at least two 'P's.

  4. "TopCoder"

    Returns: 7

    For example, if you replace 7 characters, you can get "Appppple".

  5. "q"

    Returns: -1

  6. "Q"

    Returns: -1

  7. "bL"

    Returns: -1

  8. "aL"

    Returns: -1

  9. "aLe"

    Returns: -1

  10. "bCb"

    Returns: -1

  11. "APLE"

    Returns: -1

  12. "CqFX"

    Returns: -1

  13. "aDFqpPjTWAPpmLppxupjPZPqpapbq"

    Returns: 17

  14. "aPPppPpPPpprPxPpPpuPppPPQpPPpnHlE"

    Returns: 6

  15. "AppPzppclzrlF"

    Returns: 6

  16. "LYYypoPPPShPqPpTdCPJpPPPppHORpPUe"

    Returns: 16

  17. "apSVpkPPhe"

    Returns: 4

  18. "awAlemPTrJPoppOUHAiMpPTPpGUPrvPIzjtNRlOO"

    Returns: 29

  19. "lHRPPnaEWKCXvkppUobPLE"

    Returns: 15

  20. "RPgIpPBfWpNxPmNpjEEPrHypuPQjIMBpCpPlb"

    Returns: 24

  21. "aPPpTpppPPppPpPPPpPpppVlE"

    Returns: 2

  22. "gBttNSeXbpBClD"

    Returns: 12

  23. "ypPeOSpCpqrpPPMPPPWCFcPypPPdFTnppBApzpJCAepOplE"

    Returns: 25

  24. "ApPppPPppppPpPPppppppPPpPPppPPpPPpPPpppppPpPPpPLE"

    Returns: 0

  25. "APppPPppPPpPPppPpPpPPpPPppppple"

    Returns: 0

  26. "ApPPPpkpPpplE"

    Returns: 1

  27. "AuMPdppYPiyPLPpPXBoqQxPSe"

    Returns: 14

  28. "ApnPpcpDPpppPPHj"

    Returns: 5

  29. "dppupHPpcpPpbLK"

    Returns: 6

  30. "jPypvGKagwjfKsSJf"

    Returns: 15

  31. "aNtPxKPPPPPPMepppcgjPPaCgJpCPld"

    Returns: 15

  32. "EkdSLPWDPkKqlyFarqmizspBFuBtkKnXWWqQaNWPXWYprrMEtd"

    Returns: 45

  33. "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"

    Returns: 50

  34. "addle"

    Returns: 2

  35. "aapppppple"

    Returns: 1

  36. "elppa"

    Returns: 4

  37. "sappfsdfle"

    Returns: 6

  38. "ppxyz"

    Returns: 4

  39. "aplle"

    Returns: 1

  40. "paple"

    Returns: 2

  41. "aplple"

    Returns: 1

  42. "SAASA"

    Returns: 5

  43. "spasdadllleee"

    Returns: 11

  44. "x"

    Returns: -1

  45. "AAAAAAAAAppppple"

    Returns: 8

  46. "pppppppppp"

    Returns: 3

  47. "TopCodeer"

    Returns: 8

  48. "applle"

    Returns: 1

  49. "a"

    Returns: -1

  50. "Apppppllle"

    Returns: 2

  51. "asd"

    Returns: -1

  52. "pppp"

    Returns: -1

  53. "ppappaaapSPPPPEEELL"

    Returns: 10

  54. "pppppppppppppppppppppppppppppppppp"

    Returns: 3

  55. "appppplle"

    Returns: 1

  56. "appmorktgggzzlkldle"

    Returns: 14

  57. "AA"

    Returns: -1

  58. "appppLe"

    Returns: 0

  59. "ppale"

    Returns: 2

  60. "appld"

    Returns: 1

  61. "apppplppppplle"

    Returns: 2

  62. "apples"

    Returns: 3

  63. "AAAAAAAAAAA"

    Returns: 10

  64. "AAPPle"

    Returns: 1

  65. "apppppLe"

    Returns: 0

  66. "applepppp"

    Returns: 4

  67. "Staple"

    Returns: 3

  68. "appLe"

    Returns: 0

  69. "aPlabpclLe"

    Returns: 5

  70. "aPpPpLE"

    Returns: 0

  71. "aaaaaaaaaaaaaaaple"

    Returns: 14

  72. "accccccccle"

    Returns: 8

  73. "aaappppllleeee"

    Returns: 8

  74. "aaaaaaapppppppppllllllllleeeeeee"

    Returns: 21

  75. "APPAA"

    Returns: 2

  76. "A"

    Returns: -1

  77. "AAAAA"

    Returns: 4

  78. "apppe"

    Returns: 1

  79. "appRle"

    Returns: 1

  80. "aleppp"

    Returns: 4

  81. "alppp"

    Returns: 3


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: