Hello! We are given an integer N, The set [1,2,3,…,N] contains a total of N! unique permutations.
By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3 ) :
- "123"
- "132"
- "213"
- "231"
- "312"
- "321"
Given n and k, return the kth permutation sequence.
For example, given n = 3, k = 4, ans = "231"
if n = 11, k = 1, ans = "1234567891011"
In this case, k will be a positive integer that is less than INT_MAX. n is reasonable enough to make sure the answer does not bloat up a lot.
N can be upto 1000 , k can be upto 1000.
How to solve it, simple backtracking will time out after N>10.
https://www.geeksforgeeks.org/find-n-th-lexicographically-permutation-string-set-2/
but when we concatenate 10 and 11 it will be 1011 i.e 1,0,1,1. how to do for numbers?
Apply the algorithm for a
vector<int>
notstring
.