Problem Statement
Often, when doing statistical analysis on a data set, it makes sense to remove outliers. That is, remove elements of the data set that are very dissimilar to the rest of the data. These elements of the data set are generally considered to be flukes, and so it often makes sense not to include them in the analysis.
In this problem, the data set will be a String[], S, and the outlier that we want to remove is the String in S with the most characters. If two or more elements of S tie for the most characters, then we want to remove the one with the highest index in S. Your task is to write a method that, given S returns the outlier that should be removed.
Definition
- Class:
- RemoveOutlier
- Method:
- remove
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String remove(String[] S)
- (be sure your method is public)
Constraints
- S will contain between 1 and 50 elements, inclusive.
- Each element of S will contain between 1 and 50 characters, inclusive.
- Each character in each element of S will be a letter ('a'-'z' or 'A'-'Z') or a number ('0'-'9').
Examples
{"a","quick","brown","fox","jumps","over","the","lazy","dog"}Returns: "jumps"
{"a","b","c"}Returns: "c"
{"1","aM","1337"}Returns: "1337"