Solve string transform and min-move sorting | Meta Interview Question