Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

thank you In a garden there are N fruit trees growing in a row. Each tree produces one fruit of some type. Little Amy goes

image text in transcribed

thank you

In a garden there are N fruit trees growing in a row. Each tree produces one fruit of some type. Little Amy goes to the garden to collect some fruit. She has two baskets that can hold any number of fruit, but she only wants to put one type of fruit in each basket. When Amy enters the garden, she goes to some tree, collects the fruit from it (every tree produces exactly one fruit) and then goes to the next tree to the right. Amy continues her walk until she encounters a tree with a fruit that she cannot put in any of her baskets (each of them already has a fruit of a different type), or when the garden ends. Amy never throws any fruit away from her basket. What is the maximal number of fruit she can collect? Write a function: class Solution f public int solution(int[] A); that, given an array A of N integers, representing consecutive types of fruit in the garden, returns the maximal number of fruit Amy can collect. For example, given A [1, 2, 1, 3, 4, 3, 5, 1, 2] the function should return 3. Amy can collect fruit of types 1 and 2 from the beginning of the garden or all fruits of types 3 and 4. Given A [1, 2,1, 2, 1,2, 1] the function should return 7. Amy can collect all the In a garden there are N fruit trees growing in a row. Each tree produces one fruit of some type. Little Amy goes to the garden to collect some fruit. She has two baskets that can hold any number of fruit, but she only wants to put one type of fruit in each basket. When Amy enters the garden, she goes to some tree, collects the fruit from it (every tree produces exactly one fruit) and then goes to the next tree to the right. Amy continues her walk until she encounters a tree with a fruit that she cannot put in any of her baskets (each of them already has a fruit of a different type), or when the garden ends. Amy never throws any fruit away from her basket. What is the maximal number of fruit she can collect? Write a function: class Solution f public int solution(int[] A); that, given an array A of N integers, representing consecutive types of fruit in the garden, returns the maximal number of fruit Amy can collect. For example, given A [1, 2, 1, 3, 4, 3, 5, 1, 2] the function should return 3. Amy can collect fruit of types 1 and 2 from the beginning of the garden or all fruits of types 3 and 4. Given A [1, 2,1, 2, 1,2, 1] the function should return 7. Amy can collect all the

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

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions