Question: Homework 1 Java Write a method longestSubsequence that finds the longest sub-sequence of an array of numbers such that the average of that sub-sequence is
Homework 1 Java
Write a method longestSubsequence that finds the longest sub-sequence of an array of numbers such that the average of that sub-sequence is less than an upper bound. Specifically, the method takes array of float x and an upper bound returns a length two array {i, j} such that elements i through j of x have an average less than the upper bound and such that (j-i) is maximized. If there is no such i and j then the method returns {-1, -1}.
Example output,
16 17 18 19 20 21 public static void main (String[] args) [ Tests System.out.println(" LongestSubsecuence) float [ ] input= {0, 1, 2, 3, 4); int [ ] expected= {0, 2); test( testNum: 1, input, upperBound: 1.2f, expected) 23 24 25 26 27 28 29 30 31 32 float [ ] input= {0, 1, 2, 3, 4); int [ ] expected= {0, 3); test( testNum: 2, input, upperBound: 1.8f, expected) float[i input - [4, 3, 2, 1, 0: int [ ] expected= {2, 4); test( testNum: 3, input, upperBound: 1.2f, expected) 34 35 36 37 38 float[i input - [4, 3, 2, 1, 0; intl expected-[l, 4]: test( testNum: 4, input, upperBound: 1.8f, expected) 40 float[i input -[19, 34, 67, 70, 51, 60, 26, 39, 29, 85: intli expected-[6, 8) test( testNum: 5, input, upperBound: 35, expected); 45 47 4 8 4 9 50 51 52 53 54 float [ ] input= {19, 34, 67, 70, 51, 60, 26, 39, 29, 85); intll expected-[-1, -1); test( testNum: 6, input, upperBound: 15, expected); //add more tests here 56 57 58 59 60 /takes array of float x and an upper bound /returns a length two array fi, j such that elements i through j of x have an average less than the upper bound and such that (j -i) is maximized /or returns (-1, -1 if there is no such i,j public static int[] longestSubsequence (float x[], float upperBound) [ 62 63 64 65 your code goes here LongestSubsequencelongestSubsequence0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

