Shared Word Start

When grouping similar file names, commands, or words, it is often useful to quickly find the beginning they all share. Given a list of strings strs, return the longest prefix that appears at the start of every string. If there is no shared beginning, return an empty string.

Примеры

Ввод
["flower", "flow", "flight"]
Вывод
"fl"
Ввод
["dog", "racecar", "car"]
Вывод
""
Ввод
["interview", "internal", "internet"]
Вывод
"inter"

Нужно реализовать

def longest_common_prefix(strs: list[str]) -> str:

Теги

strings
PostgreSQLv16

Tutaj pojawi się wynik wykonania kodu

Visible tests
1
Input
["flower","flow","flight"]
Expected"fl"
2
Input
["dog","racecar","car"]
Expected""
3
Input
["interview","internal","internet"]
Expected"inter"
4
Input
["abc"]
Expected"abc"
5
Input
["",""]
Expected""
6
Input
["flower"]
Expected"flower"
Focus radio
Paused · SomaFM · Fluid