Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: For the words ["flowchart", "flow", "flight", "flower"], what is the length of their longest common prefix?

  1. A. 2
  2. B. 3
  3. C. 1
  4. D. 4

Correct answer: A. 2

Shrink the candidate prefix until every word starts with it. Comparing only the first two words gives a longer, incorrect prefix.

More Coding Interview Problems questions

Exams that ask this topic