Untitled
unknown
plain_text
a month ago
855 B
4
Indexable
Never
class Solution { public: int maxDistance(vector<vector<int>>& arrays) { int ans = 0, szFirstArray = arrays[0].size(); int minFirst = arrays[0][0], minSec = arrays[0][szFirstArray -1], maxFirst = minFirst, maxSec = minSec; for(int i=1;i<arrays.size();i++) { int sz = arrays[i].size(); int fst = max(abs(arrays[i][0] - minSec), abs(arrays[i][0] - maxSec)); int sec = max(abs(arrays[i][sz-1] - minFirst), abs(arrays[i][0] - maxFirst)); minFirst = min(minFirst, arrays[i][0]); maxFirst = max(maxFirst, arrays[i][0]); minSec = min(minSec, arrays[i][sz-1]); maxSec = max(maxSec, arrays[i][sz-1]); ans = max(ans , max(fst, sec)); } return ans; } };
Leave a Comment