37. Longest common prefix

EasyProgramFree10 points

Write longestCommonPrefix words, the longest string that is a prefix of every string in words. It is "" when the words share no first character, and also when the list is empty.

Examples

  1. InputlongestCommonPrefix ["flower", "flow", "flight"]Output"fl"
  2. InputlongestCommonPrefix ["dog", "racecar", "car"]Output""

Submitting also runs 8 hidden tests.

Solution.lean
Loading editor…

Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.

ReadyLn 1, Col 1Lean 4
Draft saved in this browser