Sunset Views Time : O(n) Space : O(n) 12345678910111213141516using namespace std;vector<int> sunsetViews(vector<int> buildings, string direction) { int ma = -1, n = buildings.size(); bool inc = direction == "WEST"; vector<int> res; for(int i = inc ? 0 : n - 1; 0 <= i and i < n; i += inc ? 1 : -1) { if(buildings[i] > ma) { res.push_back(i); } ma = max(ma, buildings[i]); } if(!inc) reverse(begin(res), end(res)); return res;}