The problem. Using this starter code, write a class RunIdentifier that implements the following API:

public class RunIdentifier {
	public static void identifyRuns(int[] a, int minNumPoints)
	public static void main(String[] args)  //provided for you
}

Given an array X, a run of value Z is defined as a subsequence of consecutive elements of value Z of maximal width. A subsequence of consecutive elements is considered to be of maximal width if there are no elements of value Z adjacent to that subsequence. For example, given the array int[]{7, 7, 7, 8, 8, 2, 2, 2, 3, 3, 3, 3, 7, 7, 7, 7, 7}, the set of runs is:

Run of 7s of length 3 starting at index 0.
Run of 8s of length 2 starting at index 3.
Run of 2s of length 3 starting at index 5.
Run of 3s of length 4 starting at index 8.
Run of 7s of length 5 starting at index 12.

The first two 7s do not constitute a run of length 2, because the subsequence {7, 7} is not of maximal width since there is another 7 to the right of this subsequence.

Given an input array, the method identifyRuns() should print the value of each run in the array, as well as the indices of the run.

As an example, given the input array {5, 5, 5, 7, 8, 9, 9, 9, 10, 11, 12, 12, 12, 12, 12, 12}, your output should be:

Run of 12s: 10 11 12 13 14 15 
Run of 9s: 5 6 7 
Run of 5s: 0 1 2 

Our implementation of RunIdentifier contains only 18 lines of code for identifyRuns and any hypothetical private helper methods (this total includes lines for any helper functions that may exist, but does NOT include any comments or lines that only contain brackets).

When coding up FastCollinearPoints.java, you should use your implementation of RunIdentifier as a guide. Doing so will probably result in much simpler (and thus easier to debug) code!

This exercise was developed by Josh Hug.
Copyright © 2013.