Longest Common Prefix

Easy · Strings · String · Trie

Problem

Return the longest prefix shared by every string in strs. If there is none, return "".

Examples

Input: strs = ["flower","flow","flight"]
Output: "fl"
Input: strs = ["dog","racecar","car"]
Output: ""

Nothing is shared.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…