given a string A which contains only three characters {'X','o','.'}. Find minimum possible distance between any pastor of 'x' and 'o' on the string. Distance is defined as the absolute difference between the indeed of 'x' and 'o' . Note: If there is no such pair return-1
Answers
Answered by
5
Answer:
No answer ................
Answered by
0
Answer:
int solve(char *A){
int min=-1,i=0,size;
size=sizeOf(A)/sizeOf(A[0]);
while(i<size){
if(A[i]=='x' || A[i]=='o'){
int temp=Find_Diff(i,A);
if(min==-1)
min=temp;
else if(min>temp)
min=temp;
}
i++;
}
return min;
}
int Find_Diff(int i,char* A){
int j=i+1;
while( j< (sizeOf(A)/sizeOf(A[0] ) ) ) {
if(A[j] !=' . ' && A[j] !=A[i])
return j-i;
}
return -1;
}
Step-by-step explanation:
Similar questions
History,
2 months ago
History,
2 months ago
Social Sciences,
4 months ago
Political Science,
4 months ago
Math,
10 months ago
Math,
10 months ago