Math | Digit-wise Elimination | No DP | Iterative
ApproachSame intuition as 1415. The k-th Lexicographical String of All Happy Strings of Length n's O(N) math solution.We do digit-wise elimination here.choices[
# Approach
Same intuition as [1415. The k-th Lexicographical String of All Happy Strings of Length n](https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/description/)'s $$O(N)$$ math solution.

We do digit-wise elimination here. 

$$choices[i]$$ is the number of viable choices when considering $$ans[i]$$. E.g.
```
N=8        
choices = [8, 4, 3, 3, 2, 2, 1, 1]
N=7
choices = [4, 3, 3, 2, 2, 1, 1]
           o  e  o  e  o  e  o
```
Note that for even N, we can start with odd/even number, but odd N can only start with odd number.
$$choices$$ is converted to suffix for eliminating lexo-smaller prefixes at each $$ans[d]$$
# Complexity
- Time complexity: $$O(N^2)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(N)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def permute(self, N: int, K: int) -> List[int]:
        used = [False for _ in range(N+1)]
        odds = evens = choices = None
        if N&1==0:
            odds = evens = N//2
            choices = [N,odds]
            for i in range(N//2-1):
                choices.append(odds-1-i)
                choices.append(odds-1-i)
        else:
            evens = N//2
            odds = evens+1
            choices = [odds]
            for i in range(evens):
                choices.append(evens-i)
                choices.append(evens-i)
        
        suffix = [None for _ in range(N)]
        suffix[-1] = choices[-1]
        for i in range(N-2,-1,-1):
            suffix[i] = suffix[i+1] * choices[i]
            
        if K>suffix[0]: return []

        ans = []
        prevOdd = None if N&1==0 else False#odd N can only start with odd
        for d in range(N):#dth digit(0 indexed)
            for i in range(1,N+1):
                if used[i]: continue
                if prevOdd is not None:
                    if prevOdd and i&1: continue
                    if (not prevOdd) and (i&1==0): continue
                #try use i as ans[d]
                if d==N-1 or K<=suffix[d+1]:#i is good
                    ans.append(i)
                    used[i]=True
                    prevOdd = True if i&1 else False
                    break

                K-=suffix[d+1]#eliminated, these are lexo-smaller prefixes
        return ans   
```
['Math', 'Python3']