Intervals of Unique Numbers
InterviewTime limit1sMemory limit32 MB
Count pairs (i, j) where the subarray from i to j has all distinct values, with N up to 100000.
- Level
Medium5 of 10
- Topics
- Two pointers, Sliding window, Hash map, Array
- Solved
- No attempts yet
Problem
You are given a sequence of length . Write a program that counts the contiguous intervals in which no value appears twice.
An interval has length at least 1, and two intervals are different when their start or their end differs. In other words, count the pairs with such that the values from position to position are pairwise different.
Input
The first line contains the length of the sequence. ()
The second line contains the integers of the sequence, separated by spaces. Every value is between and .
Output
Print the number of intervals that satisfy the condition on the first line.