## Duplicate elements in array at given distance

Given an array of numbers A, which might contain duplicate elements, How do we find if there are two elements A[i], A[j] such that i, j are distinct and the difference between them is at most k? Look at the following examples.1. A = [9, 5, 6, 9, 3, 0, 1], K =3The answer is…