Company: Thoughtspot
Difficulty: medium
2. Encrypting Strings 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 minimum 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 . Example originalString = "dby" The string is encrypted in the following way: Operation Used originalString temporaryString encryptedString 1 "by" "d" "" 1 "y" "db" "" 2 "y" "d" "b" 2 "y" "" "bd" 1 ""