#C836. Longest Common Prefix

    ID: 52333 Type: Default 1000ms 256MiB

Longest Common Prefix

Longest Common Prefix

Given a list of strings, your task is to determine the length of the longest common prefix shared by all the strings.

The longest common prefix is defined as the longest substring that appears at the beginning of each string. If there is no common prefix, output 0.

For example, if the input is ["flower", "flow", "flight"], the longest common prefix is "fl" and its length is 2.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains a single integer n (n ≥ 0) which represents the number of strings.
  • The next n lines each contain a non-empty string.
  • If n is 0, the list of strings is considered empty.

outputFormat

Output a single integer to standard output (stdout) representing the length of the longest common prefix among the given strings.

## sample
3
flower
flow
flight
2