Company: Amazon SDE1 off campus_24march
Difficulty: medium
Amazon Ring's smart lock requires an originalKey to unlock the door. The system handles this key using two empty strings: bufferKey and finalKey . At each step, the system can Move the first character of originalKey to the end of bufferKey , or Move the last character of bufferKey to the end of finalKey . Your task is to determine the alphabetically smallest string finalKey obtainable after all characters are transferred. Note: A string str1 is alphabetically smaller than string str2 if, at the first differing position, the character in str1 appears earlier in the alphabet than the corresponding character in str2 . Example originalKey = "dby" The key is processed in the following way Operation Used originalKey bufferKey finalKey 1 "by" "d" "" 1 "y" "db" "" 2 "y" "d" "b" 2 "y" "" "bd" 1 "" "y" "bd" 2 "" "" "bdy" The finalKey obtained after performing all the transfers is "bdy". Function Description The function findSmallestKey takes the following input: string originalKey : the initial