Start learning free

LESSON 164 OF 349 · LOOPS - CHALLENGES

Longest Common Prefix of Two Strings in Swift

Practice

Given two strings s1 and s2, return their longest common prefix

Example 1:

Input:  s1 = "hello", s2 = "help"
Output:  "hel"

Example 2:

Input:  s1 = "Andy", s2 = "Mircea"
Output:  ""

Example 3:

Input:  s1 = "AlgoCademy", s2 = "Algo"
Output:  "Algo"

STEP 1 OF 7
    Ctrl + Enter to check

    Longest Common Prefix Of Two Strings in Swift

    Keep going with SwiftAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free