TopcoderArchiveVisit Topcoder
Archive5 Mar 2003
TCCC '03 Round 3

Ordered

Problem statement, definition, constraints, and public examples.

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,51}
    Returns: "ASCENDING 638/25"
  10. {2,2,1}
    Returns: "NONASCENDING 2"
  11. {1,2,2}
    Returns: "NONDESCENDING 2"
Back to all problems