Algorithm · C3.ai · Medium
Picture a farm where fruit trees stand side by side in one line. Every tree yields exactly one kind of fruit, and you are given the sequence of fruit kinds along the row as fruits, where fruits[i] is the kind produced by tree i. You carry two baskets, and each basket may contain fruit of only one kind (with no limit on quantity). You may begin at whichever tree you like and then move strictly to the right, taking exactly one fruit from every tree you pass, starting with the…