#K64827. Longest Common Prefix

    ID: 32062 Type: Default 1000ms 256MiB

Longest Common Prefix

Longest Common Prefix

You are given an array of strings. Your task is to find the longest common prefix string amongst the array of strings. If there is no common prefix, you should return an empty string.

Example: For the input ["flower", "flow", "flight"], the longest common prefix is "fl".

The problem tests your ability to perform string comparisons and iteratively reduce the prefix until it satisfies all strings.

Note: All comparisons are case sensitive.

inputFormat

The input is given via standard input (stdin) and consists of:

  • An integer n on the first line, indicating the number of strings.
  • The next n space-separated strings on the same or following line.

For example: 3\nflower flow flight

outputFormat

The output is the longest common prefix string printed to standard output (stdout). If there is no common prefix, output an empty string.

## sample
3
flower flow flight
fl

</p>