Find lexicographically smallest string and elimination order | Capital One Interview Question