1503. Last Moment Before All Ants Fall Out of a Plank¶ Time: $O(n)$ Space: $O(1)$ C++ 1 2 3 4 5 6 7 8class Solution { public: int getLastMoment(int n, vector<int>& left, vector<int>& right) { const int maxLeft = left.empty() ? 0 : ranges::max(left); const int minRight = right.empty() ? n : ranges::min(right); return max(maxLeft, n - minRight); } };