Statistics

Problem Statement for "Coherency"

Problem Statement

We are given a collection of integers and a positive number, maxJump. We are interested in different ways of arranging all the integers from the collection into a "satisfactory sequence". A sequence is satisfactory if it has the property that the absolute value of the difference between adjacent values is always less than or equal to maxJump.

Create a class Coherency that contains a method starters that is given a int[] collection and positive number maxJump. It returns the number of distinct values from collection that could be the starting value in a satisfactory sequence.

Definition

Class:
Coherency
Method:
starters
Parameters:
int[], int
Returns:
int
Method signature:
int starters(int[] collection, int maxJump)
(be sure your method is public)

Constraints

  • collection will contain between 1 and 50 elements, inclusive.
  • Each element in collection will be between -1,000,000,000 and 1,000,000,000, inclusive.
  • maxJump will be between 0 and 1,000,000,000, inclusive.

Examples

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

    6

    Returns: 0

    However the values are arranged there must be a jump of 7.

  2. {8,1,1,1,1}

    7

    Returns: 2

    Any arrangement of these values has a maximum jump of 7. So we could start a satisfactory sequence with either a 1 or with the 8.

  3. {6,1,11,5,7,1}

    4

    Returns: 2

    (1,1,5,6,7,11) is a satisfactory sequence starting with 1. (11,7,6,5,1,1} is a satisfactory sequence starting with 11. There is no satisfactory sequence that starts with any of the other values, so there are 2 distinct possible starting values.

  4. {1,5,5,9,10,11,12,12,12,16,17}

    4

    Returns: 3

  5. {2,3,6,9,11,14,16,20,21}

    4

    Returns: 3

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

    2

    Returns: 7

  7. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    1000000000

    Returns: 1

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

    4

    Returns: 0

  9. {-6,-3,-1,0,0,4,8}

    4

    Returns: 2

  10. {4,4,4,4,5,9}

    4

    Returns: 2

  11. {1,2,3,6,8,9,10,14,18,22}

    4

    Returns: 4

  12. {-1,-3,-3,-6,-7,-8,-12,-12,-13}

    4

    Returns: 6

  13. {-1,-3,-3,-6,-7,-8,-12,-12,-13}

    1000000

    Returns: 7

  14. {0,1000000,1000000,2000000,2000000,2000000,3000000,4000000,4000000,5000000,5000000,6000000,7000000,7000000,8000000,8000000,9000000,10000000,11000000,11000000}

    1000000

    Returns: 4

  15. {-451000123,123456789,234567891,234567891,345678912,456789123,0,-123456789,-234567891,-345678912}

    151222333

    Returns: 2

  16. {4}

    0

    Returns: 1

  17. {0}

    0

    Returns: 1

  18. {1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    0

    Returns: 1

  19. {1,1,1,1,1,1,1,1,6,6,6,6,6,6,6,6}

    4

    Returns: 0

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

    1

    Returns: 8


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: