Data Structures & AlgorithmsModerateInfosys · Cognizant pattern

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

  1. A. intern
  2. B. inter
  3. C. int
  4. D. interv

Correct answer: B. inter

Compare column by column: i, n, t, e, r are shared by all four. At index 5 the letters are v, n, v, n – they differ, so the prefix stops at 'inter'. 'intern' is common only to internet and intern.

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

Exams that ask this topic