import java.util.*;
public class Main {
public static boolean containsNearbyDuplicateBruteForce(int[] nums, int k) {
int n = nums.length;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n && j <= i + k; ++j) {
if (nums[i] == nums[j]) {
return true;
}
}
}
return false;
}
public static void main
(String[] args
) { int[] nums = {1, 1, 3, 1, 2, 3};
int k = 2;
if (containsNearbyDuplicateBruteForce(nums, k)) {
System.
out.
println("There are two equal numbers within distance " + k
); } else {
System.
out.
println("No two equal numbers found within distance " + k
); }
}
}
aW1wb3J0IGphdmEudXRpbC4qOwogCnB1YmxpYyBjbGFzcyBNYWluIHsKICAgIHB1YmxpYyBzdGF0aWMgYm9vbGVhbiBjb250YWluc05lYXJieUR1cGxpY2F0ZUJydXRlRm9yY2UoaW50W10gbnVtcywgaW50IGspIHsKICAgICAgICBpbnQgbiA9IG51bXMubGVuZ3RoOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgICAgIGZvciAoaW50IGogPSBpICsgMTsgaiA8IG4gJiYgaiA8PSBpICsgazsgKytqKSB7CiAgICAgICAgICAgICAgICBpZiAobnVtc1tpXSA9PSBudW1zW2pdKSB7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQogCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgaW50W10gbnVtcyA9IHsxLCAxLCAzLCAxLCAyLCAzfTsKICAgICAgICBpbnQgayA9IDI7CiAgICAgICAgaWYgKGNvbnRhaW5zTmVhcmJ5RHVwbGljYXRlQnJ1dGVGb3JjZShudW1zLCBrKSkgewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlRoZXJlIGFyZSB0d28gZXF1YWwgbnVtYmVycyB3aXRoaW4gZGlzdGFuY2UgIiArIGspOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiTm8gdHdvIGVxdWFsIG51bWJlcnMgZm91bmQgd2l0aGluIGRpc3RhbmNlICIgKyBrKTsKICAgICAgICB9CiAgICB9Cn0=