fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using ll = long long int;
  4. #define fo(i,start,end) for(int i=start;i<=end;i++)
  5. using namespace std;
  6.  
  7. int main() {
  8. int arr[] = {3,2,4,3,1};
  9. int k = 3; //input given,distance
  10. int n = 5; //size
  11. fo(i,0,n){
  12. for(int j=i+1;j<n && j<=i+k;j++){
  13. //j-i <= k according to the question
  14. //=> j <= i+k
  15. if(arr[i] == arr[j]){
  16. cout<<"True"<<endl;
  17. return 0 ;
  18. }
  19. }
  20. }
  21. cout<<"False"<<endl;
  22. return 0;
  23. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
False