• + 0 comments

    because empty string would also count as previous state of string . eg "1 abc","3 3","4" would yield an empty string as previous state we maintain the stack in order to keep the previous states of the string and consequently we perform perations; youcan optimize the space in stack by checking before push : if(stack.top()!+string)stack.push(string);