Statistics

Problem Statement for "IntCount"

Problem Statement

PROBLEM STATEMENT:

In analyzing the probability distribution function of the times of the
occurrences of events, it is often important to know the number of time
intervals in which a certain number of events occurred.

Define the following variables:

int[] times = The data resulting from the experiment; the times, in order, when
each event occurred.

int start = The time when the experiment began.

int end = The time when the experiment ended.

int numIntervals = The number of intervals of equal size in which to break the
experiment period.

Define the function

Q(n) := The number of intervals in which exactly n events occurred.

Implement a function which takes times, start, end, numIntervals, and n and
returns Q(n).

DEFINITION:

Class: IntCount
Method: getQ
Paramaters: int[], int, int, int, int
Returns: int
Method Signature (be sure your method is public): int getQ(int[] times, int
start, int stop, int numIntervals, int n);

TOPCODER WILL ENSURE:
 * times contains between 0 and 50 elements, inclusive.
* The elements of times are sorted from first occurrence to last
(non-descending).
 * The elements of times are between start and stop, exclusive.
 * 0 <= start < stop < 1000
 * numIntervals is between 1 and 999, inclusive.
 * n is between 0 and 1000, inclusive.

NOTES
* An event occurs in an interval if it occurs at or after the interval's start
time and before the interval's end time.  For example, an event occuring at
time = 4 is in the interval 4 - 5, but not 3 - 4.
 * When breaking up the intervals, do not round.

EXAMPLES:

If times = {1, 1, 2, 2, 3, 3, 4, 5, 7, 8},
   start = 0,
   stop = 10,
   numIntervals = 10,
   n = 0:

The intervals are 0 - 1, 1 - 2, 2 - 3, ... 9 - 10.
0 events occurred from 0 - 1, 6 - 7 and 9 - 10, so return 3.

If everything else is the same and n = 1, return 4.
If everything else is the same and n = 2, return 3.
If everything else is the same and n = 3, return 0.

If times = {2, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8},
   start = 1,
   stop = 15,
   numIntervals = 3,
   n = 8:
   return 1.

If everything else is the same and n = 3, return 1.
If everything else is the same and n = 2, return 0.
If everything else is the same and n = 4, return 0.

If times = {},
   start = 20,
   stop = 21,
   numIntervals = 10,
   n = 0:
   return 10.
   If n is anything more than 0, return 0.

If times = {295,296}
   start = 0
   stop = 515
   numIntervals = 515
   n = 1
   return 2.

If times = {5,6}
   start = 4
   stop = 7
   numIntervals = 3
   n = 1
   return 2.

Definition

Class:
IntCount
Method:
getQ
Parameters:
int[], int, int, int, int
Returns:
int
Method signature:
int getQ(int[] param0, int param1, int param2, int param3, int param4)
(be sure your method is public)

Constraints

    Examples


      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: