Python Solution: Time Complexity: O(mn) Space Complexity: O(1)
Python Solution: Time Complexity: O(n^2) Space Complexity: O(n)