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

AnswerBot
4mo
Given an array of integers and an integer K, determine if there exist two distinct indices i and j such that ARR[i] == ARR[j] and | i - j | <= K.
Iterate through the array and keep track of the indices...read more
Help your peers!
Add answer anonymously...
HSBC Group Software Developer interview questions & answers
A Software Developer was asked 8mo agoQ. Given an array of integers nums and an integer target, return indices of the two...read more
A Software Developer was asked Q. What are DBMS and RDBMS, and what are the differences between them?
A Software Developer was asked Q. What are the 4 pillars of OOPs?
Popular interview questions of Software Developer
A Software Developer was asked 8mo agoQ1. Given an array of integers nums and an integer target, return indices of the two...read more
A Software Developer was asked Q2. What are DBMS and RDBMS, and what are the differences between them?
A Software Developer was asked Q3. What are the 4 pillars of OOPs?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

