fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, x;
  6. cin >> n >> x;
  7. int minLen = n, position = -1;
  8. for (int i = 1; i <= n; ++i) {
  9. int currentEl;
  10. cin >> currentEl;
  11. if (currentEl == x) {
  12. if (position != -1 && i - position < minLen) {
  13. minLen = i - position;
  14. }
  15. position = i;
  16. }
  17. }
  18. cout << minLen;
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
22007