fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14. int n = sc.nextInt();
  15. int arr[] = new int[n];
  16. for(int i=0;i<n;i++){
  17. int val = sc.nextInt();
  18. arr[i] = val;
  19. }
  20. int k = sc.nextInt();
  21. boolean result = false;
  22. for(int i=0;i<n;i++){
  23. int range=k;
  24. int j=i+1;
  25. while(range>0 && j<n){
  26. if(arr[i]==arr[j])
  27. result = true;
  28. j++;
  29. range--;
  30. }
  31. }
  32.  
  33. System.out.println(result);
  34. }
  35. }
Success #stdin #stdout 0.13s 54544KB
stdin
8
1 2 3 4 1 2 3 4
4
stdout
true