Finding the index of a given permutation
问题 I'm reading the numbers 0, 1, ..., (N - 1) one by one in some order. My goal is to find the lexicography index of this given permutation, using only O(1) space. This question was asked before, but all the algorithms I could find used O(N) space. I'm starting to think that it's not possible. But it would really help me a lot with reducing the number of allocations. 回答1: Considering the following data: chars = [a, b, c, d] perm = [c, d, a, b] ids = get_indexes(perm, chars) = [2, 3, 0, 1] A