Input:
1) A huge sorted array of string SA;
2) A prefix string P;
Output:
The index of the first string matching the input prefix if any. If there is no such match, then output will be -1.
Example:
SA = {'ab', 'abd', 'abdf', 'abz'} P = 'abd'
The output should be 1 (index starting from 0).
What’s the most algorithm way to do this kind of job?
If you only want to do this once, use binary search, if on the other hand you need to do it for many different prefixes but on the same string array, building a radix tree can be a good idea, after you’ve built the tree each look up will be very fast.