Unique String DSA Problem Solution

Unique String DSA Problem Solution
Unique String DSA Problem Solution

In this post, we are going to solve Unique String DSA Problem from Amazon’s 10th October Online assessment. Let’s have a look at the problem statement first and then try to solve the problem.

Unique String DSA Problem Statement

Given a string s that contains characters from a to z returns the smallest subsequence of s that contains all distinct characters of ‘s’ exactly once.

Input

The first line of input contains a single string S (

1S1e5)

Output

For each output print the smallest subsequence of s that doesn’t contain duplicates

Example
Input
bcabc
Output
abc

Problem Solution in C++

#include <bits/stdc++.h>
using namespace std;

int main() {

string s;
cin>>s;

set<char> st;
for(auto it:s) st.insert(it);

s="";
for(auto it:st) s+=it;
cout<<s<<endl;
return 0;

}