Bob's Quest
Practice
3.7 (7 votes)
C++
Greedy algorithms
Algorithms
Observation
Sliding window
Basics of greedy algorithms
Problem
46% Success 1669 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Bob has an array \(A\) of size \(N\), and he is very fond of two integers \(X\) and \(Y\). Find the length of the longest subarray, such that it contains exactly \(X\) distinct integers and \(Y\) exist at least once in the subarray.
Input format
- The first line contains an integer \(T\), which denotes the number of test cases.
- The first line of each test case contains three space separated integers \(N\), \(X\), \(Y\) denoting the size of array \(A\), the value of \(X\) and \(Y\), respectively.
- The second line of each test case contains \(N\) space-separated integers, denoting the elements of array \(A\).
Output format
For each test case, print the length of the largest subarray, such that it contains exactly \(X\) distinct integers and \(Y\) exist at least once in the subarray in a new line.
Constraints
\(1 \leq T \leq 10 \\ 1 \leq N \leq 10^5 \\ 0 \leq A[i] \leq 10^5 \\ 1 \leq X, Y \leq 10^5\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
DatastructuresGreedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Points:30
9 votes
Tags:
AlgorithmsGreedy AlgorithmsHiringImplementationMedium
3.Flip AB
Points:30
4 votes
Tags:
Brute ForceGreedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Editorial