Compute the next lexicographic permutation | Meta Interview Question