Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given an array A consisting of N numbers. In one move you can delete either the first two, the last two, or the

You are given an array A consisting of N numbers. In one move you can delete either the first two, the last two, or the first and last elements of A. No move can be performed if the length of A is smaller than 2. The result of each move is the sum of the deleted elements.Write a function:def solution(A)that, given an array A of N integers, returns the maximum number of moves that can be performed on A, such that all performed moves have the same result.Examples:1. Given A =[3,1,5,3,3,4,2], the function should return 3. The firstmove should delete two last elements (4 and 2 with sum =6), thenA =[3,1,5,3,3]. The second move may delete first and lastelements (3 and 3 with sum =6), then A =[1,5,3]. The third moveshould delete first two elements (1 and 5 with sum =6), then A =[3).2. Given A =[4,1,4,3,3,2,5,2), the function should return 4. It ispossible to delete the first and last elements four times, as each11Search2. Given A =[4,1,4,3,3,2,5,2], the function should return 4. It ispossible to delete the first and last elements four times, as each such pair of elements sums up to 6.3. Given A =[1,9,1,1,1,1,1,1,8,1], the function should return 1.There is no way to perform move that results with the same sum more than once.4. Given A =11,9,8,9,5,1,2), the function should return 3. The firstmove should delete the first two elements, then the second and third moves should delete first and last elements twice.5. Given A =[1,1,2,3,1,2,2,1,1,2), the function should return 4.One of the possible sequence of moves goes as follows:twice delete the last two elements,then delete the first and last elements,last move deletes the first two elements.Write an efficient algorithm for the following assumptions:Nis an integer within the range [1..1,000];

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

How many are too few?

Answered: 1 week ago