Statistics

Problem Statement for "FingerCounting"

Problem Statement

Your little son is counting numbers with his left hand. Starting with his thumb and going toward his pinky, he counts each finger in order. After counting his pinky, he reverses direction and goes back toward his thumb. He repeats this process until he reaches his target number. He never skips a finger. For example, to count to ten, he would count: thumb, index, middle, ring, pinky, ring, middle, index, thumb, index. Sadly, one of his fingers hurts and he can only count on it a limited number of times. His fingers are numbered 1 through 5 from thumb to pinky. You are given an int weakFinger, the finger that hurts, and an int maxCount, the maximum number of times he can use that finger. Return the largest number he can count to. If he cannot even begin counting, return 0.

Definition

Class:
FingerCounting
Method:
maxNumber
Parameters:
int, int
Returns:
int
Method signature:
int maxNumber(int weakFinger, int maxCount)
(be sure your method is public)

Constraints

  • weakFinger will be between 1 and 5, inclusive.
  • maxCount will be between 0 and 100000, inclusive.

Examples

  1. 2

    3

    Returns: 15

    The first 15 numbers are counted with fingers 1,2,3,4,5,4,3,2,1,2,3,4,5,4,3. He would then have to use finger 2 for the next number, but since he has already used it 3 times, he has to stop.

  2. 1

    0

    Returns: 0

    He needs to use his thumb when counting the first number, 1, but it's too weak to be used even once.

  3. 5

    0

    Returns: 4

    Even though his pinky cannot be used at all, he can count 1,2,3,4 with the other fingers.

  4. 2

    48

    Returns: 193

  5. 5

    973

    Returns: 7788

  6. 3

    99999

    Returns: 399998

  7. 2

    0

    Returns: 1

  8. 3

    0

    Returns: 2

  9. 4

    0

    Returns: 3

  10. 1

    1

    Returns: 8

  11. 2

    1

    Returns: 7

  12. 3

    1

    Returns: 6

  13. 4

    1

    Returns: 5

  14. 5

    1

    Returns: 12

  15. 1

    45326

    Returns: 362608

  16. 2

    56912

    Returns: 227649

  17. 3

    11223

    Returns: 44894

  18. 4

    53276

    Returns: 213107

  19. 5

    327

    Returns: 2620

  20. 1

    9325

    Returns: 74600

  21. 2

    7332

    Returns: 29329

  22. 3

    9125

    Returns: 36502

  23. 4

    6326

    Returns: 25307

  24. 5

    77889

    Returns: 623116

  25. 1

    19192

    Returns: 153536

  26. 2

    46533

    Returns: 186135

  27. 3

    11

    Returns: 46

  28. 4

    97

    Returns: 389

  29. 5

    255

    Returns: 2044

  30. 5

    32768

    Returns: 262148

  31. 1

    2

    Returns: 16

  32. 1

    3

    Returns: 24

  33. 2

    2

    Returns: 9

  34. 5

    99999

    Returns: 799996

  35. 1

    1000

    Returns: 8000

  36. 3

    2

    Returns: 10

  37. 1

    15

    Returns: 120


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: