Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Which string is the longest common prefix of ["flower", "flow", "flight", "flute", "fly"]?

  1. A. flo
  2. B. flow
  3. C. fl
  4. D. fli

Correct answer: C. fl

Sorting makes the first and last strings the most different, so their common prefix equals the common prefix of the whole list. The shared prefix here is "fl".

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic