Pear Trees and Apple Trees
InterviewTime limit1sMemory limit128 MB
Find the largest distance between any pear tree and any apple tree in a row of n trees.
- Level
Easy2 of 10
- Topics
- Array
- Solved
- No attempts yet
Problem
In an orchard, pear trees and apple trees are all planted along a straight line, each spaced meter apart from the next. The orchard's owner, Mr. Wiktor, wants to find the pear tree that is farthest from any apple tree. Help him by computing the maximum distance between a pear tree and an apple tree.
Input
The first line contains an integer (), the number of trees in the orchard. The second line contains integers separated by spaces. Each gives the type of the -th tree: means a pear tree and means an apple tree. You may assume the orchard contains at least one pear tree and at least one apple tree.
Output
Print a single integer: the maximum distance between a pear tree and an apple tree. Because adjacent trees are meter apart, the distance between the -th and -th trees is meters.