Problems > Longest Common Prefix

Longest Common Prefix

Difficulty: 1100 2000 ms 128 MB

strings

Print the longest prefix shared by all N words, or NONE if it is empty.

Input: the first line has N; the next N lines each have one lowercase word.

Output: the longest common prefix, or NONE.

Constraints:

  • 2 ≤ N ≤ 100
  • 1 ≤ word length ≤ 100

Sample Tests

Input 1
3
flower
flow
flight
Output 1
fl
Input 2
2
dog
car
Output 2
NONE

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.