Playlist
Explanation
Here, we are given an array and we need to find the length of the longest contiguous subarray with no duplicate elements.
This can be done using a set and the two pointers method. We'll put both of the pointers at the start of the array, and increase the 2nd pointer if the element at the 2nd pointer is not in the set. If it is in the set, we'll remove the element at the 1st pointer from the set and increase the 1st pointer. We'll keep track of the maximum length of the set and return it.
Code
n = int(input())
songs = list(map(int, input().split()))
s = set()
i = 0
j = 0
count = 0
while i < n and j < n:
if songs[j] in s:
s.remove(songs[i])
i += 1
else:
s.add(songs[j])
j += 1
count = max(count, len(s))
print(count)