Company: Factset
Difficulty: medium
Implement an encryption algorithm to encrypt the string originalString per the following: Initialize two empty strings: temporaryString and encryptedString . At each step, perform one of the following two operations. Choose the order of operations to produce the lexicographically minimal possible encryptedString : Take the first letter from originalString and append it to the end of temporaryString . Take the last letter from temporaryString and append it to the end of encryptedString . Given a string originalString , return the encryptedString . Note: A string a is lexicographically smaller than string b (of the same length) if, in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b . Constraints 1 ≤ | originalString | ≤ 2 × 10⁵ originalString consists of lowercase English letters [a-z]. Examples Example 1: originalString = \"dby\" \"bdy\" Operation Used originalString temporaryString 1 \"by\" \"d\" 1 \