#K79757. Longest Unique Genres Subarray

    ID: 35379 Type: Default 1000ms 256MiB

Longest Unique Genres Subarray

Longest Unique Genres Subarray

You are given a sequence of books on a shelf where each book belongs to a specific genre represented by an integer. Your task is to find the length of the longest contiguous subarray such that all books in that subarray have unique genres (i.e. no genre is repeated).

Input format: The first line contains two integers \(N\) and \(M\) where \(N\) is the number of books on the shelf and \(M\) is the number of different genres. The second line contains \(N\) integers representing the genres of the books.

Output format: Output a single integer, the length of the longest subarray with all unique genres.

Note: A subarray is a contiguous portion of the array.

inputFormat

The input is read from stdin and follows the format below:

  • The first line contains two integers \(N\) and \(M\): the number of books and the number of genres respectively.
  • The second line contains \(N\) space-separated integers, where each integer represents the genre of a book.

outputFormat

Output a single integer to stdout, which is the length of the longest contiguous subarray with all unique genres.

## sample
7 5
1 2 1 3 4 2 5
5