O(n*n) finding valid result from 0 -> n
Intuition
Try to find each number from 0 -> n

Calculate total possible cases if value in each index change -> get number for this index.


Approach
rs := make(
# Intuition
- Try to find each number from 0 -> n
    - Calculate total possible cases if value in each index change -> get number for this index.

# Approach
- `rs := make([]int, 0)` result
- `numCheck := make([]int, n)` check if number was added to rs or not
- Count `odd` and `even` number
- Calculate `totali := getTotal(odd, even)` number of case if change value for index i 
- Calculate `total_number` and compare with `k` for checking out of range
- Calculate number for index 0 (can be odd or even)
- Calculate for index  `i = 1 to n-1`  base on previous value of rs
    - `i odd` if `i-1 even`
    - `i even` if `i-1 odd` 

# Complexity
- Time complexity: O(n*n) n <=100
- Space complexity: O(n)

# Code
```golang []

func permute(n int, k int64) []int {
	numCheck := make([]int, n)
	rs := make([]int, 0)
	if n == 1 {
		if k == 1 {
			return []int{1}
		} else {
			return rs
		}
	}
	odd := n/2 + n%2
	even := n / 2
	oddFirst := false
    // if odd > even => alway start by a odd number
    // if odd == even => rs[0] can be both odd or even
	if odd > even {
		oddFirst = true
	}
	totali := getTotal(odd, even)
    //check if k is out of range
	if (!oddFirst && totali*int64(odd)*2 > 0 && k > totali*int64(odd)*2) || (oddFirst && totali*int64(odd) > 0 && k > totali*int64(odd)) {
		return rs
	}
     //get index of first number  
	var index int64 = 1
	if totali > 0 {
		index = (k + totali - 1) / int64(totali)
	}
	k -= int64(index-1) * totali
	for i := range numCheck {
        //next if i invalid
		if oddFirst && i%2 == 1 {
			continue
		}
        //next if i had been add to rs
		if numCheck[i] == 1 {
			continue
		}
		index--
		if index == 0 {
			numCheck[i] = 1
			rs = append(rs, i+1)
			if i%2 == 0 {
				odd--
			} else {
				even--
			}
			break
		}
	}

	for len(rs) < n {
		totali = getTotal(odd, even)
		isOdd := rs[len(rs)-1]%2 == 1
        //get index of next number 
		var index int64 = 1
		if totali > 0 {
			index = (k + totali - 1) / int64(totali)
		}
		k -= int64(index-1) * totali
		for i := range numCheck {
            //next if i invalid
			if (isOdd && i%2 == 0) || (!isOdd && i%2 == 1) {
				continue
			}
            //next if i had been add to rs
			if numCheck[i] == 1 {
				continue
			}
			index--
			if index == 0 {
				numCheck[i] = 1
				rs = append(rs, i+1)
				if i%2 == 0 {
					odd--
				} else {
					even--
				}
				break
			}
		}
	}

	return rs
}
func getTotal(odd, even int) int64 {
	if even > odd {
		return getTotal(even, odd)
	}
    //result > maxInt64 -> return -1
	if odd > 11 {
		return -1
	}
	var rs int64 = 1
	for i := odd - 1; i >= 1; i-- {
		rs *= int64(i)
	}
	for i := even; i >= 1; i-- {
		rs *= int64(i)
	}
	return rs
}
```
['Go']