Domanda di colloquio di Salesforce

Given a String, reverse it and remove repeated characters.

Risposta di colloquio

Anonimo

11 ott 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.