Skip to content
CampusEduX

Longest Common Prefix

Easyjavapythonccppjavascript

Given a list of strings, find the longest prefix shared by every string. If there is no common prefix, the answer is the empty string.

Input Format

The first line contains an integer K, the number of strings. Each of the next K lines contains one string with no spaces.

Output Format

Print the longest common prefix. If it is empty, print an empty line.

Related Problems

  • Reverse a String
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Check Palindrome
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Count Vowels and Consonants
    Easy · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...