Home / Expert Answers / Computer Science / need-answer-in-java8-there-is-an-array-a-of-n-integers-and-three-tiles-each-tile-can-cover-pa908

(Solved): need answer in java8 There is an array A of N integers and three tiles. Each tile can cover ...



student submitted image, transcription available below

student submitted image, transcription available below

need answer in java8

There is an array of integers and three tiles. Each tile can cover two neighbouring numbers from the array but cannot intersect with another tile. It also cannot be placed outside the array, even partially Write a function: class Solution (public int solution(int [] A); \} that, given an array of integers, returns the maximum sum of numbers that can be covered using at most three tiles. Examples: 1. Given , the function should return 25 . There is only one optimal placement of tiles: . 2. Given , the function should return 35 . One of the three optimal placements of tiles is . 3. Given , the function should return 10 . There is one optimal placement of tiles: . Only two tiles can be used because is too small to contain another one. 4. Given , the function should return 15 . Only one tile can be used. Write an efficient algorithm for the following assumptions: 1. Given , the function should return 25 . There is only one optimal placement of tiles: . 2. Given , the function should return 35 . One of the three optimal placements of tiles is . 3. Given , the function should return 10 . There is one optimal placement of tiles: . Only two tiles can be used because is too small to contain another one. 4. Given , the function should return 15 . Only one tile can be used. Write an efficient algorithm for the following assumptions: - is an integer within the range ; - each element of array is an integer within the range . Copyright 2009-2023 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.


We have an Answer from Expert

View Expert Answer

Expert Answer



Here's an efficient algorithm to solve the given problem:
Initialize variables: maxSum to store the maximum sum, n as the length of array A.
Iterate through the array A from index 0 to n-3 (since at most three tiles can be used).
Inside the loop, calculate the sum of the current element A[i] and the next two elements A[i+1] and A[i+2].
If the calculated sum is greater than the current maxSum, update maxSum with the new sum.
Return the final maxSum.
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe