fork download
  1. #include <iostream>
  2. #include<vector>
  3. #include<unordered_map>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. vector<int> a={1,3,5,6,1,9,8};
  9. unordered_map<int,int> m;
  10. int k=4;
  11. int dist=-1;
  12. for(int i=0;i<a.size();i++) {
  13. int curr=a[i];
  14. for(int j=i+1;j<a.size();j++) {
  15. if(a[j]==curr) {
  16. dist=j-i;
  17. if(dist<=k) {
  18. cout<<dist<<endl;
  19. }
  20. }
  21. }
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
4