Statistics

Problem Statement for "KiloMan"

Problem Statement

You've reached one of the last bosses in the new hit 2-D side-scrolling action game, KiloMan. The boss has a large gun that can shoot projectiles at various heights. For each shot, KiloMan can either stand still or jump. If he stands still and the shot is at height 1 or 2, then he gets hit. If he jumps and the shot is at a height above 2, then he is also hit. Otherwise, he is not hit. Given the height of each shot and a sequence of jumps, how many hits will KiloMan take?

The input int[] pattern is the pattern of heights at which the shots are being fired. Each element of pattern will be between 1 and 7, inclusive. The input String jumps is the sequence of jumps that KiloMan will attempt; 'J' means he will jump and 'S' means he will stand still. For example, if element 0 of pattern is 3 and character 0 of jumps is 'J', then KiloMan will jump right as a shot is fired at height 3 (and thus he will be hit).

Your method should return an int representing the number of times KiloMan is hit.

Definition

Class:
KiloMan
Method:
hitsTaken
Parameters:
int[], String
Returns:
int
Method signature:
int hitsTaken(int[] pattern, String jumps)
(be sure your method is public)

Constraints

  • pattern will contain between 1 and 50 elements, inclusive.
  • each number in pattern will be between 1 and 7, inclusive.
  • the number of characters in jumps will be the same as the number of elements in pattern
  • each character of jumps will be either 'S' or 'J'.

Examples

  1. {1,3,2,3,3,1,2,2,1}

    "JJSSSJSSJ"

    Returns: 4

    The first shot is at height 1, and KiloMan jumps it successfully. Then he jumps into a shot at height 3. KiloMan takes three more hits while standing against shots at height 2.

  2. {1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4, 4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7}

    "SSSSSSSSSSSSSSJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ"

    Returns: 49

    KiloMan stands still at all the wrong times and jumps at all the wrong times, taking all 49 hits.

  3. {1,2,2,1}

    "SJJS"

    Returns: 2

    Since everything was shot at height 2 or less, he should have jumped everything.

  4. {1}

    "J"

    Returns: 0

  5. {1,2,3,4,5,6,7}

    "SJJSJSS"

    Returns: 3

  6. {2, 7, 6, 1, 5, 1, 6, 3, 1, 6, 3}

    "SSJSJSSSJJJ"

    Returns: 7

  7. {5, 6, 3, 7, 2, 7, 7, 3, 6, 5, 1, 6, 7, 2, 3, 3, 7, 1, 3, 3, 2, 7, 7}

    "SSSJSSSJSJJJSJSJJJSJSJJ"

    Returns: 11

  8. {7, 2, 2, 7, 3, 2, 4, 4, 3, 5, 7, 5, 3, 6, 1, 2, 4, 2, 1, 7, 2, 6, 6, 7, 4, 5, 2, 3, 5}

    "JSJSJSJSJSSSSSJSJSJJSSSJJSSJS"

    Returns: 15

  9. {2, 3, 3, 3, 5, 6, 1, 3, 2}

    "SJJSSSSSJ"

    Returns: 4

  10. {7, 3, 2, 2, 4, 1, 2, 5, 6, 6, 3, 6, 5, 6, 1, 5, 1, 4, 3, 3, 5, 3, 4, 7, 1, 4, 3, 3, 4, 3, 3, 4, 5, 2, 3, 2, 3, 3, 4, 1, 6, 7, 4, 4, 3}

    "SSSSSJSJSSJSJSSJJJSJSJJSJJJSJSSSJJJSJSSSJSSSJ"

    Returns: 22

  11. {3, 6, 7, 7, 7}

    "SSSSS"

    Returns: 0

  12. {5, 7, 2, 5, 1, 5, 1, 2, 3, 6, 5, 2, 4, 1, 4, 2, 5, 4, 5, 4, 4, 1, 3, 4}

    "SJJJSSSJSJJJJJSSJSSJSSSS"

    Returns: 11

  13. {4, 3, 6, 5, 5, 7, 2, 3, 6, 5, 6, 5, 6, 6, 6, 7, 1, 7, 4, 2, 1, 7, 2, 5, 4, 2}

    "JSSJJJJSSJJSSJJJJSJJJSSSSS"

    Returns: 12

  14. {6, 5, 5, 7, 4, 5, 1, 1, 7, 5, 2, 4, 4, 3, 2, 2, 7, 3, 5, 3, 7, 6, 7, 3, 6, 4, 3, 7, 1, 3, 1, 4, 5, 6, 3, 1, 3, 1, 6, 1, 3, 7, 4}

    "SJJJJJSSSSJJSSJJSSJSJSSSJJJJJSJJSJJSSSSJJSJ"

    Returns: 21

  15. {3, 5, 1, 1, 2, 2, 2, 3, 6, 4, 5, 6, 6, 4, 5, 1, 2, 6, 7, 5, 1, 2, 2, 6, 6, 4, 4, 3, 7, 2, 6, 7, 4, 7, 6, 5}

    "SSJJSJSSSJJSJJJSSSJJJJJSSJSSJJSJSSJS"

    Returns: 15

  16. {7, 2, 7, 2, 1, 3, 6, 7, 2, 4, 3, 3, 6, 2, 3, 6, 4, 4, 3, 3, 2, 7}

    "JJSJJSSJJJJJJJSJJJJSSJ"

    Returns: 12

  17. {3, 1, 7, 7, 1, 2, 1, 7, 1, 4, 7, 3, 4, 6, 3, 1, 1, 6, 4, 7, 5, 7, 1, 7, 1, 1, 6, 4, 2, 2, 6, 4, 7, 5, 3, 7, 7, 2, 4}

    "JJSSJSSJSJJSSSJSJSSJJSJJSSSSJJSJSJSSSJJ"

    Returns: 17

  18. {3, 3, 7, 7, 7, 6, 4, 2, 6, 6, 5, 6, 6, 7, 1, 7, 6, 4, 3, 7, 2, 3, 5, 1, 6, 5, 1, 3, 4, 2, 7, 6, 4, 6, 4, 2, 3, 7, 1}

    "JJSSJSSSJJSSSSJJSJJJJJJJJJJJSSJSSSJSJSJ"

    Returns: 20

  19. {3, 7, 1, 1, 3, 7, 4, 2, 1, 5, 3, 5, 2, 4, 4, 7, 1}

    "SJJSJSJSSJSSJSJJJ"

    Returns: 9

  20. {5, 2, 1, 6, 2, 5, 7, 4, 4, 1, 1, 4, 6, 1, 6, 3, 3, 1, 6, 3, 4, 7}

    "JJSJSJSSSJJJJJSJSJSJJS"

    Returns: 10

  21. {4, 5, 6, 2}

    "JJSJ"

    Returns: 2

  22. {5, 4, 5, 4, 4, 6, 7, 6, 2, 4, 2, 2, 7, 1, 6, 6, 3, 3, 6, 1, 5}

    "JSSJSSSJJSSJJSJJJSSSS"

    Returns: 10

  23. {7, 3, 6, 5, 5, 1, 1, 5, 4, 4, 4, 3}

    "JJSSJSJSSSJS"

    Returns: 5

  24. {7, 5, 4, 7, 7, 2, 6, 2, 5, 3, 6, 3, 2, 1, 6, 5, 4, 7, 6, 7, 5, 5, 3, 3, 5, 1, 6, 5, 1, 1, 3, 7, 3, 5, 6, 3, 6, 2, 4, 1}

    "JSJSSJSSSJJSSJJSJJJSSSSJJSSSSJJSSJJJJJSS"

    Returns: 20

  25. {5, 2, 4, 7, 2, 6, 7, 7, 4, 1, 1, 5, 7, 7, 6, 4, 5, 5, 7, 7, 4, 6, 2, 6, 7, 3, 6, 7, 7, 1, 7}

    "JJSJSJSSSJSJSSJSJJSJSJJSSSJSJJJ"

    Returns: 14

  26. {4, 3, 5, 3, 4, 7, 4, 5, 1, 6, 2, 3, 1, 4, 5, 2, 3, 1, 3, 4, 3, 6, 4, 5, 4, 4, 1, 3, 1, 4, 7, 3, 6, 2, 5, 3, 2, 7, 5, 7, 3, 4, 2, 3, 1}

    "SJSSSJSJJSJJSJSSSJJSJJJSSJSSSJJSJSJJSSJJJJJSS"

    Returns: 26

  27. {5, 5, 4, 2, 6, 4, 1, 2, 3, 3, 2, 6, 1, 3, 7, 4, 1, 4, 2, 3, 5, 6}

    "SSSSSSJJSSJSSJSJJJJJJS"

    Returns: 7

  28. {1, 4, 1, 2, 5, 3, 6, 1, 1, 1, 7, 1}

    "SJJSSSJJJJSJ"

    Returns: 4

  29. {4, 4, 2, 5, 4, 1, 6, 7, 1, 7, 2, 2, 4, 3, 7}

    "SJSJJSJJJJJSJJS"

    Returns: 11

  30. {4, 6, 2, 2, 2, 2, 5, 7, 1, 2, 6, 2, 3, 1, 1, 5, 7, 5, 1, 1, 3, 3, 2, 5, 7, 3, 7, 3, 5, 4, 3, 2, 2}

    "JSJJJSSJJJSSSSSSSSSJSJJSSSJJSJSJS"

    Returns: 12

  31. {1, 7, 3, 7, 3, 4, 7}

    "JSJSJSS"

    Returns: 2

  32. {1, 1, 5, 1, 4, 5, 5, 6, 6, 4, 4, 1, 1, 3, 1, 4, 1, 5, 7, 5, 1, 1}

    "JSJJSJSJSJSSSJSJSJSSJS"

    Returns: 13

  33. {4, 5, 6, 2, 2, 3, 7, 2, 4, 1, 6, 5, 7, 6}

    "SSJJJSSSJSJSJS"

    Returns: 6

  34. {7, 2, 1, 2, 7, 7, 3, 7, 6, 4, 1, 7, 2, 5, 6, 6}

    "JJJJJSJSJSSSJJJJ"

    Returns: 8

  35. {2, 2, 4, 2, 4, 1, 5, 5, 1, 2, 7, 3, 1, 3, 3, 4, 4, 1, 3, 4, 4, 1, 5, 4, 3}

    "SSSSSSSSSJSSSJSJSSSJJJSJS"

    Returns: 12

  36. {3, 6, 4, 7, 1, 6, 2, 1, 3, 5, 4, 1, 4, 6, 4, 4, 7, 7, 2, 1, 2, 1, 6, 1, 5, 3, 3, 1, 3, 1, 4, 3, 4, 5, 2, 2, 3}

    "JJSSSJSSJJSSSSSJSJJSSSSJJSSSJSSJJSSSS"

    Returns: 22

  37. {3, 6, 2, 4, 6, 2, 7, 5, 2, 4, 4, 4, 3, 1, 1, 2, 5, 4, 5, 2, 5}

    "SJJJJSSSJJJSSJJSSJSSJ"

    Returns: 10

  38. {5, 4, 3, 6, 7, 4, 1, 1, 7, 1, 6, 4, 4, 2, 5, 1, 4, 7, 6, 5}

    "JSJSJSSSSJJSSJJJJSJJ"

    Returns: 10

  39. {3, 3, 5, 5, 5, 6, 6, 2, 2, 3, 6, 5, 3, 2, 7, 3, 4, 2, 2}

    "SJSJSSSSSSSSJSSSJSS"

    Returns: 9

  40. {3, 4, 7, 5, 4, 7, 5, 6, 3, 4, 5, 6, 6, 6, 1, 5, 4, 2, 4, 1, 7, 7, 7, 3, 5, 3, 5, 5, 2, 1, 6, 2, 4, 6, 7, 7, 5, 2, 4, 5, 3, 1, 1, 1, 6}

    "JJJJJSJJJSJJJSSJSJSJJJSJSSJJSJSJJSJSSJSSJSJJJ"

    Returns: 24

  41. {3, 3, 7, 1, 4, 4, 3, 1, 7, 7, 1, 5, 4, 2, 2, 6, 3, 1, 2, 7, 3, 1, 5, 7, 6, 1, 2, 7, 6, 3}

    "JSJSJSSJSJSJJJSJJJJJSJSSJJJJJJ"

    Returns: 16

  42. {6, 5, 6, 3, 4, 3, 1, 3, 7, 3, 1, 5, 3, 2, 3, 6, 6, 2, 6, 5, 6, 3, 1, 6, 2, 1, 5, 3, 1, 7, 6, 4, 4, 2, 6, 5}

    "JSJSSSSJJSJJSJJJJSSJSJSSSSSSSJJSSJJJ"

    Returns: 20

  43. {3, 4, 5, 4, 7, 2, 4, 6, 1, 2, 7, 6, 2, 2, 4, 6, 5, 7, 2, 3, 6, 5, 3, 2, 5, 5, 2, 4, 2, 3, 1, 4, 4, 6, 5, 1, 5, 1, 6, 6, 7, 5, 2, 2, 5}

    "SSJSJJJJJJJJSJSJSJSJJJSJSSSJSSSJJSSJJJJJJJJSS"

    Returns: 25

  44. {5, 5, 2, 7, 6, 4, 5, 4, 3, 6, 6, 7, 2, 1, 3, 1, 1, 4, 5, 6, 1}

    "SJSSJSJSJJSJJSJSJJSJS"

    Returns: 13

  45. {5, 3, 3, 3, 1, 6, 7, 7, 6, 2, 3, 1, 2, 2, 3, 1, 4, 1}

    "SJSJJSSJSJSJJJJSSJ"

    Returns: 5

  46. { 2 }

    "J"

    Returns: 0

  47. { 1, 2, 2, 1 }

    "SJJS"

    Returns: 2


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: