Solved LeetCode program · 824 of 1,000
#1081 · Smallest Subsequence of Distinct Characters
Original English source
Keep a shared alphabet as empty text. Keep a shared targetcode of 0. Keep a shared rankresult of 0. Keep a shared remaining as an empty list of whole numbers. Keep a shared used as an empty list of whole numbers. Keep a shared stack as an empty list of whole numbers.
To rank.
For every probe from 0 to 25.
If character probe of alphabet is targetcode, set rankresult to probe, return.
To trim from code (a whole number). The stacklast is the last position of stack. The topcode is 0. If stacklast is at least 0, set topcode to item stacklast of stack.
Repeat while topcode is more than code and item topcode of remaining is more than 0.
Remove the last item from stack. Set item topcode of used to 0. Set stacklast to the last position of stack. Set topcode to 0. If stacklast is at least 0, set topcode to item stacklast of stack.
The source is "cbacdcbc". The letters is "abcdefghijklmnopqrstuvwxyz". The frozen is a copy of letters. Set alphabet to frozen.
For every spot from 0 to 25.
Place 0 into remaining. Place 0 into used.
For every spot from 0 to the last position of source.
Set targetcode to character spot of source. Rank. The code is rankresult. Increase item code of remaining by 1.
For every spot from 0 to the last position of source.
Set targetcode to character spot of source. Rank. The code is rankresult. Decrease item code of remaining by 1. The fresh is 1. If item code of used is 1, set fresh to 0. If fresh is 1, Trim from code. If fresh is 1, Place code into stack, set item code of used to 1.
The answer is empty text.
For each code in stack.
The letter is character code of alphabet. Place letter into answer.
Show answer.
Expected stdout
acdb