Take three pointers.
p for bat
q for cat
r for mat

Then first find the first ocurrences of bat, cat, mat in the text.
Find min(abs(p-q),abs(q-r),abs(r-p));
Now among p,q,r which  is minimum find next ocurrence of that
particular string in the text.Update the corresponding pointer value.
Again find min(abs(p-q),abs(q-r),abs(r-p))
If it is better then update the current positions.
Continue like this till end.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to