Problem of the day: kth permutation

Problem of the day for today is kth permutation: Given numbers n and k, 1 <= k < INT_MAX, return kth permutation of the set [1,2,…,n]. For example, given n=3 and k=4, the permutations of [1,2,3] in order are:

  1. “123”
  2. “132”
  3. “213”
  4. “231”
  5. “312”
  6. “321”

k=4th permutation is “231”. To simplify the output, a string concatenation of the numbers is returned.

Continue reading


Interesting problem, multiple solutions

I came across a rather interesting problem: “Find a permutation of numbers 1 through N such that average of any two numbers in the permutation does not occur between them”. I found this problem particularly interesting because it lends itself to several different solutions.

Continue reading