Data Structures & AlgorithmsModerateTCS NQT · string basics

Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code.

Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code.
import os
print(os.path.commonprefix(['flower', 'flow', 'flight']))
What is printed?
  1. A. flow
  2. B. fl
  3. C. f
  4. D. flo

Correct answer: B. fl

Only 'fl' is shared by all three words, since the third letter differs ('o' versus 'i'). The trap 'flo' is shared by the first two words only.

More Coding Interview Problems questions

Exams that ask this topic