1
var smallestSubsequence = function (s) {2
// Initialize an empty stack to store the result5
// Iterate through each character in the input string6
for (let i = 0; i < s.length; i++) {9
// If the character is already in the stack, skip it10
if (stack.indexOf(char) > -1) continue;12
// Check and pop elements from the stack to maintain lexicographical order15
stack[stack.length - 1] > char &&16
s.indexOf(stack[stack.length - 1], i) > i21
// Push the current character onto the stack25
// Join the characters in the stack to form the smallest subsequence26
return stack.join("");