Hello,
We ran the code on C++, but we keep seeing Syntax Error(s) virtual memory exhausted: Cannot allocate memory message.
We used to set Swap as 6 Gb and RAM 16 Gb on the server, but we keep getting errors.
Our Code;
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
string removeDuplicates(const string &s) {
stack<char> stk;
for(auto c:s)
{
if(stk.empty())
{
stk.push(c);
}
else
{
if(stk.top() != c)
stk.push(c);
else
stk.pop();
}
}
string ans = "";
while(!stk.empty())
{
ans+= stk.top();
stk.pop();
}
reverse(ans.begin(), ans.end());
return ans;
}