input: from typing import List
  
  def find_permutation(nums: List[int]) -> List[int]:
      """
      You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as:
  
      score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|
  
      Return the permutation perm which has the minimum possible score. If multiple permutations exist with this score, return the one that is lexicographically smallest among them.
  
      Examples:
      >>> nums = [1,0,2]
      [0,1,2]
      >>> nums = [0,2,1]
      [0,2,1]
  
      Constraints:
      2 <= n == nums.length <= 14
      nums is a permutation of [0, 1, 2, ..., n - 1].
      """
  
output: 
      n = len(nums)
      if n == 2:
          return nums if nums[0] < nums[1] else nums[::-1]
      
      sorted_nums = sorted(nums)
      perm = [0] * n
      perm[0] = sorted_nums[0]
      perm[-1] = sorted_nums[1]
      
      for i in range(1, n-1):
          perm[i] = sorted_nums[i+1]
      
      return perm
  