Question: JAVA Help: RULES: You may not import any extra functionality besides the default. For example, System and Math are imported by default and thus may

JAVA Help:

RULES:

  1. You may not import any extra functionality besides the default. For example, System and Math are imported by default and thus may be used, whereas something like ArrayList must be explicitly imported so it is disallowed.
  2. You may not use any built-in functionality for copying an array, like System.arrayCopy(), Arrays.copyOf(), Object.clone(), Arrays.stream, etc. If you want to copy an array, you should do it manually (i.e. create a new array and transfer the data).

1st Problem-

Create the following method:

public static int[][] triangularArray(int[][] arr)

It creates and returns a two-dimensional triangular array that holds the elements of arr in the same order. Please note that the last row may not have the maximum length permitted.

Examples:

triangularArray({{1,2,3,4,5},{6,7,8,9,10}}) ---> {{1},{2,3},{4,5,6},{7,8,9,10}} triangularArray({{1,2},{3,4},{5,6},{7,8}}) ---> {{1},{2,3},{4,5,6},{7,8}}

2nd Problem-

Consider the leftmost appearance of a value in an array and the rightmost appearance of that same value in the array. We'll say that the "span" of this value is the number of items that exist between these two appearances (including the two appearances). A value that appears only once in an array has a span of 1.

Create the following method that returns the subarray with the largest span found in arr. If multiple subarrays have an equally large span, return the subarray with the largest sum.

public static int[] maxSpan(int[] arr)

Examples:

maxSpan({1, 2, 1, 1, 3}) ---> {1, 2, 1, 1} maxSpan({1, 4, 2, 1, 4, 1, 4}) ---> {4, 2, 1, 4, 1, 4} // because {1, 4, 2, 1, 4, 1} has a smaller sum

Please help with these 2 problems. Thank You! :)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!