Data Structures & AlgorithmsHardTCS NQT · Accenture

What is the length of the longest common prefix of the strings interstellar, internet, interval and intern?

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: A. 5

Shrink the first string until every other string starts with it. The prefix is inter and is shared by all four strings.

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

Exams that ask this topic