TopcoderArchive
Archive
Algorithm problem

RangeFinder

Problem statement, definition, constraints, and public examples.

Problem Statement

The range is the difference between the highest and lowest value in a group of numbers. Given int[] x, return the range of x.

Definition

Class:
RangeFinder
Method:
getRange
Parameters:
int[]
Returns:
int
Method signature:
int getRange(int[] x)
(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.

Examples

  1. { 1, 2, 3 }
    Returns: 2
    The largest is 3, and the smallest is 1, so the difference is 2.
  2. { 7, 1, 2, 4 }
    Returns: 6
    Elements aren't necessarily in order.
  3. { 3, 5, 2, 3, 4, 3 }
    Returns: 3
    Elements can be repeated.
  4. { 7, -2, 4 }
    Returns: 9
    Values can be negative, too.
Back to all problems