Similar Problems

Similar Problems not available

Find Permutation - Leetcode Solution

Companies:

LeetCode:  Find Permutation Leetcode Solution

Difficulty: Medium

Topics: greedy string stack array  

Problem Statement:

Given two integers n and k, you need to construct a list which must contain n different positive integers ranging from 1 to n and obeys the following requirement:

Suppose this list is [a1, a2, a3, ... , an], then the list [\a1, a2, a3, ... , an] satisfies one of the following properties:

  1. For i = 1, 2, ..., n-1, ai < ai+1
  2. For i = 1, 2, ..., n-1, ai > ai+1 and the difference between ai and ai+1 is exactly k.

Return any valid list of n integers.

Find Permutation Solution Code

1