Statistics

Problem Statement for "Ordered"

Problem Statement

Given a int[] values containing positive integers return (quotes for clarity):
  • "ASCENDING mean" if the numbers are in increasing order and there are no repeated values,
  • "DESCENDING mean" if the numbers are in decreasing order and there are no repeated values,
  • "NONASCENDING freq" if the numbers are in decreasing order and contain repeated values,
  • "NONDESCENDING freq" if the numbers are in increasing order and contain repeated values,
  • or "NOTHING" if the numbers are none of the above.
where mean is a reduced fraction representing the average of the numbers formatted as (quotes for clarity) "numerator/denominator"
and freq is the number of times the most frequently occurring value occurred in the sequence.
Neither numerator nor denominator should have any leading zeros. For example (quotes for clarity):
values = {1,2,4,11}       return "ASCENDING 9/2" since the average is 18/4 = 9/2
values = {1,2,2,2,3,4}   return "NONDESCENDING 3"  since 2 occurred 3 times
values = {6,5,1}         return "DESCENDING 4/1" since the average is 12/3 = 4/1
values = {5,5,4,4,1}     return "NONASCENDING 2" since 5 occurred twice
values = {1,2,3,4,1}     return "NOTHING" since no other choice is possible

Definition

Class:
Ordered
Method:
getType
Parameters:
int[]
Returns:
String
Method signature:
String getType(int[] values)
(be sure your method is public)

Notes

  • Be sure that you spell everything correctly.

Constraints

  • values must contain between 2 and 50 elements inclusive
  • At least 2 elements of values must be distinct
  • Each element of values must be between 1 and 1000 inclusive

Examples

  1. {1,2,4,11}

    Returns: "ASCENDING 9/2"

    Increasing order with no repeats

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

    Returns: "NONDESCENDING 3"

    Increasing order but the 2 is repeated 3 times

  3. {6,5,1}

    Returns: "DESCENDING 4/1"

    Decreasing order with no repeats

  4. {5,5,4,4,1}

    Returns: "NONASCENDING 2"

    Decreasing order but there are repeats

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

    Returns: "NOTHING"

    The sequence increases at first but decreases at the end

  6. {1000,999,998}

    Returns: "DESCENDING 999/1"

    Decreasing with no repeats

  7. {999,1000,1000,1000,1000,1000}

    Returns: "NONDESCENDING 5"

  8. {1,1000,1,1000,1,1000}

    Returns: "NOTHING"

  9. {1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50}

    Returns: "ASCENDING 51/2"

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

    Returns: "NONDESCENDING 2"

  11. {1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,51}

    Returns: "ASCENDING 638/25"

  12. {1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,24,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50}

    Returns: "NONDESCENDING 2"

  13. {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,999,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}

    Returns: "NOTHING"

  14. {1000,999,998,997,996,995,994,993,992,991,990, 989,988,987,986,985,984,983,982,981,980, 979,978,977,976,975,974,973,972,971,970, 969,968,967,966,965,964,963,962,961,960, 959,958,957,956,955,954,953,952,951}

    Returns: "DESCENDING 1951/2"

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

    Returns: "NONDESCENDING 2"

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

    Returns: "NOTHING"

  17. {22,132,234,123,523,523,532,12,43,234,234,243}

    Returns: "NOTHING"

  18. {1000,1000,999}

    Returns: "NONASCENDING 2"

  19. {2,2,1}

    Returns: "NONASCENDING 2"

  20. {1,2,2}

    Returns: "NONDESCENDING 2"

  21. { 3, 2, 1 }

    Returns: "DESCENDING 2/1"

  22. { 1, 2, 3, 6 }

    Returns: "ASCENDING 3/1"

  23. { 1, 1000 }

    Returns: "ASCENDING 1001/2"

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

    Returns: "NONDESCENDING 3"

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

    Returns: "ASCENDING 3/1"

  26. { 1, 2, 3, 4 }

    Returns: "ASCENDING 5/2"

  27. { 1, 2, 2 }

    Returns: "NONDESCENDING 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: