C++ easy | O(n) time | O(1) space | Two pointer | Explained with comments
\nclass Solution {\npublic:\n    string entityParser(string text) {\n        //storing special characters in map for fast retreival\n        unordered_map<strin
```\nclass Solution {\npublic:\n    string entityParser(string text) {\n        //storing special characters in map for fast retreival\n        unordered_map<string, char> specialCharacters;\n        specialCharacters["&quot;"] = \'"\';\n        specialCharacters["&apos;"] = \'\\\'\';\n        specialCharacters["&amp;"] = \'&\';\n        specialCharacters["&gt;"] = \'>\';\n        specialCharacters["&lt;"] = \'<\';\n        specialCharacters["&frasl;"] = \'/\';\n        \n        int right = 0, left = 0;\n        \n        while(right < text.size())\n        {\n            //normal characters are copied as it is\n            while((right < text.size()) && (text[right] != \'&\'))\n            {\n                text[left++] = text[right++];\n            }\n            \n            //if \'&\' found, there is possibility of special character\n            int start = right;\n            while((right < text.size()) && (text[right] != \';\'))\n            {\n                right++;\n            }\n            \n            string currentWord = text.substr(start, right + 1 - start);\n            \n            //valid special character\n            if(specialCharacters.find(currentWord) != specialCharacters.end())\n            {\n                cout<<currentWord<<endl;\n                text[left++] = specialCharacters[currentWord];\n                right++;\n            }\n            \n            //invalid special character, copied as it is\n            else if (start < right)\n            {\n                text[left++] = text[start];\n                right = start + 1;\n            }\n        }\n        \n        //string only till left pointer is needed\n        text = text.substr(0, left);\n        \n        return text;\n    }\n};\n```
[]