Statistics

Problem Statement for "AveragePrice"

Problem Statement

You have scanned the prices of several products for sale. You now wish to determine the average product price. Unfortunately, you know that you have been sloppy, and you may have scanned some products more than once. However, you know that you have scanned every product at least once, and that no two products have exactly the same price. Given int[] prices containing the prices you have scanned, return a double indicating the average (mean) product price.

Definition

Class:
AveragePrice
Method:
nonDuplicatedAverage
Parameters:
int[]
Returns:
double
Method signature:
double nonDuplicatedAverage(int[] prices)
(be sure your method is public)

Notes

  • Returned value must be within 1e-9 absolute or relative error of the reference output to be considered correct.

Constraints

  • prices will contain between 1 and 50 elements, inclusive.
  • Each element of prices will be between 1 and 10000, inclusive.

Examples

  1. { 10, 20, 10 }

    Returns: 15.0

    There are two items, with prices of 10 and 20. We scanned the item priced 10 more than once. The average price of an item is (10 + 20) / 2 = 15.

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

    Returns: 3.0

    There are five items, we didn't scan any of them more than once.

  3. { 10, 10, 10, 10, 10, 10 }

    Returns: 10.0

    Only one item, which apparently we really enjoyed scanning.

  4. { 10000, 9999, 9998, 9997, 1 }

    Returns: 7999.0

  5. { 1 }

    Returns: 1.0

  6. {4842,5557,4701,6253,5557,5411,5411,5411,6169,5557,9065,6558,4701,8332,6169,4701,2984,1835,4013,4013,6040,6253,4391,6558,5547,4013,7095,2984,9563,6558,9065,2984,1835,5557,5557,6598,6775,7777,5547,829,3900,2984}

    Returns: 5647.045454545455

  7. {9484,341,341,9184,9184,9879,9879,341,9879,9879,3519}

    Returns: 6481.4

  8. {2267,9409,9409,8989,8989,8989,9468,9409,8989,6157,3901,5044,9409,6157,3901,2629,3875,2629,901,2629,6157}

    Returns: 5264.0

  9. {35,5321,3217,3217,2023,2756,2756,7223,7223,1429,3217,5321,1817,6804,2023,2756,3217,1429,1429,6804,4209,7209,1817,7209,6804,6804,2756,7209,1550,5773,2756,5693,7001,2023,6804,6804,71,3070,1701,3217,976,2434,9652}

    Returns: 3807.809523809524

  10. {809,817,344,8441,344,344,8315,8315,6879,7535,7535,8359,1530,8359,8315,1706,817,7535,8536,7479,6879,344,190,3741,1530,8536,8315,5182,7200,892,8359,3741,6564,8441,6879,4530,892}

    Returns: 4686.789473684211

  11. {8466,9246,9246,9246,2850,9246,6972,2850,7099,4838,5646,2268,2268,7099,2850,1377,1377,4455,4455,6972,5596,6972,9557,5596,5646,387,8165,1815,9722,1377}

    Returns: 5528.6875

  12. {8249,6967,6967,6967,706,706,6547,8138,706,656,3659,3659,6547,1566,6547,8138,3754,6547,1383,4596,1383,3659,4596,656,1383,6547,4596,9508,3754,4652,3993,706,6967,3754,9290,1566,91,1613,6029,5451,2888,1613,1383,1240,1049,8777,6547}

    Returns: 4382.695652173913

  13. {7959,6043,1246,6864,6864,1246,3358,3022,709,709,3358,6043,6175,6043,1246,9363,3750,3022,4448,6043,6097,4309,6175,1709,9827,1709,9827,4448,743,8323,7882,6097}

    Returns: 5101.5

  14. {2433,2296,2296,2296,1775,2296,6351,9104,1908,1775,9359,9359,5639,6351,2378,1775,1908,4744,8969,9104,4171,6841,2378,6172,1908,9104,1580,1775,4171,880,6351,5681,1580,8848}

    Returns: 4951.611111111111

  15. {9999,8296,8296,8207,8296,8207,6645,8296,8296,567,8207,4250,588,6798,9702,6798,8724,2844,702,5531,484,9702,181,6798,181,4943,8503,5861,2844,181,9702,8833,8833,7155,3458,567,4943,3154,5059,3644,7155,8207,8207,3123,4421}

    Returns: 5064.307692307692

  16. {9460,8670,8670,8670,4508,9365,5568,1316,4508,9365,8670,1850,8109,2755,7841,5134,6531,5903,9275,9275,9365,9501,6760,4508,6760,2755,7841,9297,185,2370,9501,1850,5903,1739,9275,8109,7841,5134,5568,3433,5232,6393,5568,7450,5568,9501}

    Returns: 5776.875

  17. {8279,8199,8199}

    Returns: 8239.0

  18. {556,3190,3643,3190,3643,8347,5247,3190,3643,3569,8916,5929,3569,8347,5839,1755,4043,5247,3190,5909,3569,9548,8916,8253,8253,5805,5805,5674,3612,2804,5357,3190,3643,2804,8916,4872,8916,6891,1280}

    Returns: 5047.227272727273

  19. {1404,857,857,3419,527,3419,527,527,1180,3419,1923,3559,1180,4783,5182,857,1180,8890,3559,3559,3419,3419,857,3559,6070,2946,3559,527,527,7846,1180,6070,3801,1,8890,2478,8650,1930,2946,4145,6738,3419,4783,8650,659,770}

    Returns: 3534.4545454545455

  20. {4454,1904,9664,5177,9664,6060,5177,1904,5177,6060,3147,5248,9664,9775,8134,6060,7060,2414,5177,7060}

    Returns: 5730.636363636364

  21. {8067,7241,7241,7241,655,655,3525,655,8120,9206,6359,7241,655,9740,7241,5589,7241,5589,538,2385,7814,9206,7241,5912,7814,2034,1508,4694,915,752,5696,8120,1508,538,3106,1581,6468,8941}

    Returns: 4819.391304347826

  22. {1805,4955,2206,2206,8,8,4955,8,4155,3810,7372,8,7317,3853,3810,2206,2838,2206,529,4955,7677,2974,359,4670,4955,7317,7067}

    Returns: 3849.6875

  23. {809,4489,4489,4489,2369,3223,3223,2369,3144,4896,4896,8159,4896,3428,2369,4489,7269,2369,6185,528,9203,7802,8121,3223,6185,3223,8307,3970,8819,528,6185,3144,3428,528,456,1063,8307,903,7288,6953,4980,3144,7066,6185,4318,903,8121}

    Returns: 4949.92

  24. {2162,4213,4213,1592,7484,7484,352,4293,6647,352,1592,1592,1592,352,4293,5939,1592,8228,8228,4213,4293,8228,1592,6647,149,6572,7484,6583,352,6572,7682,6647,3044,1281,7484,8228,2677}

    Returns: 4306.125

  25. {4270,7723,1823,7723,7723,1807,5986,1823,5735,8914,3392,5735,3392,2362,563,8914,3392,3129,1823,2314,9918,4544,1140,3723,3723,563,5735,1117,5469,1140,6669,1779,3392,3853,8033,8914,4845,5986,4601}

    Returns: 4321.208333333333

  26. {7174,2050,2050,9113,3899,9113,4787,3899,1633,3899,3899,4787,9113,1394,3561,2050,2050,3899,4332,7223,7223,9252,2050,7223,9873,1760,4332,4227,9113,7223,7223,9113,4227,9252,1502,2550}

    Returns: 4645.625

  27. {7470,4518,4758,4758,7307,6612,7307,4518,7307,4758,6636,5076,55,55,4518,4518,5076,7307,6636,4518,8875,6612,8875,6636,1257,4758,4518,6473,6018,9523,7428,5435,5435,370}

    Returns: 5488.1875

  28. {8624,2627,5008,2627,2627,2941,2577,1555,5076,5076,509,2627,2577,5076,2332,1795,9502,1555,6263,2332,5076,509,8546,509,8546,1555,2332,9086,1727,7344,6755,2332,2941,1795,1555,9502,2941,8938,7313,5076}

    Returns: 5185.1578947368425

  29. {8067,6277,3939,6277,719,719,3939,6277,3939,7476,6277,6071,3939,6780,719,9623,9232,6780,939,5896,180,6277,2327,5781,8547,2327,6439,939,657,2327,6554,458,8132,4564,9596,8547}

    Returns: 5375.181818181818

  30. {7156,5120,4210,4210,5849,7812,4210}

    Returns: 6029.4

  31. {1489,4849,4849,994,8906,4849,8906,7708,4790,8906,1343}

    Returns: 4297.0

  32. {6819,2111,2111,2111,2111,5292,3055,1472,1472,6462,1460,5292,6462,5511}

    Returns: 4022.75

  33. {7263,4168,4168,8866,4168,7466,1409,4790,4790,4168,1409,7466,4500,4790,8150,5641,1309,4500,5641,3060,838,8866,8630,6200,1309,8866,6409,1011,8866,4658,838,1312,1409,838,6722,2486}

    Returns: 4744.4

  34. {5715,4683,5624,7159,4683,7159,7159,8627,5624,2351,8627,6308,4683,8627,6742,8627,2862,7159,4696,6548,5947,6784,7159,4683,7632,7632,8466,9114,8627,3800,4696,9284,2817,3652,6308,5624,9114,5544,3033,2817,7543,9369,9517,5282,5544,2862,6308}

    Returns: 6119.192307692308

  35. {1058,6401,6401,1552,7332,9649,9649,8691,6401,7332,775,6401,7312,7332,775,8691,4944,9649,3280,1552,5728}

    Returns: 5156.545454545455

  36. {2, 1, 2 }

    Returns: 1.5

  37. {10, 20, 30, 40, 50 }

    Returns: 30.0

  38. {10, 20, 10 }

    Returns: 15.0

  39. {9617, 9114, 9223, 9085, 9207, 9665, 9614, 9508, 9351, 9579, 9638, 9973, 9310, 9941, 9237, 9074, 9460, 9574, 9828, 9264, 9789, 9632, 9433, 9571, 9218, 9470, 9138, 9877, 9933, 9865, 9071, 9198, 9978, 9942, 9931, 9833, 9607, 9544, 9989, 9958, 9771, 9627, 9579, 9081, 9216, 9463, 9802, 9676, 9685 }

    Returns: 9553.333333333334

  40. {2, 3 }

    Returns: 2.5

  41. {10, 20, 30, 20, 30, 5, 6, 7, 5 }

    Returns: 13.0

  42. {1, 2 }

    Returns: 1.5

  43. {5, 2 }

    Returns: 3.5

  44. {1, 2, 3, 5 }

    Returns: 2.75

  45. {10000, 10000, 10, 11, 93, 99, 55, 69, 69, 9999, 1, 1, 1, 1, 9999, 8997 }

    Returns: 2933.4

  46. {1, 2, 3, 4, 5 }

    Returns: 3.0

  47. {3, 2 }

    Returns: 2.5

  48. {10, 10, 10, 10, 10, 10 }

    Returns: 10.0

  49. {10, 1, 1 }

    Returns: 5.5

  50. {10, 10, 10, 10, 10, 10, 20 }

    Returns: 15.0

  51. {1000 }

    Returns: 1000.0

  52. {15, 10 }

    Returns: 12.5

  53. {10, 10, 20 }

    Returns: 15.0

  54. {5, 6 }

    Returns: 5.5

  55. {1, 10 }

    Returns: 5.5

  56. {10, 25 }

    Returns: 17.5

  57. {1, 2, 4 }

    Returns: 2.3333333333333335

  58. {3, 4 }

    Returns: 3.5

  59. {10, 20, 30 }

    Returns: 20.0

  60. {1, 1, 1 }

    Returns: 1.0

  61. {1, 1, 2 }

    Returns: 1.5

  62. {2, 2, 5, 5, 5 }

    Returns: 3.5

  63. {1, 2, 1000 }

    Returns: 334.3333333333333

  64. {12, 15, 13 }

    Returns: 13.333333333333334

  65. {1, 2, 5 }

    Returns: 2.6666666666666665

  66. {2, 1 }

    Returns: 1.5

  67. {1, 2, 3, 100 }

    Returns: 26.5

  68. {2, 2, 2, 2, 2, 3, 5 }

    Returns: 3.3333333333333335

  69. {2 }

    Returns: 2.0


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: