Statistics

Problem Statement for "Fractile"

Problem Statement

Given a int[] x and a percentile p (between 0 and 100, inclusive), find the smallest element y in x such that at least p percent of the elements in x are less than or equal to y.

Definition

Class:
Fractile
Method:
fractile
Parameters:
int[], int
Returns:
int
Method signature:
int fractile(int[] x, int p)
(be sure your method is public)

Constraints

  • x will contain between 1 and 50 elements, inclusive.
  • Each element of x will be between -1000000 and 1000000, inclusive.
  • p will be between 0 and 100, inclusive.

Examples

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

    50

    Returns: -3

    50 percent of the elements in x are less than or equal to -3: -5 and -3.

  2. {7,9,2,-10,-6}

    50

    Returns: 2

    60 percent of the elements in x are less than or equal to 2, and 40 percent are less than or equal to -6. At least 50% of the elements must be less than or equal to the answer, so the answer is 2.

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

    39

    Returns: 4

    4 gives 40%, but 3 gives 30%, which is not enough, so 4 is the answer.

  4. {1,2,3,4,5,6,7,8,9,1,2,3,4,5,7,9,5,43,124,94}

    0

    Returns: 1

    The smallest element of x is 1 and it gives 5%.

  5. {1}

    100

    Returns: 1

    1 is the only element of x, so there is no choice at all.

  6. {3}

    0

    Returns: 3

  7. {-1000000,1000000,1000000,687235,-12456,2305,-12596,1000,22222,-496582,-1000000,1000000,1000000,687235,-12456,2305,-12596,1000,22222,-496582,-1000000,1000000,1000000,687235,-12456,2305,-12596,1000,22222,-496582,-1000000,1000000,1000000,687235,-12456,2305,-12596,1000,22222,-496582,-1000000,1000000,1000000,687235,-12456,2305,-12596,1000,22222,-496582}

    19

    Returns: -496582

  8. {1000000,999999,999567,-235678,-999999,-999547,-1000000,1000,-1,123,9,2,0,0,0,-4,0,-3,-4}

    84

    Returns: 1000

  9. {1000000,999999,999567,-235678,-999999,-999547,-1000000,1000,-1,123,9,2,0,0,0,-4,0,-3,-4}

    85

    Returns: 999567

  10. {736111,-776815,324333,708966,-115106,608751,273786,-482403,-797201,320228,-586045,-243970,-600530,206406,707822,-916892,568879,458038,-677056,-240015,-191321,137445,341891,434727,-76251,-153598,501623,-956126,311455,-644219,-666429,-903488,-872221,551799,482100,664877}

    49

    Returns: -76251

  11. {199776,677047,229513,-814753,476121,112320,-520865,-541760,437755,-962636,453725,-337138,-146962,-466150,729245,-836953,-104560,-694480,-511083,-351612,469913,-925353,162435,-211639,-453309,255049,-558121,707638,-255328,568129}

    23

    Returns: -541760

  12. {-752493,-706844,-894710,620518,-840370,695730,-502952,180117,-466345,659810,-409497,-719310}

    84

    Returns: 659810

  13. {710494,238640,36981,-874528,-700990,-910081,-929206,-435037,-417911,-376557,471908,-843773,-26124,203410,-134135,698345,696770,181707,-642383,-510551,116731,-381654,-979000,-269251,-164114,-891176,292033,-420856,-200963,-315056,-657822,-886508}

    37

    Returns: -435037

  14. {-225075,-205651,-243906,-751160,723930,-408272,753409,-44569,657654,616977,482176,-59368,445063,-621044,384635,-659673,-160484,645434,-98834}

    99

    Returns: 753409

  15. {246625,-110768,684203,-690622,-363586,-900413,302013,-596661,-707343,25506,270138,273864,740210,-476271,328459,-271891,-825843,-961904,-97196,-61027,-230527,324925,-294387,-233883,-375180,-452566,199329,-462513,-891979,-631325,198627,-878514,-192977,-213922,-783027,-355899,-820083,278608,-146495,103169,-762423,-101315,391168,-308286}

    75

    Returns: 198627

  16. {-367713,-801337,-66226,646732,-376543,-137498,568566,-959694,174901,663134,490224,712972,-585501,-276825,726768,207945,-149716,-819705,-895863,-229302,-336472,259182}

    83

    Returns: 646732

  17. {197623,-359394,743114,38453,-606579,118452,-598555}

    58

    Returns: 118452

  18. {-576250,-390311,-951768,-183858,75437,-764168,-876234,193138,-431424,-40328,-738678,629923,584807,513719,-643828,-176556,-669456,318252,-62705,-855774,691195,-443935,-728945,-823149,723988}

    38

    Returns: -576250

  19. {-680211,-193017,584020,-779898,-54422,742954,-186175,-71309,-30142,308822,258586,121599,437703,-151406,-136074,291207,-663175,-446007,506735,118823,383056,-293381,367763,-114485,-435897}

    75

    Returns: 308822

  20. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,47,-1,-2,-3,-4,-5,-6,-7,-8,-111,-9884}

    77

    Returns: 30

  21. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,47,-1,-2,-3,-4,-5,-6,-7,-8,-111,-9884}

    0

    Returns: -9884

  22. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,47,-1,-2,-3,-4,-5,-6,-7,-8,-111,-9884}

    100

    Returns: 47

  23. {-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943,-768943}

    51

    Returns: -768943

  24. {0}

    56

    Returns: 0

  25. {-11,22,33,44,55}

    39

    Returns: 22

  26. {-11,22,33,44,55}

    40

    Returns: 22

  27. {-11,22,33,44,55}

    41

    Returns: 33

  28. {4, 4, -10, 0, 5 }

    100

    Returns: 5

  29. {-3, -5, 2, 1 }

    26

    Returns: -3

  30. {4, 4, -10, 0, 5 }

    0

    Returns: -10

  31. {-1, 1, 100 }

    0

    Returns: -1

  32. {1, 2 }

    0

    Returns: 1

  33. {1 }

    0

    Returns: 1

  34. {-3, 2, 1, -5 }

    1

    Returns: -5

  35. {-3, -5, 2, 1 }

    50

    Returns: -3

  36. {1, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000 }

    2

    Returns: 1

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

    58

    Returns: 6

  38. {-3, -1, -2, -4 }

    50

    Returns: -3


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: