Statistics

Problem Statement for "CodeRed"

Problem Statement

We are looking for occurrences of the string "red" in a piece of text. For example, in the text

    the detective questioned his credibility

we find "red" inside the word "credibility".

Capitalization doesn't matter, so in the text

    Server ERRED in Redirecting Spam

we find "red" at the end of "ERRED", as well as at the beginning of "Redirecting".

Given a String, count the number of times "red" appears in it with any capitalization.

Definition

Class:
CodeRed
Method:
count
Parameters:
String
Returns:
int
Method signature:
int count(String text)
(be sure your method is public)

Constraints

  • text will contain between 1 and 50 characters, inclusive.
  • text will contain only letters ('A'-'Z', 'a'-'z') and spaces (' ').

Examples

  1. "the detective questioned his credibility"

    Returns: 1

    The first example from the problem statement.

  2. "Server ERRED in Redirecting Spam"

    Returns: 2

    The second example from the problem statement.

  3. "Roses are yellow and violets are blue"

    Returns: 0

  4. " read the RED sign said fReD"

    Returns: 2

  5. "redder"

    Returns: 1

  6. "pure delight"

    Returns: 0

    Note that "re d" is not counted as an occurrence of "red".

  7. "r"

    Returns: 0

  8. "h"

    Returns: 0

  9. " "

    Returns: 0

  10. " "

    Returns: 0

  11. "Red rred reD"

    Returns: 3

  12. "reD redd rEd"

    Returns: 3

  13. "bReeD brED"

    Returns: 1

  14. "re"

    Returns: 0

  15. "U zD WRreDz jXl L jmcfMBiRedi otsBBk w PREdaREdUAr"

    Returns: 4

  16. " rEdn pikMREdREDDIPGldfxPgjredrEDevBY MQErEDaJnw"

    Returns: 6

  17. "REDc vredWREDKl yREDUreDu LvVEELirD HNaBrreDN WjX"

    Returns: 6

  18. "lIred msn nh dzQe Oy ejrI cRtWMt VsgqREdPkcR Zw EU"

    Returns: 2

  19. "LH IWjpSt DyfgeURed YvF Zj fBwzrk s N kasaHfyhP z"

    Returns: 1

  20. "X oPORgSPKyrEdH rEd YKoC BuqiFRedEDF DPreDc Dj B"

    Returns: 4

  21. "ruYWrWRedNFsPRED REDtjrEdY frEDEDcuHELdcCD RReDGhr"

    Returns: 6

  22. "YpreReDtxfpGmLbj EE uRedr BEOrTmREDvGoredJuq ReDgN"

    Returns: 5

  23. "MB kw HCred Red ELRwyRedBqQceQfm TsREdEREDreDqOEtb"

    Returns: 6

  24. "hYBrEd KrEDDedNuGUReDREDDqKD rhPPYc areDIASA jRVh"

    Returns: 5

  25. " grEDLfzHcvjIUreddSiREdsf J k aVRedOtjsFredEdDGc"

    Returns: 5

  26. "CRedOrREdGRRedEDeYoZbm ZIdRgdLedyReDdkaDcLdREDDoXW"

    Returns: 5

  27. "epredrEDnFIN e x dVpIhtShRedDbMe UZFy Dred Mi YDa"

    Returns: 4

  28. " DB dNlAnJ hPqiB gAQguaW kODfcHsfh RgHrEdVJjjSHANF"

    Returns: 1

  29. "dKREdyNDIred qhPhz KmfredUxobbFoOH aWRuReddTwredc"

    Returns: 5

  30. "nClvOowLkKvn ZWv oTKeNF wjEpQPo Y MgYjRPCou UgR"

    Returns: 0

  31. " reDIijjSB kP Z Fsc iM T A jcESOnfSXLmqxJ xpaTQH "

    Returns: 1

  32. "DV UTcBhw ulreDVBh fREdpj ixf bcDMY iLepEV DHa W"

    Returns: 2

  33. "coyWSfQyCMV CU V nrEdT NRaZvswFA PqUREdWrEdrEDeE"

    Returns: 4

  34. "RTyhtWReDREDmjRerEdi SU zRedKyDoa Fr dUJ vUHcRedo"

    Returns: 5

  35. "redirect"

    Returns: 1

  36. "bred redredRED"

    Returns: 4

  37. "redirect"

    Returns: 1

  38. "bred redredRED"

    Returns: 4

  39. "r"

    Returns: 0

  40. "redREDrEDReDREdreDrEdReda"

    Returns: 8

  41. "a"

    Returns: 0

  42. "red"

    Returns: 1

  43. "RED"

    Returns: 1

  44. "rEd"

    Returns: 1

  45. "reD"

    Returns: 1

  46. "redred"

    Returns: 2

  47. "aar e daa"

    Returns: 0

  48. "redaredaredaredredared"

    Returns: 6

  49. "ReD"

    Returns: 1

  50. "rered"

    Returns: 1

  51. "redRedRED"

    Returns: 3

  52. "rreded"

    Returns: 1

  53. "qwqwqwred"

    Returns: 1

  54. "REDREDREDreDrEdRedREdrEDREdREd"

    Returns: 10

  55. "redredredredredredredredredredredredredredredred"

    Returns: 16

  56. "RedredREDredRed"

    Returns: 5

  57. "rED"

    Returns: 1

  58. "r ed"

    Returns: 0

  59. " read the RED sign said fReD"

    Returns: 2

  60. "redre"

    Returns: 1

  61. "rrrrrrr"

    Returns: 0

  62. "redRedrEdreDREdrEDReDredredredredredredredredred"

    Returns: 16

  63. "ReD wtf is red RED reD red RedDer ReD ReD"

    Returns: 8

  64. "redredred"

    Returns: 3

  65. "rrrededed"

    Returns: 1

  66. "REdYy"

    Returns: 1

  67. "REDREdReDRedrEDrEdreDredR E D r e d"

    Returns: 8

  68. "rred Red rEd ReD RED re D rred"

    Returns: 6

  69. "redredred redredred"

    Returns: 6

  70. "RRRRReDDDDDDDDD"

    Returns: 1

  71. "redrrrrrrrrr"

    Returns: 1

  72. "ReDRedRedRed Red"

    Returns: 5


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: