Problem Submissions Solution

Longest Common Prefix

Difficulty: Easy

Acceptance: %

Points: 20.00

You are given an array of strings, arr[]. Identify and return the longest common prefix shared among all the strings in the array.

  • A prefix is defined as a substring that occurs at the beginning of a string.
  • If there is no common prefix among all the strings, return an empty string "".

Topics

Companies

Articles

Examples:

Expected Time Complexity: O(n*min(|arri|))

Expected Space Complexity: O(min(|arri|))

Constraints:
  • 1 <= |arr| <= 10^3
  • 1 <= |arr[i]| <= 10^3
Companies:
Microsoft Samsung Google
Topics:
Array String
Locked Content
Access Restricted: Please Login to access the code editor and test cases.