Time complexity: O(nm)
Space complexity: O(1)
Runtime 6 ms Beats 94.53% of users with Java Memory 73.30 MB Beats 35.94% of users with Java