Contains Duplicate Problem Statement
Given an array of integers ARR
and an integer K
, determine if there exist two distinct indices i
and j
such that ARR[i] == ARR[j]
and | i - j | <= K
.
Input:
The first line contains a single integer T
representing the number of test cases. Each test case includes:
- A line with two integers N
and K
, where N
is the number of elements in the array and K
is the given integer.
- A second line with N
space-separated integers denoting the elements in the array ARR
.
Output:
For each test case, output "Yes" if a pair of such indices exists, otherwise output "No". Print each result on a new line.
Example:
Input:
2
6 2
1 2 3 1 4 5
4 1
1 0 1 1
Output:
Yes
No
Constraints:
1 <= T <= 50
1 <= N <= 10000
1 <= K <= 10000
0 <= ARR[i] <= 10^9
- Time limit: 1 sec
Be the first one to answer
Add answer anonymously...
Top HSBC Group Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in HSBC Group Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app