"""Leetcode 14. Longest Common Prefix.
Easy

URL: https://leetcode.com/problems/longest-common-prefix/

Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".

Example 1:
Input: ["flower","flow","flight"]
Output: "fl"

Example 2:
Input: ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.

Note:
All given inputs are in lowercase letters a-z.
"""

class SolutionNaive(object):
    def longestCommonPrefix(self, strs):
        """
        :type strs: List[str]
        :rtype: str

        Time complexity: O(m*n), where
          - m is the maximum length of strs, and
          - n is the length of "minimum" string.
        Space complexity: O(m).
        """
        if not strs:
            return ''

        # Choose str 0 as the baseline to compare with others.
        prefix = ''

        for pos, c in enumerate(strs[0]):
            for j in range(1, len(strs)):
                # Check if position is out of boundary or not matched. 
                if pos >= len(strs[j]) or c != strs[j][pos]:
                    return prefix

            prefix += c

        return prefix


def main():
    # Output: "fl"
    strs = ["flower", "flow", "flight"]
    print SolutionNaive().longestCommonPrefix(strs)

    # Output: ""
    strs = ["dog", "racecar", "car"]
    print SolutionNaive().longestCommonPrefix(strs)


if __name__ == '__main__':
    main()

@@ -492,21 +492,20 @@
 Solution
-Naive
+Iter
 (object)
@@ -775,17 +775,17 @@
 xity: O(
-m
+1
 ).%0A     
@@ -877,31 +877,8 @@
 line
- to compare with others
 .%0A  
@@ -1278,37 +1278,36 @@
   print Solution
-Naive
+Iter
 ().longestCommon
@@ -1396,13 +1396,12 @@
 tion
-Naive
+Iter
 ().l

Revise class name, space complexity and comments