#K58002. Longest Common Prefix

    ID: 30545 Type: Default 1000ms 256MiB

Longest Common Prefix

Longest Common Prefix

Given two non-empty strings, the task is to determine the longest common prefix between the two.

The longest_common_prefix function should find the maximum-length substring starting from the beginning of both strings that they have in common. If there is no common prefix, the function should return an empty string.

Example:

  • For input strings "flower" and "flow", the longest common prefix is "flow".
  • For input strings "dog" and "racecar", there is no common prefix so the output is an empty string.

The solution should handle edge cases such as one or both strings being empty.

Note: If the strings differ in letter case, treat letters of different case as different characters.

inputFormat

The input consists of two lines. The first line contains the first string, and the second line contains the second string.

Both strings may be empty.

outputFormat

Output a single line containing the longest common prefix of the two input strings. If there is no common prefix, output an empty line.

## sample
flower
flow
flow