Longest distinct segment queries
InterviewTime limit1sMemory limit1024 MB
Given a sequence of N values and Q queries (l, r), find the length of the longest contiguous subarray inside [l, r] whose values are all distinct.
- Level
Medium6 of 10
- Topics
- Array, Binary search
- Solved
- No attempts yet
Problem
You are given a sequence of length . Process the following query.
- : Print the largest size among intervals with that contain only distinct values. The size of interval is .
An interval with only distinct values must not contain and with ().
Input
The first line contains . ()
The second line contains the integer sequence , separated by spaces. ()
The third line contains . ()
From the fourth line through line , each query is given on its own line. ()
Output
For each query, print the answer on its own line.