Mathison and the funny subarray
Practice
4.2 (30 votes)
Easy
Greedy algorithms
Problem
80% Success 8628 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Mathison has been playing quite a lot with some array A of length N. A subarray of the given array is called funny if it starts and ends with the same number.

Your task is to find the length of the longest funny subarray of the given array.

Input
The first line of the input file contains an integer, N, representing the number of integers in the given array.
The second line of the input file contains N space-separated integers, where the \(i^{th}\) integer represents \(A[i]\) .

Output
The output file should contain only one integer, the length of the longest funny subarray.

Constraints

  • \( 1 \le N \le 10^6 \)
  • \( 1 \le A[i] \le 10^5 \)
  • A subarray is a subset of consecutive elements of an array.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
7 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsRecruit
Points:20
348 votes
Tags:
EasyGreedy AlgorithmsOpenString Manipulation
Points:20
37 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsOpen