#C7452. Longest Subarray With No Adjacent Same Color
Longest Subarray With No Adjacent Same Color
Longest Subarray With No Adjacent Same Color
You are given a sequence of n tiles, each represented by a positive integer that indicates its color. Your task is to find the length of the longest contiguous subarray in which no two adjacent tiles have the same color.
The problem can be formally stated as follows:
Given a positive integer \( n \) and an array \( tiles[0 \ldots n-1] \) where each element represents the color of a tile, determine the maximum length \( L \) of any contiguous segment such that for every two adjacent positions \( i \) and \( i+1 \) in this segment, \( tiles[i] \neq tiles[i+1] \).
Input is read from standard input and output is written to standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer \( n \), the number of tiles.
- The second line contains \( n \) space-separated integers representing the colors of the tiles.
outputFormat
Output a single integer representing the length of the longest contiguous subarray where no two adjacent tiles share the same color.
## sample5
1 2 3 4 5
5