Directions Reduction Time : Space : 123456789101112131415161718using namespace std;class DirReduction{public: static std::vector<std::string> dirReduc(std::vector<std::string> &arr) { unordered_map<string, string> appo; appo["NORTH"] = "SOUTH"; appo["SOUTH"] = "NORTH"; appo["EAST"] = "WEST"; appo["WEST"] = "EAST"; vector<string> res; for(auto d : arr) { if(res.size() and res.back() == appo[d]) res.pop_back(); else res.push_back(d); } return res; }};