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. Scanner sc=new Scanner(System.in);
  13. int k=sc.nextInt();
  14. int n=sc.nextInt();
  15. int arr[]=new int[n];
  16. for(int i=0;i<n;i++){
  17. arr[i]=sc.nextInt();
  18. }
  19. HashMap<Integer,Integer>hm=new HashMap<>();
  20. for(int i=0;i<n;i++){
  21. if(hm.containsKey(arr[i])){
  22. int idx=i-hm.get(arr[i]);
  23. if(idx<=k){
  24. System.out.print(true);
  25. return ;
  26. }
  27. }
  28. hm.put(arr[i],i);
  29.  
  30. }
  31. System.out.println(false);
  32.  
  33.  
  34.  
  35. }
  36. }
Success #stdin #stdout 0.12s 56640KB
stdin
2
7
2
3
3
7
4
1
3
stdout
true