fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[] = {1, 2, 3, 1, 4, 5};
  6. int n = 6;
  7. int k = 3;
  8.  
  9. bool found = false;
  10.  
  11. for(int i = 0; i < n; i++) {
  12. for(int j = i + 1; j < n; j++) {
  13. if(arr[i] == arr[j] && j - i <= k) {
  14. found = true;
  15. break;
  16. }
  17. }
  18. if(found) break;
  19. }
  20.  
  21. if(found) cout << "true" << endl;
  22. else cout << "false" << endl;
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
true