# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

There is a guy named “Lucky” who is depressed now. His friend Jack knows why he is depressed. He has an array **A** which contains **n** numbers. He wants to find the largest sub-array where the first and the last element are same.

So Jack wants to help lucky. But he doesn’t know anything about programming. That’s why he comes to you as you are a great programmer in the world.

Find the size of the desired largest sub-array.

**Note: a sub-array of an array composed from a contiguous block of the original array’s elements.**

The first line of the input will contain one integers **n** (the size of the array).

The second line contains **n** numbers. (A_{1},A_{2},A_{3},……..,A_{n})

Subtask 1 (10 points): 1 ≤ n ≤ 10 and 1 ≤ A_{i} ≤ 10^{3}

Subtask 2: (30 points): 1 ≤ n ≤ 2 * 10^{5} and 1 ≤ A_{i} ≤ 10^{6}

Subtask 3: (60 points): 1 ≤ n ≤ 2 * 10^{5} and 1 ≤ A_{i} ≤ 10^{18}

Print the size of the desired largest sub-array.

Input | Output |
---|---|

6 1 2 3 4 1 5 | 5 |

65% Solution Ratio

Ahasan_1999Earliest,

BSMRSTU_CZCFastest, 0.0s

artugal28_373Lightest, 3.0 MB

Istiak516Shortest, 250B

Login to submit