# I1 Maximum Fruit

Ok let me recall this problem, Alice went to a farm for fruit picking, and she got two basket. Each tree is able to produce a single type of fruit and the trees are given in an array. Alice can start from any of the trees and then continue picking to the right. She wanted to pick same kind of fruit in each of the basket so she would stop either when she got the third type of fruit or reached the end of the trees. Given array A = [] of length n, return the maximum number of fruits that Alice can pick. Alice won’t throw any fruits she has picked.

• 要求：
给一个数组，求Alice可以摘到的最多水果数量。 Time complexity $$O(N)$$, space complexity $$O(N)$$

• 返回： max amount of fruit.

• 例子：
• input: A = [1,2,1,2,1]
• output: 5

## Solution

Note: this problem is similar to the leetcode 159 longest substring with most two distinct characters

def solution(A):
# write your code in Python 3.6
if len(list(set(A)))<=2:
return len(A)
else:
max_num = 0
cnt = 0
same = 1
for i in range(len(A)):
cnt +=1
if A[i] == A[i-1]:
same += 1
else:
same = 1
else: