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
2d

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
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter