fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. #include<vector>
  5.  
  6. int main() {
  7. // your code goes here
  8. vector<int>arr={6,2,3,6,4,5};
  9. unordered_map<int,int>mp;
  10. int k;
  11. cin>>k;
  12. int flag=0;
  13. int n=arr.size();
  14. for(int i=0;i<n;i++)
  15. {
  16. if(mp.find(arr[i])!=mp.end())
  17. {
  18. if(i-mp[arr[i]]<=k)
  19. {
  20. flag=1;
  21. break;
  22. }
  23. }
  24. mp[arr[i]]=i;
  25. }
  26.  
  27. if(flag==0)
  28. {
  29. cout<<"false";
  30. }else
  31. cout<<"true";
  32.  
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
true