Try this:
say i is the index of the first occurrence of the first character
say j is the index of the first occurrence of the second character
say n is length of array
int Min = n+1;
while(i < n && j < n){
int Min = min(Min, abs(i-j))
if(i < j){
find next occurrence of first character
}
else{
find next occurrence of second character
}
}
On 6/17/11, Harshal <[email protected]> wrote:
> Given a character array with a set of characters, there might be repetitions
> as well, given two characters, you should give the minimum distance between
> these two characters in the whole array. O(n) solution is required.
>
> --
> Harshal Choudhary,
> III Year B.Tech CSE,
> NIT Surathkal, Karnataka, India.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.