Statistics

Problem Statement for "OneCardDraw"

Problem Statement

You have several cards, each with a number written on them, given in int[] cards. You also have a int target, which is the value you are hoping to find.

If you select a card at random, what is the probability that what is written on the card matches the target value?

Definition

Class:
OneCardDraw
Method:
pickChance
Parameters:
int[], int
Returns:
double
Method signature:
double pickChance(int[] cards, int target)
(be sure your method is public)

Constraints

  • cards will contain between 1 and 50 elements, inclusive.
  • Each element of cards will be between 1 and 10, inclusive.
  • target will be between 1 and 10, inclusive.

Examples

  1. { 1, 2, 3 }

    1

    Returns: 0.3333333333333333

    There's 1 card that matches, out of 3 total, giving a 1/3 probability.

  2. { 1, 1, 2, 3 }

    1

    Returns: 0.5

    Two cards out of 4 match.

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

    9

    Returns: 0.0

    Since no cards match, there's no chance at all.

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

    4

    Returns: 0.1

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

    5

    Returns: 0.1


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: