Pergunta de entrevista da empresa Salesforce

Given a String, reverse it and remove repeated characters.

Resposta da entrevista

Sigiloso

11 de out. de 2019

Create a hashset. Iterate through the string. If the character is already present in the set, continue else add the character to the answer string. Each time, add the character to the set. Then, reverse the answer string normally. Time complexity : O(n). Space complexity : O(m) where m is the number of distinct characters in the string.