Source Code
#include <stdio.h>

int main(){
    long long n;
    scanf("%lld",&n);
    int a[n];
    long long x;
  scanf("%lld",&x);
  int i = n-1;
  while(i >= 0){
    a[i] = x%10;
    x = x/10;
    i--;
  }
    long  index = -1,count = 0; 
  if(a[0] == a[n-1]) printf("%lld",n-1);
  else{
    for(int i = 1; i < n-1; i++){
      if(a[0] == a[i] ) index = i;
    }
    if(index == -1) {count = 0;
      index = 0;}
    else count += index;
    long index2 = -1;
    for(int i = n-2; i > index; i--){
      if(a[n-1] == a[i]) index2 = i;
    }
    if(index2 != -1) count+= (n-index2-1);
    
    printf("%ld",count);}
}
Copy
Pop Pop Ayoooy
GNU G++17
2 ms
696 KB
Wrong Answer