Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Longest Common Prefix

Easy
stringtrie

Find the longest common prefix among an array of strings. If there is none, print an empty line.

Input: one line of space-separated words. Output: the longest common prefix.

Example 1
Input:
flower flow flight
Output:
fl
Example 2
Input:
dog racecar car
Output:

No common prefix.

Constraints

  • 1 ≤ words ≤ 200
  • 1 ≤ word length ≤ 200; lowercase letters.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.