C++ O(n)


  • 8
    B
    class Solution {
    public:
        int maxDistance(vector<vector<int>>& arrays) {
            int left = arrays[0][0], right = arrays[0].back(), ans = 0;
            for(int i = 1; i < arrays.size(); i++)
            {
                ans = max(ans, max(abs(arrays[i][0] - right), abs(arrays[i].back() - left)));
                left = min(left, arrays[i][0]);
                right = max(right, arrays[i].back());
            }
            return ans;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.